在另一个用户帐户下启动流程

时间:2017-11-08 14:34:12

标签: vb6 createprocesswithlogonw

以下是流程调用的顺序;

  1. 服务调用流程A(这会导致流程A在本地系统帐户下运行)。

  2. 进程使用CreateProcessWithLogonW API在不同用户帐户(非管理员用户)下启动进程B(作为不同用户的登录凭据可用)。

  3. 进程B执行一些涉及调用另一个进程的活动。

  4. 直到第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)
    

0 个答案:

没有答案