我正在尝试使用模拟网络服务advapi32
LogonUser("NETWORK SERVICE", "NT AUTHORITY", null, LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, ref token)
Access is denied
但是在 Windows 8 机器上不断出错。有任何想法吗?(我用谷歌搜索了很多,但找不到答案)。
<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)
困惑。