jazzyjeff Posted September 11, 2017 Share Posted September 11, 2017 I think it has been done before, although I couldn't find one that I could get to work so I have wrote a little GUI for PSExec. The PSExec file needs to reside in the same location as this script is ran from. Here is the code, and any improvements are welcome. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=C:\PSTools\PSExecGUI.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> Local $fileCheck=False $psexec = @ScriptDir & "\psexec.exe" If Not FileExists($psexec) Then MsgBox(0,"Error","The PSExec.exe file needs to be in the same location as this executable.") Exit EndIf #Region ### START Koda GUI section ### Form= $formMain = GUICreate("PSTools GUI", 601, 518, 192, 124) $miFile = GUICtrlCreateMenu("&File") $miExit = GUICtrlCreateMenuItem("E&xit", $miFile) $miTools = GUICtrlCreateMenu("&Tools") $miOptions = GUICtrlCreateMenuItem("&Options", $miTools) $miHelp = GUICtrlCreateMenu("&Help") $miAbout = GUICtrlCreateMenuItem("&About", $miHelp) $tabSheet = GUICtrlCreateTab(8, 8, 585, 481) $tabPSExec = GUICtrlCreateTabItem("PSExec") $lblComputer = GUICtrlCreateLabel("Computer(s)", 22, 88, 60, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inComputer = GUICtrlCreateInput("", 96, 86, 481, 21) GUICtrlSetTip(-1, "Add multiple computers by separating the name with commas. e.g. PC1,PC2,PC3") $radioComputer = GUICtrlCreateRadio("Computer", 22, 56, 65, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetTip(-1, "Direct PsExec to run the application on the remote computer or computers specified. If you omit the computer name, PsExec runs the application on the local system, and if you specify a wildcard (\\*), PsExec runs the command on all computers in the current domain.") $radioFileList = GUICtrlCreateRadio("Computer File List", 96, 56, 113, 17) GUICtrlSetTip(-1, "PsExec will execute the command on each of the computers listed in the file.") $lblFileList = GUICtrlCreateLabel("File List", 22, 120, 39, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inFileList = GUICtrlCreateInput("", 96, 116, 385, 21) GUICtrlSetTip(-1, "PsExec will execute the command on each of the computers listed in the file.") $btnBrowse = GUICtrlCreateButton("&Browse", 501, 115, 75, 25) $lblUsername = GUICtrlCreateLabel("Username", 22, 157, 52, 16) GUICtrlSetBkColor(-1, 0xFFFFFF) $inUsername = GUICtrlCreateInput("", 96, 154, 193, 21) GUICtrlSetTip(-1, "Specifies optional user name for login to remote computer.") $lblPassword = GUICtrlCreateLabel("&Password", 312, 157, 56, 16) GUICtrlSetBkColor(-1, 0xFFFFFF) $inPassword = GUICtrlCreateInput("", 376, 154, 201, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) GUICtrlSetTip(-1, "Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.") $lblTimeout = GUICtrlCreateLabel("Timeout (s)", 22, 193, 56, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inTimeout = GUICtrlCreateInput("", 96, 190, 49, 21) GUICtrlSetTip(-1, "Specifies timeout in seconds connecting to remote computers.") $lblService = GUICtrlCreateLabel("Remote Service", 182, 193, 80, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inRemoteService = GUICtrlCreateInput("", 272, 190, 305, 21) GUICtrlSetTip(-1, "Specifies the name of the remote service to create or interact with.") $lblInteractive = GUICtrlCreateLabel("Interactive Session", 22, 223, 94, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inInteractive = GUICtrlCreateInput("", 126, 220, 193, 21) GUICtrlSetTip(-1, "Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.") $lblWDir = GUICtrlCreateLabel("Working Directory", 22, 248, 89, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inWDir = GUICtrlCreateInput("", 126, 245, 193, 21) GUICtrlSetTip(-1, "Set the working directory of the process (relative to remote computer).") $lblPriority = GUICtrlCreateLabel("Priority", 22, 274, 35, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $comboPriority = GUICtrlCreateCombo("None", 126, 271, 193, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "None|Low|BelowNormal|AboveNormal|High|Realtime|Backgroumd") GUICtrlSetTip(-1, "Specifies -low, -belownormal, -abovenormal, -high or -realtime to run the process at a different priority. Use -background to run at low memory and I/O priority on Vista.") $lblCPU = GUICtrlCreateLabel("CPU", 22, 301, 26, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inCPU = GUICtrlCreateInput("", 126, 298, 193, 21) GUICtrlSetTip(-1, 'Separate processors on which the application can run with commas where 1 is the lowest numbered CPU. For example, to run the application on CPU 2 and CPU 4, enter: "-a 2,4"') $groupParam = GUICtrlCreateGroup(" Parameters ", 24, 328, 553, 57) GUICtrlSetBkColor(-1, 0xFFFFFF) $cbParamH = GUICtrlCreateCheckbox("-h", 49, 352, 30, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "If the target system is Vista or higher, has the process run with the account's elevated token, if available.") $cbParamL = GUICtrlCreateCheckbox("-l", 109, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs the Low Integrity.") $cbParamS = GUICtrlCreateCheckbox("-s", 229, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Run the remote process in the System account.") $cbParamE = GUICtrlCreateCheckbox("-e", 169, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Does not load the specified account’s profile.") $cbParamX = GUICtrlCreateCheckbox("-x", 289, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Display the UI on the Winlogon secure desktop (local system only).") $cbParamC = GUICtrlCreateCheckbox("-c", 349, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Copy the specified program to the remote system for execution. If you omit this option the application must be in the system path on the remote system.") $cbParamF = GUICtrlCreateCheckbox("-f", 409, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Copy the specified program even if the file already exists on the remote system.") $cbParamV = GUICtrlCreateCheckbox("-v", 469, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Copy the specified file only if it has a higher version number or is newer on than the one on the remote system.") $cbParamD = GUICtrlCreateCheckbox("-d", 529, 352, 35, 17) GUICtrlSetFont(-1,"10") GUICtrlSetTip(-1, "Don't wait for process to terminate (non-interactive).") GUICtrlCreateGroup("", -99, -99, 1, 1) $btnBrowse2 = GUICtrlCreateButton("B&rowse", 501, 392, 75, 25) $inCMD = GUICtrlCreateInput("", 96, 394, 385, 21) GUICtrlSetTip(-1, "Name of application to execute.") $lblCMD = GUICtrlCreateLabel("Command", 22, 397, 51, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $lblArguments = GUICtrlCreateLabel("Arguments", 22, 425, 54, 17) GUICtrlSetBkColor(-1, 0xFFFFFF) $inArguments = GUICtrlCreateInput("", 96, 423, 481, 21) GUICtrlSetTip(-1, "Arguments to pass (note that file paths must be absolute paths on the target system).") $btnExecute1 = GUICtrlCreateButton("&Execute", 504, 456, 75, 25) $tabPSKill = GUICtrlCreateTabItem("PSKill") GUICtrlCreateTabItem("") GUICtrlSetState($lblFileList,$GUI_DISABLE) GUICtrlSetState($inFileList,$GUI_DISABLE) GUICtrlSetState($btnBrowse,$GUI_DISABLE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 If $fileCheck = True And BitAND(GUICtrlRead($radioComputer), $GUI_CHECKED) = $GUI_CHECKED Then ;MsgBox(0,"","Computer selected") GUICtrlSetState($radioFileList, $GUI_UNCHECKED) GUICtrlSetState($lblFileList,$GUI_DISABLE) GUICtrlSetState($inFileList,$GUI_DISABLE) GUICtrlSetState($btnBrowse,$GUI_DISABLE) GUICtrlSetState($lblComputer,$GUI_ENABLE) GUICtrlSetState($inComputer,$GUI_ENABLE) $fileCheck = False ElseIf $fileCheck = False And BitAND(GUICtrlRead($radioFileList), $GUI_CHECKED) = $GUI_CHECKED Then ;MsgBox(0,"","File list selected") GUICtrlSetState($radioComputer, $GUI_UNCHECKED) GUICtrlSetState($lblComputer,$GUI_DISABLE) GUICtrlSetState($inComputer,$GUI_DISABLE) GUICtrlSetState($lblFileList,$GUI_ENABLE) GUICtrlSetState($inFileList,$GUI_ENABLE) GUICtrlSetState($btnBrowse,$GUI_ENABLE) $fileCheck = True EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $miExit Exit Case $btnExecute1 $error = False $string = @ScriptDir & "\psexec.exe" If $fileCheck = False Then ; Check if psexec will work using pc name If GUICtrlRead($inComputer) = "" Then MsgBox(0,"Error","Please enter a computer name to continue.") $error = True Else $string = $string & " \\" & GUICtrlRead($inComputer) ; Run PSExec against the machines here If GUICtrlRead($inUsername) <> "" Then $string = $string & ' -u ' & GUICtrlRead($inUsername) EndIf If GUICtrlRead($inPassword) = "" Then If GUICtrlRead($inUsername) <> "" Then MsgBox(0,"Error","You have entered a username, and therefore also require a password to be entered to continue.") $error = True Else If GUICtrlRead($inTimeout) <> "" Then $string = $string & ' -n ' & GUICtrlRead($inTimeout) EndIf If GUICtrlRead($inRemoteService) <> "" Then $string = $string & ' -r ' & GUICtrlRead($inRemoteService) EndIf If BitAND(GUICtrlRead($cbParamH), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -h' EndIf If BitAND(GUICtrlRead($cbParamL), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -l' EndIf If BitAND(GUICtrlRead($cbParamS), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -s' EndIf If BitAND(GUICtrlRead($cbParamE), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -e' EndIf If BitAND(GUICtrlRead($cbParamX), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -x' EndIf If GUICtrlRead($inInteractive) <> "" Then $string = $string & ' -i ' & GUICtrlRead($inInteractive) EndIf If BitAND(GUICtrlRead($cbParamC), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -c' EndIf If BitAND(GUICtrlRead($cbParamF), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -f' EndIf If BitAND(GUICtrlRead($cbParamV), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -v' EndIf If GUICtrlRead($inWDir) <> "" Then $string = $string & ' -w "' & GUICtrlRead($inWDir) & '"' EndIf If BitAND(GUICtrlRead($cbParamD), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -d' EndIf If GUICtrlRead($comboPriority) <> "None" Then $string = $string & ' -' & GUICtrlRead($comboPriority) EndIf If GUICtrlRead($inCPU) <> "" Then $string = $string & ' -a ' & GUICtrlRead($inCPU) EndIf If GUICtrlRead($inCMD) = "" Then MsgBox(0,"Error","You cannot run PSExec without entering a command to run.") $error = True Else $string = $string & ' ' & GUICtrlRead($inCMD) If GUICtrlRead($inArguments) <> "" Then $string = $string & ' ' & GUICtrlRead($inArguments) EndIf EndIf If $error = False Then Run(@ComSpec & ' /c ' & $string) EndIf EndIf Else If GUICtrlRead($inUsername) = "" Then MsgBox(0,"Error","You have entered a password, and therefore also require a username to be entered to continue.") $error = True Else $string = $string & ' -p ' & GUICtrlRead($inPassword) If GUICtrlRead($inTimeout) <> "" Then $string = $string & ' -n ' & GUICtrlRead($inTimeout) EndIf If GUICtrlRead($inRemoteService) <> "" Then $string = $string & ' -r ' & GUICtrlRead($inRemoteService) EndIf If BitAND(GUICtrlRead($cbParamH), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -h' EndIf If BitAND(GUICtrlRead($cbParamL), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -l' EndIf If BitAND(GUICtrlRead($cbParamS), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -s' EndIf If BitAND(GUICtrlRead($cbParamE), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -e' EndIf If BitAND(GUICtrlRead($cbParamX), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -x' EndIf If GUICtrlRead($inInteractive) <> "" Then $string = $string & ' -i ' & GUICtrlRead($inInteractive) EndIf If BitAND(GUICtrlRead($cbParamC), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -c' EndIf If BitAND(GUICtrlRead($cbParamF), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -f' EndIf If BitAND(GUICtrlRead($cbParamV), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -v' EndIf If GUICtrlRead($inWDir) <> "" Then $string = $string & ' -w "' & GUICtrlRead($inWDir) & '"' EndIf If BitAND(GUICtrlRead($cbParamD), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -d' EndIf If GUICtrlRead($comboPriority) <> "None" Then $string = $string & ' -' & GUICtrlRead($comboPriority) EndIf If GUICtrlRead($inCPU) <> "" Then $string = $string & ' -a ' & GUICtrlRead($inCPU) EndIf If GUICtrlRead($inCMD) = "" Then MsgBox(0,"Error","You cannot run PSExec without entering a command to run.") $error = True Else $string = $string & ' ' & GUICtrlRead($inCMD) If GUICtrlRead($inArguments) <> "" Then $string = $string & ' ' & GUICtrlRead($inArguments) EndIf EndIf If $error = False Then Run(@ComSpec & ' /c ' & $string) EndIf EndIf EndIf EndIf ElseIf $fileCheck = True Then ; Check if psexec will work using a file list If GUICtrlRead($inFileList) = "" Then MsgBox(0,"Error","Please enter a location for the computer file list") Else $string = $string & " @file\" & GUICtrlRead($inFileList) & '"' ; Run PSSExex against machines in this file list If GUICtrlRead($inUsername) <> "" Then $string = $string & ' -u ' & GUICtrlRead($inUsername) EndIf If GUICtrlRead($inPassword) = "" Then If GUICtrlRead($inUsername) <> "" Then MsgBox(0,"Error","You have entered a username, and therefore also require a password to be entered to continue.") $error = True Else If GUICtrlRead($inTimeout) <> "" Then $string = $string & ' -n ' & GUICtrlRead($inTimeout) EndIf If GUICtrlRead($inRemoteService) <> "" Then $string = $string & ' -r ' & GUICtrlRead($inRemoteService) EndIf If BitAND(GUICtrlRead($cbParamH), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -h' EndIf If BitAND(GUICtrlRead($cbParamL), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -l' EndIf If BitAND(GUICtrlRead($cbParamS), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -s' EndIf If BitAND(GUICtrlRead($cbParamE), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -e' EndIf If BitAND(GUICtrlRead($cbParamX), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -x' EndIf If GUICtrlRead($inInteractive) <> "" Then $string = $string & ' -i ' & GUICtrlRead($inInteractive) EndIf If BitAND(GUICtrlRead($cbParamC), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -c' EndIf If BitAND(GUICtrlRead($cbParamF), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -f' EndIf If BitAND(GUICtrlRead($cbParamV), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -v' EndIf If GUICtrlRead($inWDir) <> "" Then $string = $string & ' -w "' & GUICtrlRead($inWDir) & '"' EndIf If BitAND(GUICtrlRead($cbParamD), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -d' EndIf If GUICtrlRead($comboPriority) <> "None" Then $string = $string & ' -' & GUICtrlRead($comboPriority) EndIf If GUICtrlRead($inCPU) <> "" Then $string = $string & ' -a ' & GUICtrlRead($inCPU) EndIf If GUICtrlRead($inCMD) = "" Then MsgBox(0,"Error","You cannot run PSExec without entering a command to run.") $error = True Else $string = $string & ' ' & GUICtrlRead($inCMD) If GUICtrlRead($inArguments) <> "" Then $string = $string & ' ' & GUICtrlRead($inArguments) EndIf EndIf If $error = False Then Run(@ComSpec & ' /c ' & $string) EndIf EndIf Else If GUICtrlRead($inUsername) = "" Then MsgBox(0,"Error","You have entered a password, and therefore also require a username to be entered to continue.") $error = True Else $string = $string & ' -p ' & GUICtrlRead($inPassword) If GUICtrlRead($inTimeout) <> "" Then $string = $string & ' -n ' & GUICtrlRead($inTimeout) EndIf If GUICtrlRead($inRemoteService) <> "" Then $string = $string & ' -r ' & GUICtrlRead($inRemoteService) EndIf If BitAND(GUICtrlRead($cbParamH), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -h' EndIf If BitAND(GUICtrlRead($cbParamL), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -l' EndIf If BitAND(GUICtrlRead($cbParamS), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -s' EndIf If BitAND(GUICtrlRead($cbParamE), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -e' EndIf If BitAND(GUICtrlRead($cbParamX), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -x' EndIf If GUICtrlRead($inInteractive) <> "" Then $string = $string & ' -i ' & GUICtrlRead($inInteractive) EndIf If BitAND(GUICtrlRead($cbParamC), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -c' EndIf If BitAND(GUICtrlRead($cbParamF), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -f' EndIf If BitAND(GUICtrlRead($cbParamV), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -v' EndIf If GUICtrlRead($inWDir) <> "" Then $string = $string & ' -w "' & GUICtrlRead($inWDir) & '"' EndIf If BitAND(GUICtrlRead($cbParamD), $GUI_CHECKED) = $GUI_CHECKED Then $string = $string & ' -d' EndIf If GUICtrlRead($comboPriority) <> "None" Then $string = $string & ' -' & GUICtrlRead($comboPriority) EndIf If GUICtrlRead($inCPU) <> "" Then $string = $string & ' -a ' & GUICtrlRead($inCPU) EndIf If GUICtrlRead($inCMD) = "" Then MsgBox(0,"Error","You cannot run PSExec without entering a command to run.") $error = True Else $string = $string & ' ' & GUICtrlRead($inCMD) If GUICtrlRead($inArguments) <> "" Then $string = $string & ' ' & GUICtrlRead($inArguments) EndIf EndIf If $error = False Then Run(@ComSpec & ' /c ' & $string) EndIf EndIf EndIf EndIf EndIf $browse1 = "" $browse2 = "" ;end of btn execute Case $btnBrowse $browse1 = FileOpenDialog("Select a file","C:\","All (*.*)") GUICtrlSetData($inFileList,'"' & $browse1 & '"') Case $btnBrowse2 $browse2 = FileOpenDialog("Select a file","C:\","All (*.*)") GUICtrlSetData($inCMD,'"' & $browse2 & '"') EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 11, 2017 Moderators Share Posted September 11, 2017 Well done. I did notice that on Windows 10 @ 1920x1080 your GUI comes up just fine. On Windows 7 at the same resolution it looks like your labels are cutting off. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
jazzyjeff Posted September 11, 2017 Author Share Posted September 11, 2017 Thanks for the heads up on this. I will take a look. I did build this on a Windows 10 system, on a resolution of 2560x1440 and 125% scale. I'll do some testing with other resolutions and Windows 7. Link to comment Share on other sites More sharing options...
jazzyjeff Posted September 11, 2017 Author Share Posted September 11, 2017 Just out of curiosity JLogan3o13, what is the scale set to on your display settings? Thanks. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 11, 2017 Moderators Share Posted September 11, 2017 100% "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now