“访问被拒绝”LOGON32_LOGON_SERVICE

时间:2013-01-04 21:21:32

标签: c#

我正在尝试使用advapi32

模拟网络服务
LogonUser("NETWORK SERVICE", "NT AUTHORITY", null, LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, ref token)

但在Windows 8计算机上不断出现Access is denied错误。有任何想法吗? (我google了很多但找不到答案)。

<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">        
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
      <applicationRequestMinimum>
        <defaultAssemblyRequest permissionSetReference="Custom" />
        <PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
      </applicationRequestMinimum>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application />      
  </compatibility>  
</asmv1:assembly>

修改

因此,经过几次尝试,模仿似乎有效,但我无法作为主机的网络服务进行身份验证。应用程序池如何在网络服务下运行?

使用

LOGON32_LOGON_SERVICE

结果:

Unhandled Exception: System.ComponentModel.Win32Exception: Access is denied
   at Tools.Network.Impersonator.Impersonate(String userName, String domainName,
 String password, LogonType logonType, LogonProvider logonProvider)
   at Tools.Network.Impersonator..ctor(String userName, String domainName, Strin
g password, LogonType logonType, LogonProvider logonProvider)
   at Impersonation.Program.Main(String[] args)

使用

LOGON32_LOGON_NEW_CREDENTIALS

结果:

System.IO.IOException: Logon failure: unknown user name or bad password.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Bo
olean overwrite)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean ov
erwrite)
   at Impersonation.Program.Main(String[] args)

困惑。

2 个答案:

答案 0 :(得分:3)

最后!我找到了答案:

How do I 'run as' 'Network Service'?

http://geek.hubkey.com/2008/02/impersonating-built-in-service-account.html

在Windows 8上.. “Microsoft已在Windows 8 / Windows Server 2012中更改了此默认行为。要允许交互式服务,您需要找到注册表项HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Windows并将NoInteractiveServices从1更改为0.”

答案 1 :(得分:1)

这是一个非常好的链接,有代码和我认为这就是你可能正在寻找的一切。 如果此链接有效,请告诉我

.NET (C#) Impersonation with Network Credentials works for LOGON32_LOGON_NEW_CREDENTIALS as your logon type, which requires that you select LOGON32_PROVIDER_WINNT50 as the logon provider type.

相关问题