0

Below is the sequence of Process calling;

  1. Service calling Process A (this causes Process A to run under local system account).

  2. Process A launching Process B under different user account (non admin user) using CreateProcessWithLogonW API (as logon credentials of different user is available).

  3. Process B performing some activity which involves invoking another process.

Up to step 2 everything works fine. Process B launched under given user account but Process B is not able to perform a task like executing batch file or launching one more process using CreateProcess API.

Below is the code for invoking Process 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)

And below code used in Process B to execute batch file;

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)
Bugs
  • 4,491
  • 9
  • 32
  • 41
Gvs13
  • 126
  • 12
  • Look in here and look for password and username. https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo?view=netframework-4.7.1 – Chillzy Nov 08 '17 at 15:19
  • @Chillzy The link u have given provides the .Net solution and I want it in vb6 – Gvs13 Nov 09 '17 at 07:39
  • @Gvs13 have a small think. You tagged this as VB.NET and not as VB6. People will offer solutions in .NET because you tagged it so. In future tag correctly from the beginning so 1. You don't get the wrong solutions being offered and 2. People don't waste their time offering you the wrong solutions. Thank you. – Bugs Nov 10 '17 at 14:01

0 Answers0