【发布时间】:2017-07-17 17:55:32
【问题描述】:
在我成功冒充另一个用户后,我正在调用 CMD.exe。
cmd出现后。
然后我通过代码echo %username% 检查它再次返回给我的用户。
在调试模式下,我调用WindowsIdentity,作为另一个用户成功了。
这是我模拟的一些代码
Dim impersonationContext As WindowsImpersonationContext = Nothing
Dim userHandle As IntPtr = IntPtr.Zero
Dim fAccess As New FAccess.clsFAccess
Try
If LogonUser("my.user", "domain", "password", 2, 0, userHandle) Then
If userHandle <> IntPtr.Zero Then
impersonationContext = WindowsIdentity.Impersonate(userHandle)
shell("cmd.exe", AppWinStyle.NormalFocus, True)
End Using
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
MsgBox(ex.Message)
Finally
If impersonationContext IsNot Nothing Then
impersonationContext.Undo()
End If
If userHandle <> IntPtr.Zero Then
Marshal.FreeHGlobal(userHandle)
End If
End Try
我只是想问一下,我调用的shell是否总是作为用户登录窗口?
*我也尝试使用 ProcessStartInfo 执行 cmd,它总是说“目录失败”或“找不到文件”或“拒绝访问”
【问题讨论】:
-
旧的 Shell() 函数太原始而无法控制。您需要使用 .NET Process 类,ProcessStartInfo.LoadUserProfile 属性很重要。它还具有 UserName 属性,因此您不必再通过模拟破坏您自己的进程状态。
-
对不起,我想问一下LoadUserProfile。从这个文档 [链接] msdn.microsoft.com/en-us/library/… 它说函数将从注册表中加载。如果我进行模拟,模拟过程是否会设置注册表中的配置文件数据,这些数据将由 LoadUserProfile 函数加载?我只是好奇,因为当我使用 ProcessStartInfo 时,它总是“拒绝访问”。无论如何感谢您的指导
标签: vb.net impersonation