Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Public Function W2KRunAsUser(ByVal UserName As String, _
  2. ByVal Password As String, _
  3. ByVal DomainName As String, _
  4. ByVal CommandLine As String, _
  5. ByVal CurrentDirectory As String) As Long
  6.  
  7. Dim si As STARTUPINFO
  8. Dim pi As PROCESS_INFORMATION
  9.  
  10. Dim wUser As String
  11. Dim wDomain As String
  12. Dim wPassword As String
  13. Dim wCommandLine As String
  14. Dim wCurrentDir As String
  15.  
  16. Dim Result As Long
  17.  
  18. si.cb = Len(si)
  19.  
  20. wUser = StrConv(UserName + Chr$(0), vbUnicode)
  21. wDomain = StrConv(DomainName + Chr$(0), vbUnicode)
  22. wPassword = StrConv(Password + Chr$(0), vbUnicode)
  23. wCommandLine = StrConv(CommandLine + Chr$(0), vbUnicode)
  24. wCurrentDir = StrConv(CurrentDirectory + Chr$(0), vbUnicode)
  25.  
  26. Result = CreateProcessWithLogonW(wUser, wDomain, wPassword, _
  27. LOGON_WITH_PROFILE, 0&, wCommandLine, _
  28. CREATE_DEFAULT_ERROR_MODE, 0&, wCurrentDir, si, pi)
  29. ' CreateProcessWithLogonW() does not
  30. If Result <> 0 Then
  31. CloseHandle pi.hThread
  32. CloseHandle pi.hProcess
  33. W2KRunAsUser = 0
  34. Else
  35. W2KRunAsUser = Err.LastDllError
  36. MsgBox "CreateProcessWithLogonW() failed with error " & Err.LastDllError, vbExclamation
  37. End If
  38.  
  39. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement