Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function W2KRunAsUser(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, _
- LOGON_WITH_PROFILE, 0&, wCommandLine, _
- CREATE_DEFAULT_ERROR_MODE, 0&, wCurrentDir, si, pi)
- ' CreateProcessWithLogonW() does not
- If Result <> 0 Then
- CloseHandle pi.hThread
- CloseHandle pi.hProcess
- W2KRunAsUser = 0
- Else
- W2KRunAsUser = Err.LastDllError
- MsgBox "CreateProcessWithLogonW() failed with error " & Err.LastDllError, vbExclamation
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement