Jump to content

Psexec/autoit remote soft installing


Recommended Posts

ok so i have posted this already and had a responce but still haven't cracked it !

i'm new to autoit and have used if for simple stuff so far. i do use psexec and love to run silent installs through our network to update machines/rooms etc etc

so i started with

RunWait('"' & @ComSpec & '" /c psexec @C:\psexec installers\test.txt -c -i C:\psexec installers\sw_lic_full_installer.exe /S ', '', @SW_HIDE)

this installs shockwave on the computers named in the test.txt(simple enough)

now what i want autoit to do is let me select the text file i want to use , and also let me select which program i want to remote install. it would also be helpfull if i could add the ssilent switch also ?

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Local $textfilepath,$exepath

#Region ### START Koda GUI section ### Form=Form1.kxf

$Form1 = GUICreate("Connect", 404, 195, 206, 126)

$filemenu=GUICtrlCreateMenu("File")

GUICtrlCreateMenuItem("",$filemenu)

$hfilemenuitem1vls=GUICtrlCreateMenuItem("Choose Your install",$filemenu)

GUICtrlCreateMenuItem("",$filemenu)

$menuitem2textfile=GUICtrlCreateMenuItem("Open Your room",$filemenu)

GUICtrlCreateMenuItem("",$filemenu)

$exititem=GUICtrlCreateMenuItem("Exit...",$filemenu)

GUICtrlCreateMenuItem("",$filemenu)

$Button1 = GUICtrlCreateButton("Run", 120, 128, 129, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $hfilemenuitem1vls

$hopen=FileOpenDialog("Choose Your install",@WindowsDir&"\install","Exe Files (*.exe)")

$exepath=FileGetLongName($hopen)

;MsgBox(64,"",$vlcpath)

Case $menuitem2textfile

$textfile=FileOpenDialog("Open Your room",@WindowsDir&"\install","Text Files (*.txt)")

$textfilepath=FileGetLongName($textfile)

;MsgBox(64,"",$textfilepath)

Case $Button1

If $exepath="" Then

check()

EndIf

If $textfilepath="" Then

second()

Else

;RunWait('"' & @ComSpec & '" /c psexec @c:\WINDOWS\install\test.txt -c -i C:\WINDOWS\install\vlc.exe ', '', @SW_HIDE)

RunWait("cmd.exe /c " & "psexec " & ""& $textfilepath &"" & " -c -i " & "" & $exepath & "",@ScriptDir,@SW_HIDE)

MsgBox(64,"Operation Done","Operation Done", "",5)

EndIf

Case $exititem

ExitLoop

EndSwitch

WEnd

Func check()

MsgBox(64,"NO PROGRAM SELECTED!" ,"NO PROGRAM SELECTED!!",4)

EndFunc

Func second()

MsgBox(64,"TEXT FILE NOT SELECTED!","TEXT FILE NOT SELECTED!",4)

EndFunc

this script was posted in the previouse topic but for some reason it wouldn't install anything to the remote machine. i have tinkered a little to try to get it to work can't figure it out

any help would be greatfull

Link to comment
Share on other sites

ok with some amazing help from Sh3llC043r

we've got it working any adds to make this pimped up would be good?

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Local $textfilepath,$exepath

#Region ### START Koda GUI section ### Form=Form1.kxf

$Form1 = GUICreate("Connect", 404, 195, 206, 126)

$filemenu=GUICtrlCreateMenu("File")

GUICtrlCreateMenuItem("",$filemenu)

$hfilemenuitem1vls=GUICtrlCreateMenuItem("Choose Your install",$filemenu)

GUICtrlCreateMenuItem("",$filemenu)

$menuitem2textfile=GUICtrlCreateMenuItem("Open Your room",$filemenu)

GUICtrlCreateMenuItem("",$filemenu)

$exititem=GUICtrlCreateMenuItem("Exit...",$filemenu)

GUICtrlCreateMenuItem("",$filemenu)

$Button1 = GUICtrlCreateButton("Run", 120, 128, 129, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $hfilemenuitem1vls

$hopen=FileOpenDialog("Choose Your install",@WindowsDir&"\install","Exe Files (*.exe)")

$exepath=FileGetLongName($hopen)

;MsgBox(64,"",$vlcpath)

Case $menuitem2textfile

$textfile=FileOpenDialog("Open Your room",@WindowsDir&"\install","Text Files (*.txt)")

$textfilepath=FileGetLongName($textfile)

;MsgBox(64,"",$textfilepath)

Case $Button1

If $exepath="" Then

check()

EndIf

If $textfilepath="" Then

second()

Else

;RunWait('"' & @ComSpec & '" /c psexec @c:\WINDOWS\install\test.txt -c -i C:\WINDOWS\install\vlc.exe ', '', @SW_HIDE)

RunWait("cmd.exe /c " & "psexec " & ""& "@"&$textfilepath &"" & " -c -i " & "" & $exepath & "",@ScriptDir,@SW_HIDE)

MsgBox(64,"Operation Done","Operation Done", "",5)

EndIf

Case $exititem

ExitLoop

EndSwitch

WEnd

Func check()

MsgBox(64,"NO PROGRAM SELECTED!" ,"NO PROGRAM SELECTED!!",4)

EndFunc

Func second()

MsgBox(64,"TEXT FILE NOT SELECTED!","TEXT FILE NOT SELECTED!",4)

EndFunc

Link to comment
Share on other sites

I liked this idea, and I wanted to add to it as I have used PSEXEC in the past to push out software to multiple PCs. Just an FYI, there is a great open source program called Purgos (softulz.net) that can do this too.

Anyway, I know there are a bunch of code issues in my script, but I plan on working through these.

What I am having trouble with is moving the text of a program location that I browse to, into the input box. To explain, I have a browse button where I can browse for a file I want to push out to a PC. I can select the file I want, but I can't get the location of this file into the "Input" box that I have created. I have tried all the various "File" functions to see if it would make the text appear, but I have had no luck.

Does anyone know of a function that I can use to achieve this? I don't necessarily want someone to write the code for me, I just need a little help in knowing what function will do the task for me.

Here is what I have:

Case $ButtonBrowse1
            $open=FileOpenDialog("Browse for your file",@WindowsDir&"\install","BAT (*.bat)|EXE (*.exe)|MSI (*.msi)|VBS (*.vbs)")
            $InputPExecute=GUICtrlRead($open)

This is the entire script so far:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=d:\software\koda\my work\remoteexecution.kxf
$Form1_1 = GUICreate("TCAPS Remote Execution tool", 625, 318, 192, 124)
$MenuFile = GUICtrlCreateMenu("&File")
$MenuExit = GUICtrlCreateMenuItem("Exit", $MenuFile)
$MenuHelp = GUICtrlCreateMenu("&Help")
$MenuAbout = GUICtrlCreateMenuItem("About", $MenuHelp)
$LabelCName = GUICtrlCreateLabel("Computer Name", 24, 40, 93, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$InputCName = GUICtrlCreateInput("", 169, 37, 129, 21)
$LabelPExecute1 = GUICtrlCreateLabel("Program to Execute", 24, 72, 115, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$InputPExecute = GUICtrlCreateInput("", 170, 67, 329, 21)
$ButtonBrowse1 = GUICtrlCreateButton("Browse", 504, 65, 75, 25)
$LabelUsername1 = GUICtrlCreateLabel("Username", 24, 104, 60, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$LabelPassword1 = GUICtrlCreateLabel("Password", 24, 136, 58, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$InputUsername1 = GUICtrlCreateInput("", 170, 98, 121, 21)
$InputPassword1 = GUICtrlCreateInput("", 170, 130, 121, 21)
$GroupInput = GUICtrlCreateGroup("Input Data", 8, 19, 585, 145)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GroupOptions = GUICtrlCreateGroup("Options", 8, 176, 577, 73)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$CheckInteract = GUICtrlCreateCheckbox("Interact with Desktop", 16, 200, 145, 17)
$CheckCopyProg = GUICtrlCreateCheckbox("Copy Program to remote system", 16, 224, 201, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ButtonExecute1 = GUICtrlCreateButton("Execute Command", 8, 264, 115, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

Global $CheckCopyProg = "-c"
Global $CheckInteract = "-i"
Global $open

Func Setup()



EndFunc

Func sExecute()

    $ButtonExecute1 = MouseClick("left")
    RunWait("cmd.exe /c " & "psexec " & "" & $InputCName & "" & "-u" & "" & $InputUsername1 & "" & "-p" & "" & $InputPassword1 & "" & $CheckCopyProg & "" & $CheckInteract & "" & $InputPExecute & "", @ScriptDir, @SW_HIDE)

EndFunc   ;==>sExecute

Func ProgError()
    MsgBox(64, "Warning", "Please enter a program path.", 4)
EndFunc   ;==>ProgError

Func PCNameError()
    MsgBox(64, "Warning", "Please enter a Computer name or IP address", 4)
EndFunc   ;==>PCNameError

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonBrowse1
            $open=FileOpenDialog("Browse for your file",@WindowsDir&"\install","BAT (*.bat)|EXE (*.exe)|MSI (*.msi)|VBS (*.vbs)")
            $InputPExecute=GUICtrlRead($open)

        Case $ButtonExecute1
            If $InputCName = "" Then
                PCNameError()
            EndIf
            If $InputPExecute = "" Then
                ProgError()
            Else
                sExecute()
                MsgBox(64, "Successful", "Your command is being executed", 4)
            EndIf

    EndSwitch
WEnd

Thanks for any help/feedback.

Link to comment
Share on other sites

Ok, I guess I just didn't try hard enough before, but I have figured it out! I'm actually kind of proud of myself now!

I have to use the following code:

Case $ButtonBrowse1
            $open=FileOpenDialog("Browse for your file",@WindowsDir&"\install","BAT (*.bat)|EXE (*.exe)|MSI (*.msi)|VBS (*.vbs)")
            For $i=0 To $open
            GUICtrlSetData($InputPExecute,$open)
            Next

Thanks all for taking the time to look and read this.

Link to comment
Share on other sites

yes yes jazzey jeff

looks good. I'll try it later. been looking at adding an auto login feature to this or a separate script. haven't started it yet, but i'll post up some ideas soon.

tron

Link to comment
Share on other sites

This is the one I use...

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=PsexecGUI.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Constants.au3>
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <StatusBarConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <array.au3>
#include <GuiListView.au3>
#include <file.au3>
#include <GuiTab.au3>
#include <IE.au3>

FileInstall('.\Include\Psexec.exe', @TempDir & '\')

Global Const $SV_TYPE_WORKSTATION = 0x1
Global Const $SV_TYPE_SERVER = 0x2
Global Const $SV_TYPE_SQLSERVER = 0x4
Global Const $SV_TYPE_DOMAIN_CTRL = 0x8
Global Const $SV_TYPE_DOMAIN_BAKCTRL = 0x10
Global Const $SV_TYPE_TIME_SOURCE = 0x20
Global Const $SV_TYPE_AFP = 0x40
Global Const $SV_TYPE_NOVELL = 0x80
Global Const $SV_TYPE_DOMAIN_MEMBER = 0x100
Global Const $SV_TYPE_PRINTQ_SERVER = 0x200
Global Const $SV_TYPE_DIALIN_SERVER = 0x400
Global Const $SV_TYPE_XENIX_SERVER = 0x800
Global Const $SV_TYPE_NT = 0x1000
Global Const $SV_TYPE_WFW = 0x2000
Global Const $SV_TYPE_SERVER_MFPN = 0x4000
Global Const $SV_TYPE_SERVER_NT = 0x8000
Global Const $SV_TYPE_POTENTIAL_BROWSER = 0x10000
Global Const $SV_TYPE_BACKUP_BROWSER = 0x20000
Global Const $SV_TYPE_MASTER_BROWSER = 0x40000
Global Const $SV_TYPE_DOMAIN_MASTER = 0x80000
Global Const $SV_TYPE_WINDOWS = 0x400000
Global Const $SV_TYPE_CLUSTER_NT = 0x1000000
Global Const $SV_TYPE_TERMINALSERVER = 0x2000000
Global Const $SV_TYPE_CLUSTER_VS_NT  = 0x4000000
Global Const $SV_TYPE_LOCAL_LIST_ONLY = 0x40000000
Global Const $SV_TYPE_DOMAIN_ENUM = 0x80000000
Global Const $SV_TYPE_ALL = 0xFFFFFFFF
Global Const $PsExecReg = 'HKCU\Software\Sysinternals\PsExec'

Local $DomainList = _NetServerEnum($SV_TYPE_DOMAIN_ENUM)
$DomainList = _ArrayToString($DomainList, '|', 1)

$PS = 'psexec.exe'
$TOOLS = GUICreate("PSexec GUI", 532, 435, -1, -1, $WS_SYSMENU)
$App = GUICtrlCreateInput("", 8, 24, 201, 21)
$Browse1 = GUICtrlCreateButton("Browse", 218, 23, 75, 23, 0)
$PL2 = GUICtrlCreateLabel("Application to run on remote PC", 8, 6, 184, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$CLO = GUICtrlCreateInput("", 8, 67, 289, 21)
$PL3 = GUICtrlCreateLabel("Command line parameters", 8, 50, 148, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$PL4 = GUICtrlCreateLabel("Admin User Name", 8, 95, 124, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$PL5 = GUICtrlCreateLabel("Admin Password", 155, 95, 124, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Usrnm = GUICtrlCreateInput("", 8, 112, 143, 21)
$Pw = GUICtrlCreateInput("", 155, 112, 143, 21, $ES_PASSWORD)
$PCH8 = GUICtrlCreateCheckbox("Run process as limited user", 16, 138, 225, 17)
$PCH9 = GUICtrlCreateCheckbox("Does not load the specified account's profile", 16, 154, 226, 17)
$Group1 = GUICtrlCreateGroup("Parameters", 8, 178, 289, 225)
$PCH1 = GUICtrlCreateCheckbox("Interact with the users desktop", 16, 194, 185, 17)
$PCH2 = GUICtrlCreateCheckbox("Run application in the system account", 16, 210, 225, 17)
$PCH3 = GUICtrlCreateCheckbox("Copy file to remote", 16, 226, 113, 17)
$Group2 = GUICtrlCreateGroup("Copy Options", 40, 245, 250, 54)
$PCH4 = GUICtrlCreateRadio("Overwrite existing file", 48, 261, 121, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$PCH5 = GUICtrlCreateRadio("Copy file only if it is a higher version or newer", 48, 278, 241, 17)
$PCH6 = GUICtrlCreateCheckbox("Don't wait for the process to terminate", 16, 300, 225, 17)
$SliderLbl = GUICtrlCreateLabel('Timeount Connecting To Remote 15 Secs.', 16, 318, 275, 21, $SS_CENTER)
$Slider = GUICtrlCreateSlider(16, 335, 275, 21)
    GUICtrlSetLimit(-1, 120, 1)
    GUICtrlSetData(-1, 15)

$Wkd = GUICtrlCreateInput("", 16, 378, 201, 21)
$Browse3 = GUICtrlCreateButton("Browse", 220, 377, 75, 23, 0)
GUICtrlCreateLabel("Working directory on remote PC", 16, 360, 184, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$PT1 = GUICtrlCreateTab(304, 8, 217, 313)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$PTS1 = GUICtrlCreateTabItem("Enter Name")
$RPC = GUICtrlCreateInput("", 312, 56, 137, 21)
$PL6 = GUICtrlCreateLabel("Remote PC name (or add PC to the list)", 312, 32, 188, 17)
$Add = GUICtrlCreateButton("Add", 456, 54, 41, 25, 0)
$List0 = GUICtrlCreateListView("", 310, 85, 200, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $WS_VSCROLL))
_GUICtrlListView_InsertColumn($List0, 0, "Machine name or IP", 200)
_GUICtrlListView_SetExtendedListViewStyle($List0, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$Rms1 = GUICtrlCreateButton("Remove from list", 310, 287, 100, 25, 0)
$Clr1 = GUICtrlCreateButton("Clear list", 440, 287, 70, 25, 0)
$PTS2 = GUICtrlCreateTabItem("Load PC List")
$PL7 = GUICtrlCreateLabel("Load text file (one pc name per line)", 312, 34, 172, 17)
$CL = GUICtrlCreateInput("", 312, 56, 121, 21)
$Browse2 = GUICtrlCreateButton("Browse", 435, 54, 41, 25, 0)
$Load = GUICtrlCreateButton("Load", 476, 54, 41, 25, 0)
$List1 = GUICtrlCreateListView("", 310, 85, 200, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $WS_VSCROLL))
_GUICtrlListView_InsertColumn($List1, 0, "Machine name or IP", 200)
_GUICtrlListView_SetExtendedListViewStyle($List1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$Rms2 = GUICtrlCreateButton("Remove From List", 310, 287, 100, 25, 0)
$Clr2 = GUICtrlCreateButton("Clear List", 440, 287, 70, 25, 0)


$PTS3 = GUICtrlCreateTabItem("Browse Net")
GUICtrlCreateLabel("Select Domain", 330, 38, 172, 17)
$PCB2 = GUICtrlCreateCombo("", 310, 56, 121, 21)
GUICtrlSetData($PCB2, $DomainList)
$List2 = GUICtrlCreateListView("", 310, 85, 200, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $WS_VSCROLL))
_GUICtrlListView_InsertColumn($List2, 0, "Machine name or IP", 200)
_GUICtrlListView_SetExtendedListViewStyle($List2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$Rms3 = GUICtrlCreateButton("Remove from list", 310, 287, 100, 25, 0)
$Clr3 = GUICtrlCreateButton("Clear list", 440, 287, 70, 25, 0)


GUICtrlCreateTabItem("")
$PL11 = GUICtrlCreateLabel("Thread priority:", 350, 325, 74, 17)
$PCB1 = GUICtrlCreateCombo("", 428, 323, 90, 17)
GUICtrlSetData($PCB1, "Low|Below Normal|Normal|Above Normal|High|Real Time")
_GUICtrlComboBox_SetCurSel($PCB1, 2)
$LOG = GUICtrlCreateButton("View Log", 302, 370, 70, 25, 0)
$HLP = GUICtrlCreateButton("Help", 374, 370, 70, 25, 0)
$EX = GUICtrlCreateButton("Execute", 445, 370, 70, 25, 0)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)

If RegRead($PsExecReg, 'EulaAccepted') = '' Then RegWrite($PsExecReg, 'EulaAccepted', 'REG_DWORD', 1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            FileDelete(@TempDir & '\PsExec.exe')
            FileDelete(@TempDir & '\Psexec.log')
            ExitLoop
        Case $LOG
            ShellExecute(@TempDir & '\PSexec.log', '', @TempDir)
        Case $Slider
            GUICtrlSetData($SliderLbl, 'Timeount Connecting To Remote ' & GUICtrlRead($Slider) & ' Secs.')
        Case $Browse1, $Browse2
            ;If browse buttong is selected will read selection and set data to input box
            $FileFullName = FileOpenDialog("Browse", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All Files (*.*)")
            If @error Then ContinueLoop
            If $nMsg = $Browse1 Then
                GUICtrlSetData($App, $FileFullName)
            Else
                GUICtrlSetData($CL, $FileFullName)
            EndIf
        Case $Browse3
            $FolderName = FileSelectFolder("Browse", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 2)
            If @error Then ContinueLoop
            GUICtrlSetData($Wkd, $FolderName)
        Case $PCB2
            clear($List2)
            $CursorID = MouseGetCursor()
            GUICtrlSetCursor($List2, 15)
            $aCompList = _NetServerEnum($SV_TYPE_WORKSTATION, _GUICtrlComboBox_GetEditText($PCB2))
            If IsArray($aCompList) Then
                For $x = 1 To $aCompList[0]
                    _GUICtrlListView_AddItem($List2, $aCompList[$x])
                Next
            EndIf
            GUICtrlSetCursor($List2, $CursorID)
        Case $Add
            ;check if remote computer was specified
            $PC = GUICtrlRead($RPC)
            _GUICtrlListView_AddItem($List0, $PC)
            GUICtrlSetData($RPC, "")
            GUICtrlSetState($RPC, $GUI_FOCUS)
        Case $Clr1, $Clr2, $Clr3
            ;Clears list1 on Enter name tab if clear button is pressed
            $ClearList = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            Clear($ClearList)
        Case $Load
            ;loads file for load pc list tab list2 box
            $PCL = GUICtrlRead($CL)
            If $PCL <> "" Then load($PCL)
            GUICtrlSetData($CL, "")
        Case $Rms1, $Rms2, $Rms3
            ;removes selected item
            $ClearSelected = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($ClearSelected))
        Case $HLP
            _IECreate('http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx')
        Case $EX
            Local $d = '', $c = '', $v = '', $f = '', $e = '', $s = '', $i = '', $w = '', $l = '', $USN = '', $PAS = '', $TO = ''
            $CursorID = MouseGetCursor()
            GUISetCursor(15)
            ;reads app input box
            $AP = StringStripWS(GUICtrlRead($App), 3)
            ;Don't wait for process to terminate
            If BitAND(GUICtrlRead($PCH6), $GUI_CHECKED) = $GUI_CHECKED Then $d = ' -d'
            ;Copy file to remote machine
            If BitAND(GUICtrlRead($PCH3), $GUI_CHECKED) = $GUI_CHECKED Then $c = ' -c'
            ;Copy if newer or higher version
            If BitAND(GUICtrlRead($PCH5), $GUI_CHECKED) = $GUI_CHECKED And BitAND(GUICtrlRead($PCH3), $GUI_CHECKED) = $GUI_CHECKED Then $v = ' -v'
            ;Overwrite existing file
            If BitAND(GUICtrlRead($PCH4), $GUI_CHECKED) = $GUI_CHECKED And BitAND(GUICtrlRead($PCH3), $GUI_CHECKED) = $GUI_CHECKED Then $f = ' -f'
            ;Run application in the system account
            If BitAND(GUICtrlRead($PCH2), $GUI_CHECKED) = $GUI_CHECKED Then $s = ' -s'
            ;Interact with the users desktop
            If BitAND(GUICtrlRead($PCH1), $GUI_CHECKED) = $GUI_CHECKED Then $i = ' -i'
            ;Does not load the speified account's profile.
            If BitAND(GUICtrlRead($PCH9), $GUI_CHECKED) = $GUI_CHECKED Then $e = ' -e'
            ;Run process as limeted user
            If BitAND(GUICtrlRead($PCH8), $GUI_CHECKED) = $GUI_CHECKED Then $e = ' -l'
            ;reads any command line options were specified
            $CO = StringStripWS(GUICtrlRead($CLO), 3)
            ;Specifies what priority was selected
            $P = StringLower('-' & StringReplace(_GUICtrlComboBox_GetEditText($PCB1), ' ', ''))
            ;Timeout connecting to remote machine
            $TO = ' -n ' & GUICtrlRead($Slider)
            ;Depending which tab is active create the correct computer list
            $list = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            ;checks if alternate username was specified
            If GUICtrlRead($Wkd) <> '' Then $w = ' -w "' & GUICtrlRead($Wkd) & '"'
            $USN = GUICtrlRead($Usrnm)
            If $USN <> '' Then
                $USN = ' -u "' & GUICtrlRead($Usrnm) & '"'
                $PAS = ' -p ' & GUICtrlRead($Pw)
            EndIf
            ;Execution loop
            While 2
                If $AP = '' Then
                    MsgBox(0, "", "No application was specified.")
                Else
                    $IC = _GUICtrlListView_GetItemCount($list)
                    If $IC = 0 Then MsgBox(0, '', 'Need to add a computer name or ip to the list.')
                    If $IC > 1 Then ProgressOn('', 'Processing ', '', Default, Default)
                    For $item = 0 To $IC - 1
                        $FL = 'psexec.exe \\' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item) & $USN & $PAS & $TO & $s & $e & $i & $c & $v & $f & $w & $d & ' ' & $P & ' "' & $AP & '" "' & $CO & '"'
;ConsoleWrite($FL & @CRLF)
                        If $IC > 1 Then ProgressSet(Int(($item+1)/$IC*100), 'Step ' & $item + 1 & ' of ' & $IC, 'Processing ' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item))
                        $Pid = Run(@ComSpec & ' /c ' & $FL, @TempDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
                        $Handle = _ProcessExitCode($Pid)
                        ShowStdOutErr($Pid, 0)
                        $ExitCode = _ProcessExitCode($Pid, $Handle)
                        _ProcessCloseHandle($Handle)
                        If $USN <> '' Then $FL = StringReplace($FL, $PAS, ' -p (password is not logged)')
                        _FileWriteLog(@TempDir & '\PSexec.log', $FL)
                        FileWriteLine(@TempDir & '\PSexec.log', @TAB & 'ErrorCode: ' & $ExitCode & ' ' & _GetExitCode($ExitCode) & @CRLF & @CRLF)
                    Next
                    If $IC > 1 Then ProgressOff()
                EndIf
                ExitLoop
            WEnd
            GUISetCursor($CursorID)
    EndSwitch
WEnd

;load pc list from text file
Func Load($list)
    $file = FileOpen($list, 0)
    If $file = -1 Then
        MsgBox(0, 'Error', 'Unable To open file')
    EndIf
    While 2
        $FRPCL = FileReadLine($file)
        If @error = -1 Then ExitLoop
        _GUICtrlListView_AddItem($List1, $FRPCL)
    WEnd
EndFunc   ;==>Load

;clears array and list
Func Clear($listview)
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listview))
EndFunc   ;==>Clear

; Unknown programmer
Func _NetServerEnum ($iSrvType = -1, $sDomain = '')
    Local $uBufPtr = DllStructCreate("ptr;int;int"), $res[1]=[0], $i
    Local $uRecord = DllStructCreate("dword;ptr"), $iRecLen = DllStructGetSize($uRecord)
    Local $uString = DllStructCreate("char[16]")
    Local $uDomain = DllStructCreate("byte[32]"), $pDomain = 0
    If Not ($sDomain='' Or $sDomain='*') Then
        DllStructSetData($uDomain, 1, StringToBinary($sDomain,2))
        $pDomain = DllStructGetPtr($uDomain)
    EndIf
    Local $ret = DllCall ("netapi32.dll", "int", "NetServerEnum", _
        "ptr", 0, "int", 100, _
        "ptr", DllStructGetPtr($uBufPtr,1), "int", -1, _
        "ptr", DllStructGetPtr($uBufPtr,2), _
        "ptr", DllStructGetPtr($uBufPtr,3), _
        "int", $iSrvType, "ptr", $pDomain, "int", 0 )
    If $ret[0] Then Return SetError(1, $ret[0], '')
    Local $res[DllStructGetData($uBufPtr,3)+1]=[DllStructGetData($uBufPtr,3)]
    For $i=1 To DllStructGetData($uBufPtr,3)
        Local $uRecord = DllStructCreate("dword;ptr", DllStructGetData($uBufPtr,1)+($i-1)*$iRecLen)
        Local $sNBName = DllStructCreate("byte[32]", DllStructGetData($uRecord,2))
        DllStructSetData($uString,1,BinaryToString(DllStructGetData($sNBName,1),2))
        $res[$i] = DllStructGetData($uString,1)
    Next
    $ret = DllCall ("netapi32.dll", "int", "NetApiBufferFree", "ptr", DllStructGetData($uBufPtr,1))
    Return $res
EndFunc

;===============================================================================
;
; Function Name:    _ProcessExitCode()
; Description:      Returns a handle/exitcode from use of Run().
; Parameter(s):     $i_Pid        - ProcessID returned from a Run() execution
;                   $h_Process    - Process handle
; Requirement(s):   None
; Return Value(s):  On Success - Returns Process handle while Run() is executing
;                                (use above directly after Run() line with only PID parameter)
;                              - Returns Process Exitcode when Process does not exist
;                                (use above with PID and Process Handle parameter returned from first UDF call)
;                   On Failure - 0
; Author(s):        MHz (Thanks to DaveF for posting these DllCalls in Support Forum)
;
;===============================================================================
;
Func _ProcessExitCode($i_Pid, $h_Process = 0)
    ; 0 = Return Process Handle of PID else use Handle to Return Exitcode of a PID
    Local $v_Placeholder
    If Not IsArray($h_Process) Then
        ; Return the process handle of a PID
        $h_Process = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'int', 0x400, 'int', 0, 'int', $i_Pid)
        If Not @error Then Return $h_Process
    Else
        ; Return Process Exitcode of PID
        $h_Process = DllCall('kernel32.dll', 'ptr', 'GetExitCodeProcess', 'ptr', $h_Process[0], 'int*', $v_Placeholder)
        If Not @error Then Return $h_Process[2]
    EndIf
    Return 0
EndFunc   ;==>_ProcessExitCode

Func _ProcessCloseHandle($h_Process)
    ; Close the process handle of a PID
    DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $h_Process)
    If Not @error Then Return 1
    Return 0
EndFunc   ;==>_ProcessCloseHandle

Func ShowStdOutErr($l_Handle, $ShowConsole = 1)
    Local $Line, $tot_out, $err1 = 0, $err2 = 0
    Do
        Sleep(10)
        $Line = StdoutRead($l_Handle)
        $err1 = @error
        $tot_out &= $Line
        If $ShowConsole Then ConsoleWrite($Line)
        $Line = StderrRead($l_Handle)
        $err2 = @error
        $tot_out &= $Line
        If $ShowConsole Then ConsoleWrite($Line)
    Until $err1 And $err2
    Return $tot_out
EndFunc   ;==>ShowStdOutErr

Func _GetExitCode($iExitCode)
    Local $sLine = ''
    $Pid = Run(@ComSpec & " /c net helpmsg " & $iExitCode, @SystemDir, @SW_HIDE, 2)
    While 1
        $sLine &= StdoutRead($Pid)
        If @error Then ExitLoop
    Wend
    Return(StringStripWS(StringStripCR($sLine), 3))
EndFunc
Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Wow. That's basically what I was trying to achieve, but I don't know if I'd have got there!

I'll take a look and see if I can figure out how this works and maybe add some of my own features to it.

My ultimate plan was to be able to create a repository of the commands that I would use most, so they can quickly be selected by browsing and new ones can easily be added by saving the command.

I guess I'll see if I can get that going.

Link to comment
Share on other sites

My ultimate plan was to be able to create a repository of the commands that I would use most, so they can quickly be selected by browsing and new ones can easily be added by saving the command.

I guess I'll see if I can get that going.

Like the idea. Done...

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=PsexecGUIMenu.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#NoTrayIcon
#include <Crypt.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <StatusBarConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <GuiListView.au3>
#include <file.au3>
#include <GuiTab.au3>
#include <IE.au3>

FileInstall('.\Include\Psexec.exe', @TempDir & '\')

Global Const $SV_TYPE_WORKSTATION = 0x1
Global Const $SV_TYPE_SERVER = 0x2
Global Const $SV_TYPE_SQLSERVER = 0x4
Global Const $SV_TYPE_DOMAIN_CTRL = 0x8
Global Const $SV_TYPE_DOMAIN_BAKCTRL = 0x10
Global Const $SV_TYPE_TIME_SOURCE = 0x20
Global Const $SV_TYPE_AFP = 0x40
Global Const $SV_TYPE_NOVELL = 0x80
Global Const $SV_TYPE_DOMAIN_MEMBER = 0x100
Global Const $SV_TYPE_PRINTQ_SERVER = 0x200
Global Const $SV_TYPE_DIALIN_SERVER = 0x400
Global Const $SV_TYPE_XENIX_SERVER = 0x800
Global Const $SV_TYPE_NT = 0x1000
Global Const $SV_TYPE_WFW = 0x2000
Global Const $SV_TYPE_SERVER_MFPN = 0x4000
Global Const $SV_TYPE_SERVER_NT = 0x8000
Global Const $SV_TYPE_POTENTIAL_BROWSER = 0x10000
Global Const $SV_TYPE_BACKUP_BROWSER = 0x20000
Global Const $SV_TYPE_MASTER_BROWSER = 0x40000
Global Const $SV_TYPE_DOMAIN_MASTER = 0x80000
Global Const $SV_TYPE_WINDOWS = 0x400000
Global Const $SV_TYPE_CLUSTER_NT = 0x1000000
Global Const $SV_TYPE_TERMINALSERVER = 0x2000000
Global Const $SV_TYPE_CLUSTER_VS_NT  = 0x4000000
Global Const $SV_TYPE_LOCAL_LIST_ONLY = 0x40000000
Global Const $SV_TYPE_DOMAIN_ENUM = 0x80000000
Global Const $SV_TYPE_ALL = 0xFFFFFFFF
Global Const $PsExecReg = 'HKCU\Software\Sysinternals\PsExec'

Local $DomainList = _NetServerEnum($SV_TYPE_DOMAIN_ENUM)
$DomainList = _ArrayToString($DomainList, '|', 1)

$PS = 'psexec.exe'
$TOOLS = GUICreate("PSexec GUI", 532, 455, -1, -1, $WS_SYSMENU)

$filemenu = GUICtrlCreateMenu("&File")
$loaditem = GUICtrlCreateMenuItem("Load", $filemenu)
$saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
$helpmenu = GUICtrlCreateMenu("?")
$helpitem = GUICtrlCreateMenuItem("Help", $helpmenu)

$App = GUICtrlCreateInput("", 8, 24, 201, 21)
$Browse1 = GUICtrlCreateButton("Browse", 218, 23, 75, 23, 0)
$PL2 = GUICtrlCreateLabel("Application to run on remote PC", 8, 6, 184, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$CLO = GUICtrlCreateInput("", 8, 67, 289, 21)
$PL3 = GUICtrlCreateLabel("Command line parameters", 8, 50, 148, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$PL4 = GUICtrlCreateLabel("Admin User Name", 8, 95, 124, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$PL5 = GUICtrlCreateLabel("Admin Password", 155, 95, 124, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Usrnm = GUICtrlCreateInput("", 8, 112, 143, 21)
$Pw = GUICtrlCreateInput("", 155, 112, 143, 21, $ES_PASSWORD)
$PCH8 = GUICtrlCreateCheckbox("Run process as limited user", 16, 138, 225, 17)
$PCH9 = GUICtrlCreateCheckbox("Does not load the specified account's profile", 16, 154, 226, 17)
$Group1 = GUICtrlCreateGroup("Parameters", 8, 178, 289, 225)
$PCH1 = GUICtrlCreateCheckbox("Interact with the users desktop", 16, 194, 185, 17)
$PCH2 = GUICtrlCreateCheckbox("Run application in the system account", 16, 210, 225, 17)
$PCH3 = GUICtrlCreateCheckbox("Copy file to remote", 16, 226, 113, 17)
$Group2 = GUICtrlCreateGroup("Copy Options", 40, 245, 250, 54)
$PCH4 = GUICtrlCreateRadio("Overwrite existing file", 48, 261, 121, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$PCH5 = GUICtrlCreateRadio("Copy file only if it is a higher version or newer", 48, 278, 241, 17)
$PCH6 = GUICtrlCreateCheckbox("Don't wait for the process to terminate", 16, 300, 225, 17)
$SliderLbl = GUICtrlCreateLabel('Timeount Connecting To Remote 15 Secs.', 16, 318, 275, 21, $SS_CENTER)
$Slider = GUICtrlCreateSlider(16, 335, 275, 21)
    GUICtrlSetLimit(-1, 120, 1)
    GUICtrlSetData(-1, 15)

$Wkd = GUICtrlCreateInput("", 16, 378, 201, 21)
$Browse3 = GUICtrlCreateButton("Browse", 220, 377, 75, 23, 0)
GUICtrlCreateLabel("Working directory on remote PC", 16, 360, 184, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$PT1 = GUICtrlCreateTab(304, 8, 217, 313)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$PTS1 = GUICtrlCreateTabItem("Enter Name")
$RPC = GUICtrlCreateInput("", 312, 56, 137, 21)
$PL6 = GUICtrlCreateLabel("Remote PC name (or add PC to the list)", 312, 32, 188, 17)
$Add = GUICtrlCreateButton("Add", 456, 54, 41, 25, 0)
$List0 = GUICtrlCreateListView("", 310, 85, 200, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $WS_VSCROLL))
_GUICtrlListView_InsertColumn($List0, 0, "Machine name or IP", 200)
_GUICtrlListView_SetExtendedListViewStyle($List0, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$Rms1 = GUICtrlCreateButton("Remove from list", 310, 287, 100, 25, 0)
$Clr1 = GUICtrlCreateButton("Clear list", 440, 287, 70, 25, 0)
$PTS2 = GUICtrlCreateTabItem("Load PC List")
$PL7 = GUICtrlCreateLabel("Load text file (one pc name per line)", 312, 34, 172, 17)
$CL = GUICtrlCreateInput("", 312, 56, 156, 21)
$Browse2 = GUICtrlCreateButton("Browse", 470, 54, 41, 25, 0)
$List1 = GUICtrlCreateListView("", 310, 85, 200, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $WS_VSCROLL))
_GUICtrlListView_InsertColumn($List1, 0, "Machine name or IP", 200)
_GUICtrlListView_SetExtendedListViewStyle($List1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$Rms2 = GUICtrlCreateButton("Remove From List", 310, 287, 100, 25, 0)
$Clr2 = GUICtrlCreateButton("Clear List", 440, 287, 70, 25, 0)


$PTS3 = GUICtrlCreateTabItem("Browse Net")
GUICtrlCreateLabel("Select Domain", 330, 38, 172, 17)
$PCB2 = GUICtrlCreateCombo("", 310, 56, 121, 21)
GUICtrlSetData($PCB2, $DomainList)
$List2 = GUICtrlCreateListView("", 310, 85, 200, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $WS_VSCROLL))
_GUICtrlListView_InsertColumn($List2, 0, "Machine name or IP", 200)
_GUICtrlListView_SetExtendedListViewStyle($List2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$Rms3 = GUICtrlCreateButton("Remove from list", 310, 287, 100, 25, 0)
$Clr3 = GUICtrlCreateButton("Clear list", 440, 287, 70, 25, 0)


GUICtrlCreateTabItem("")
$PL11 = GUICtrlCreateLabel("Thread priority:", 350, 325, 74, 17)
$PCB1 = GUICtrlCreateCombo("", 428, 323, 90, 17)
GUICtrlSetData($PCB1, "Low|Below Normal|Normal|Above Normal|High|Real Time")
_GUICtrlComboBox_SetCurSel($PCB1, 2)
$LOG = GUICtrlCreateButton("View Log", 374, 370, 70, 25, 0)
$EX = GUICtrlCreateButton("Execute", 445, 370, 70, 25, 0)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)

If RegRead($PsExecReg, 'EulaAccepted') = '' Then RegWrite($PsExecReg, 'EulaAccepted', 'REG_DWORD', 1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exititem
            FileDelete(@TempDir & '\PsExec.exe')
            FileDelete(@TempDir & '\Psexec.log')
            ExitLoop
        Case $LOG
            ShellExecute(@TempDir & '\PSexec.log', '', @TempDir)
        Case $loaditem
            $sFileName = FileOpenDialog('', "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", '(*.Exec)', 3, '', $TOOLS)
            If @error Then ContinueLoop

            GUICtrlSetState($PCH3, IniRead($sFileName, 'Settings', 'c', ''))
            GUICtrlSetState($PCH6, IniRead($sFileName, 'Settings', 'd', ''))
            GUICtrlSetState($PCH9, IniRead($sFileName, 'Settings', 'e', ''))
            GUICtrlSetState($PCH4, IniRead($sFileName, 'Settings', 'f', ''))
            GUICtrlSetState($PCH1, IniRead($sFileName, 'Settings', 'i', ''))
            GUICtrlSetState($PCH8, IniRead($sFileName, 'Settings', 'l', ''))
            GUICtrlSetData($SliderLbl, 'Timeount Connecting To Remote ' & IniRead($sFileName, 'Settings', 'n', '') & ' Secs.')
            GUICtrlSetData($Slider, Number(IniRead($sFileName, 'Settings', 'n', '')))

            GUICtrlSetData($Pw, BinaryToString(_Crypt_DecryptData(IniRead($sFileName, 'Settings', 'p', ''), $sFileName, $CALG_RC4)))

            GUICtrlSetState($PCH2, IniRead($sFileName, 'Settings', 's', ''))
            GUICtrlSetData($Usrnm, IniRead($sFileName, 'Settings', 'u', ''))
            GUICtrlSetState($PCH5, IniRead($sFileName, 'Settings', 'v', ''))
            GUICtrlSetData($Wkd, IniRead($sFileName, 'Settings', 'w', ''))
            GUICtrlSetData($PCB1, IniRead($sFileName, 'Settings', 'priority', ''))
            GUICtrlSetData($App, IniRead($sFileName, 'Settings', 'Application', ''))
            GUICtrlSetData($CLO, IniRead($sFileName, 'Settings', 'Parameters', ''))

            $list = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            $aCompList = IniReadSection($sFileName, 'ComputerList')
            If IsArray($aCompList) Then
                Clear($list)
                For $item = 1 To $aCompList[0][0]
                    _GUICtrlListView_AddItem($list, $aCompList[$item][1])
                Next
            EndIf
        Case $saveitem
            $sFileName = FileSaveDialog('', "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", '(*.Exec)', 18, '', $TOOLS)
            If @error Then ContinueLoop
            If Not StringInStr($sFileName, '.Exec') Then $sFileName &= '.Exec'

            _Crypt_Startup()
            $hKey = _Crypt_DeriveKey($sFileName, $CALG_RC4)

            IniWrite($sFileName, 'Settings', 'c', GUICtrlRead($PCH3))
            IniWrite($sFileName, 'Settings', 'd', GUICtrlRead($PCH6))
            IniWrite($sFileName, 'Settings', 'e', GUICtrlRead($PCH9))
            IniWrite($sFileName, 'Settings', 'f', GUICtrlRead($PCH4))
            IniWrite($sFileName, 'Settings', 'i', GUICtrlRead($PCH1))
            IniWrite($sFileName, 'Settings', 'l', GUICtrlRead($PCH8))
            IniWrite($sFileName, 'Settings', 'n', GUICtrlRead($Slider))

            IniWrite($sFileName, 'Settings', 'p', _Crypt_EncryptData(GUICtrlRead($Pw), $hKey, $CALG_USERKEY))

            IniWrite($sFileName, 'Settings', 's', GUICtrlRead($PCH2))
            IniWrite($sFileName, 'Settings', 'u', GUICtrlRead($Usrnm))
            IniWrite($sFileName, 'Settings', 'v', GUICtrlRead($PCH5))
            IniWrite($sFileName, 'Settings', 'w', GUICtrlRead($Wkd))
            IniWrite($sFileName, 'Settings', 'priority', _GUICtrlComboBox_GetEditText($PCB1))
            IniWrite($sFileName, 'Settings', 'Application', GUICtrlRead($App))
            IniWrite($sFileName, 'Settings', 'Parameters', StringStripWS(GUICtrlRead($CLO), 3))

            $list = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            $IC = _GUICtrlListView_GetItemCount($list)
            For $item = 0 To $IC - 1
                IniWrite($sFileName, 'ComputerList', $item, _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item))
            Next
            _Crypt_DestroyKey($hKey)
            _Crypt_Shutdown()
        Case $Slider
            GUICtrlSetData($SliderLbl, 'Timeount Connecting To Remote ' & GUICtrlRead($Slider) & ' Secs.')
        Case $Browse1, $Browse2
            ;If browse buttong is selected will read selection and set data to input box
            $FileFullName = FileOpenDialog("Browse", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All Files (*.*)")
            If @error Then ContinueLoop
            If $nMsg = $Browse1 Then
                GUICtrlSetData($App, $FileFullName)
            Else
                GUICtrlSetData($CL, $FileFullName)
                $PCL = GUICtrlRead($CL)
                If $PCL <> "" Then load($PCL)
            EndIf
        Case $Browse3
            $FolderName = FileSelectFolder("Browse", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 2)
            If @error Then ContinueLoop
            GUICtrlSetData($Wkd, $FolderName)
        Case $PCB2
            clear($List2)
            $CursorID = MouseGetCursor()
            GUICtrlSetCursor($List2, 15)
            $aCompList = _NetServerEnum($SV_TYPE_WORKSTATION, _GUICtrlComboBox_GetEditText($PCB2))
            If IsArray($aCompList) Then
                For $x = 1 To $aCompList[0]
                    _GUICtrlListView_AddItem($List2, $aCompList[$x])
                Next
            EndIf
            GUICtrlSetCursor($List2, $CursorID)
        Case $Add
            ;check if remote computer was specified
            $PC = GUICtrlRead($RPC)
            _GUICtrlListView_AddItem($List0, $PC)
            GUICtrlSetData($RPC, "")
            GUICtrlSetState($RPC, $GUI_FOCUS)
        Case $Clr1, $Clr2, $Clr3
            ;Clears list1 on Enter name tab if clear button is pressed
            $ClearList = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            Clear($ClearList)
        Case $Rms1, $Rms2, $Rms3
            ;removes selected item
            $ClearSelected = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($ClearSelected))
        Case $helpitem
            If Ping('www.google.com') = 0 Then
                Run(@ComSpec & ' /k ' & @TempDir & '\PsExec.exe /?', @TempDir, @SW_MAXIMIZE)
            Else
                _IECreate('http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx')
            EndIf
        Case $EX
            Local $d = '', $c = '', $v = '', $f = '', $e = '', $s = '', $i = '', $w = '', $l = '', $USN = '', $PAS = '', $TO = ''
            $CursorID = MouseGetCursor()
            GUISetCursor(15)
            ;reads app input box
            $AP = StringStripWS(GUICtrlRead($App), 3)
            ;Don't wait for process to terminate
            If BitAND(GUICtrlRead($PCH6), $GUI_CHECKED) = $GUI_CHECKED Then $d = ' -d'
            ;Copy file to remote machine
            If BitAND(GUICtrlRead($PCH3), $GUI_CHECKED) = $GUI_CHECKED Then $c = ' -c'
            ;Copy if newer or higher version
            If BitAND(GUICtrlRead($PCH5), $GUI_CHECKED) = $GUI_CHECKED And BitAND(GUICtrlRead($PCH3), $GUI_CHECKED) = $GUI_CHECKED Then $v = ' -v'
            ;Overwrite existing file
            If BitAND(GUICtrlRead($PCH4), $GUI_CHECKED) = $GUI_CHECKED And BitAND(GUICtrlRead($PCH3), $GUI_CHECKED) = $GUI_CHECKED Then $f = ' -f'
            ;Run application in the system account
            If BitAND(GUICtrlRead($PCH2), $GUI_CHECKED) = $GUI_CHECKED Then $s = ' -s'
            ;Interact with the users desktop
            If BitAND(GUICtrlRead($PCH1), $GUI_CHECKED) = $GUI_CHECKED Then $i = ' -i'
            ;Does not load the speified account's profile.
            If BitAND(GUICtrlRead($PCH9), $GUI_CHECKED) = $GUI_CHECKED Then $e = ' -e'
            ;Run process as limeted user
            If BitAND(GUICtrlRead($PCH8), $GUI_CHECKED) = $GUI_CHECKED Then $e = ' -l'
            ;reads any command line options were specified
            $CO = StringStripWS(GUICtrlRead($CLO), 3)
            ;Specifies what priority was selected
            $P = StringLower('-' & StringReplace(_GUICtrlComboBox_GetEditText($PCB1), ' ', ''))
            ;Timeout connecting to remote machine
            $TO = ' -n ' & GUICtrlRead($Slider)
            ;Depending which tab is active create the correct computer list
            $list = Eval('List' & _GUICtrlTab_GetCurSel($PT1))
            ;checks if alternate username was specified
            If GUICtrlRead($Wkd) <> '' Then $w = ' -w "' & GUICtrlRead($Wkd) & '"'
            $USN = GUICtrlRead($Usrnm)
            If $USN <> '' Then
                $USN = ' -u "' & GUICtrlRead($Usrnm) & '"'
                $PAS = ' -p ' & GUICtrlRead($Pw)
            EndIf
            ;Execution loop
            While 2
                If $AP = '' Then
                    MsgBox(0, "", "No application was specified.")
                Else
                    $IC = _GUICtrlListView_GetItemCount($list)
                    If $IC = 0 Then MsgBox(0, '', 'Need to add a computer name or ip to the list.')
                    If $IC > 1 Then ProgressOn('', 'Processing ', '', Default, Default)
                    For $item = 0 To $IC - 1
                        $FL = 'psexec.exe \\' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item) & $USN & $PAS & $TO & $s & $e & $i & $c & $v & $f & $w & $d & ' ' & $P & ' "' & $AP & '" "' & $CO & '"'
;ConsoleWrite($FL & @CRLF)
                        If $IC > 1 Then ProgressSet(Int(($item+1)/$IC*100), 'Step ' & $item + 1 & ' of ' & $IC, 'Processing ' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item))
                        $Pid = Run(@ComSpec & ' /c ' & $FL, @TempDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
                        $Handle = _ProcessExitCode($Pid)
                        ShowStdOutErr($Pid, 0)
                        $ExitCode = _ProcessExitCode($Pid, $Handle)
                        _ProcessCloseHandle($Handle)
                        If $USN <> '' Then $FL = StringReplace($FL, $PAS, ' -p (password is not logged)')
                        _FileWriteLog(@TempDir & '\PSexec.log', $FL)
                        FileWriteLine(@TempDir & '\PSexec.log', @TAB & 'ErrorCode: ' & $ExitCode & ' ' & _GetExitCode($ExitCode) & @CRLF & @CRLF)
                    Next
                    If $IC > 1 Then ProgressOff()
                EndIf
                ExitLoop
            WEnd
            GUISetCursor($CursorID)
    EndSwitch
WEnd

;load pc list from text file
Func Load($list)
    $file = FileOpen($list, 0)
    If $file = -1 Then
        MsgBox(0, 'Error', 'Unable To open file')
    EndIf
    While 2
        $FRPCL = FileReadLine($file)
        If @error = -1 Then ExitLoop
        _GUICtrlListView_AddItem($List1, $FRPCL)
    WEnd
EndFunc   ;==>Load

;clears array and list
Func Clear($listview)
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listview))
EndFunc   ;==>Clear

; Unknown programmer
Func _NetServerEnum ($iSrvType = -1, $sDomain = '')
    Local $uBufPtr = DllStructCreate("ptr;int;int"), $res[1]=[0], $i
    Local $uRecord = DllStructCreate("dword;ptr"), $iRecLen = DllStructGetSize($uRecord)
    Local $uString = DllStructCreate("char[16]")
    Local $uDomain = DllStructCreate("byte[32]"), $pDomain = 0
    If Not ($sDomain='' Or $sDomain='*') Then
        DllStructSetData($uDomain, 1, StringToBinary($sDomain,2))
        $pDomain = DllStructGetPtr($uDomain)
    EndIf
    Local $ret = DllCall ("netapi32.dll", "int", "NetServerEnum", _
        "ptr", 0, "int", 100, _
        "ptr", DllStructGetPtr($uBufPtr,1), "int", -1, _
        "ptr", DllStructGetPtr($uBufPtr,2), _
        "ptr", DllStructGetPtr($uBufPtr,3), _
        "int", $iSrvType, "ptr", $pDomain, "int", 0 )
    If $ret[0] Then Return SetError(1, $ret[0], '')
    Local $res[DllStructGetData($uBufPtr,3)+1]=[DllStructGetData($uBufPtr,3)]
    For $i=1 To DllStructGetData($uBufPtr,3)
        Local $uRecord = DllStructCreate("dword;ptr", DllStructGetData($uBufPtr,1)+($i-1)*$iRecLen)
        Local $sNBName = DllStructCreate("byte[32]", DllStructGetData($uRecord,2))
        DllStructSetData($uString,1,BinaryToString(DllStructGetData($sNBName,1),2))
        $res[$i] = DllStructGetData($uString,1)
    Next
    $ret = DllCall ("netapi32.dll", "int", "NetApiBufferFree", "ptr", DllStructGetData($uBufPtr,1))
    Return $res
EndFunc

;===============================================================================
;
; Function Name:    _ProcessExitCode()
; Description:      Returns a handle/exitcode from use of Run().
; Parameter(s):     $i_Pid        - ProcessID returned from a Run() execution
;                   $h_Process    - Process handle
; Requirement(s):   None
; Return Value(s):  On Success - Returns Process handle while Run() is executing
;                                (use above directly after Run() line with only PID parameter)
;                              - Returns Process Exitcode when Process does not exist
;                                (use above with PID and Process Handle parameter returned from first UDF call)
;                   On Failure - 0
; Author(s):        MHz (Thanks to DaveF for posting these DllCalls in Support Forum)
;
;===============================================================================
;
Func _ProcessExitCode($i_Pid, $h_Process = 0)
    ; 0 = Return Process Handle of PID else use Handle to Return Exitcode of a PID
    Local $v_Placeholder
    If Not IsArray($h_Process) Then
        ; Return the process handle of a PID
        $h_Process = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'int', 0x400, 'int', 0, 'int', $i_Pid)
        If Not @error Then Return $h_Process
    Else
        ; Return Process Exitcode of PID
        $h_Process = DllCall('kernel32.dll', 'ptr', 'GetExitCodeProcess', 'ptr', $h_Process[0], 'int*', $v_Placeholder)
        If Not @error Then Return $h_Process[2]
    EndIf
    Return 0
EndFunc   ;==>_ProcessExitCode

Func _ProcessCloseHandle($h_Process)
    ; Close the process handle of a PID
    DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $h_Process)
    If Not @error Then Return 1
    Return 0
EndFunc   ;==>_ProcessCloseHandle

Func ShowStdOutErr($l_Handle, $ShowConsole = 1)
    Local $Line, $tot_out, $err1 = 0, $err2 = 0
    Do
        Sleep(10)
        $Line = StdoutRead($l_Handle)
        $err1 = @error
        $tot_out &= $Line
        If $ShowConsole Then ConsoleWrite($Line)
        $Line = StderrRead($l_Handle)
        $err2 = @error
        $tot_out &= $Line
        If $ShowConsole Then ConsoleWrite($Line)
    Until $err1 And $err2
    Return $tot_out
EndFunc   ;==>ShowStdOutErr

Func _GetExitCode($iExitCode)
    Local $sLine = ''
    $Pid = Run(@ComSpec & " /c net helpmsg " & $iExitCode, @SystemDir, @SW_HIDE, 2)
    While 1
        $sLine &= StdoutRead($Pid)
        If @error Then ExitLoop
    Wend
    Return(StringStripWS(StringStripCR($sLine), 3))
EndFunc
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

great script !

i've seen it in the forum before. just one question regarding the 'Working directory on remote Pc' part, it dosen't bring the 'my network places'? is it just my machine?

tron

Link to comment
Share on other sites

If you want to see the network places seach the script for:

Case $Browse3
            $FolderName = FileSelectFolder("Browse", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 2)

and change the CLSID number for "::{00028B00-0000-0000-C000-000000000046}"

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...