Hi,
A processA having UserA credentials runs a processB with UserB credentials.
I'm using CreateProcessWithLogonW with LOADING_PROFILE (needed)
I'd like to add some new environment variable to the processB like :
HOMEDRIVE = UserA HOMEDRIVE
HOMEPATH = UserA HOMEPATH
CALLINGUSER = UserA USERNAME
Here is the VB6 function I'm using (which is working)
Public Function RunAsUser(ByVal UserName As String, ByVal Password As String, ByVal DomainName As String, ByVal CommandLine As String, ByVal CurrentDirectory As String) As Long
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 Result As Long
si.cb = Len(si)
wUser = StrConv(UserName + Chr$(0), vbUnicode)
wDomain = StrConv(DomainName + Chr$(0), vbUnicode)
wPassword = StrConv(Password + Chr$(0), vbUnicode)
wCommandLine = StrConv(CommandLine + Chr$(0), vbUnicode)
wCurrentDir = StrConv(CurrentDirectory + Chr$(0), vbUnicode)
Result = CreateProcessWithLogonW(wUser, wDomain, wPassword, &H1, 0&, wCommandLine, &H4000000, 0&, wCurrentDir, si, pi)
If Result <> 0 Then
CloseHandle pi.hThread
CloseHandle pi.hProcess
RunAsUser = 0
Else
RunAsUser = Err.LastDllError
MsgBox "CreateProcessWithLogonW() failed with error " & Err.LastDllError, vbExclamation
End If
End Function