Guest User

Untitled

a guest
Feb 9th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. Arguments:
  2.  
  3. UserName = Nothing
  4. Password = Nothing
  5. RemoteMachineName = "CurrentMachineName"
  6. PathBashFile = "Path/To/My/Local/Script.ps1"
  7. Params = "parameter1"
  8.  
  9. Arguments:
  10.  
  11. UserName = "MyUsername"
  12. Password = "MyPassword"
  13. RemoteMachineName = "RemoteMachineName"
  14. PathBashFile = "Path/To/My/Local/Script.ps1"
  15. Params = "parameter1"
  16.  
  17. outParams("processId") = Nothing
  18. outParams("returnValue") = 8
  19.  
  20. Try
  21. connOptions = New ConnectionOptions()
  22. connOptions.Username = UserName
  23. connOptions.Password = Password
  24.  
  25. connOptions.Impersonation = ImpersonationLevel.Impersonate
  26. connOptions.Authentication = Management.AuthenticationLevel.PacketPrivacy
  27.  
  28. managementPath = New ManagementPath("\" & RemoteMachineName & "rootcimv2:Win32_Process")
  29.  
  30. Scope = New ManagementScope(managementPath, connOptions)
  31. Scope.Connect()
  32. objectGetOptions = New ObjectGetOptions()
  33. processClass = New ManagementClass(Scope, New ManagementPath("rootcimv2:Win32_Process"), objectGetOptions)
  34.  
  35. inParams = processClass.GetMethodParameters("Create")
  36. inParams("CommandLine") = "cmd.exe /c powershell """ & PathBashFile & """ " & params
  37. inParams("CurrentDirectory") = workingDirectoryPath
  38. outParams = processClass.InvokeMethod("Create", inParams, Nothing)
  39. MsgBox(outParams("processId") & " " & outParams("returnValue"))
  40.  
  41. Catch ex As Exception
  42. Throw New Exception("[ExecuteRemoteBashFile] " & ex.Message)
  43. End Try
Add Comment
Please, Sign In to add comment