下面是 Process 调用的顺序;
服务调用进程 A(这会导致进程 A 在本地系统帐户下运行)。
进程 A 使用 CreateProcessWithLogonW API 在不同的用户帐户(非管理员用户)下启动进程 B(因为不同用户的登录凭据可用)。
进程 B 执行一些涉及调用另一个进程的活动。
直到第 2 步,一切正常。进程 B 在给定的用户帐户下启动,但进程 B 无法执行任务,例如执行批处理文件或使用 CreateProcess API 启动另一个进程。
下面是调用进程B的代码;
Dim si As STARTUPINFO
Dim pi As PROCESS_INFORMATION
Dim wUser As String
Dim wDomain As String
Dim wPassword As String
Dim wCommandLine As String
Dim wCurrentDir As String
Dim wApplicaiotnName
Dim Result As Long
si.cb = Len(si)
si.lpDesktop = "WinSta0\Default"
Result = CreateProcessWithLogonW(wUser, wDomain, wPassword, _LOGON_WITH_PROFILE,
wApplicaiotnName, "", _CREATE_UNICODE_ENVIRONMENT, 0&, wCurrentDir, si, pi)
下面是进程 B 中用于执行批处理文件的代码;
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
Dim lpId As Long
Dim llReturn As Long
Dim RetVal As Long
With start
.cb = Len(start)
.lpDesktop = "WinSta0\Default"
If Not IsMissing(WindowStyle) Then
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = WindowStyle
End If
End With
ret& = CreateProcessA(0&, pathName, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)