Jump to content

Recommended Posts

Posted

I have written a script that automatically installs a exe program located in a map drive on the network. It works fine if I'm at a computer and double clicking on the exe. However, if I use psexec, remote software installation utility or any other type of software that pushes out the exe to a remote computer, it doesn't work. I can see in task manager, process tab that the exe is running but nothing is happening. I would appreciate if anyone can help. Thanks in advance.

Posted (edited)

Here's something I use all the time.

You need to make sure "psexec.exe" is in the same folder as the script when you compile it.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=config.ico
#AutoIt3Wrapper_Outfile=PC_GUI.exe
#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_Res_Comment=Runs programs on remote computers with alternate credentials.
#AutoIt3Wrapper_Res_Description=Runs programs on remote computers with alternate credentials.
#AutoIt3Wrapper_Res_Fileversion=1.0.0.1
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_File_Add=psexec.exe
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#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 <array.au3>
#include <GuiListView.au3>
#include <file.au3>
#include <GuiTab.au3>
#include <IE.au3>

Opt("TrayIconHide", 1)
Opt("TrayAutoPause", 0)
$PS = 'psexec.exe'
$TO = ' -n 60'

$TOOLS = GUICreate("Remote Program GUI", 532, 420, -1, -1)
$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, 100, 124, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$PL5 = GUICtrlCreateLabel("Admin Password", 8, 120, 124, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$PL8 = GUICtrlCreateLabel("Domain/Workstation", 8, 140, 124, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$PCH8 = GUICtrlCreateCheckbox("Use Workstation ID (list mode)", 16, 158, 225, 17)
$Usrnm = GUICtrlCreateInput("", 140, 96, 157, 21)
$Pw = GUICtrlCreateInput("", 140, 116, 157, 21, $ES_PASSWORD)
$Domain = GUICtrlCreateInput("", 140, 136, 157, 21)
$Group1 = GUICtrlCreateGroup("Parameters", 8, 178, 289, 216)
$PCH1 = GUICtrlCreateCheckbox("Interact with the users desktop", 16, 194, 185, 17)
$PCH2 = GUICtrlCreateCheckbox("Run application in the system account", 16, 218, 225, 17)
$PCH3 = GUICtrlCreateCheckbox("Copy file to remote", 16, 242, 113, 17)
$Group2 = GUICtrlCreateGroup("Copy Options", 20, 265, 250, 54)
$PCH4 = GUICtrlCreateRadio("Overwrite existing file", 28, 278, 121, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$PCH5 = GUICtrlCreateRadio("Copy file only if it is a higher version or newer", 28, 295, 241, 17)
$PCH6 = GUICtrlCreateCheckbox("Don't wait for the process to terminate", 16, 325, 225, 17)
$PCH7 = GUICtrlCreateCheckbox("Show output window", 16, 344, 129, 17)
$PL11 = GUICtrlCreateLabel("Thread priority:", 16, 370, 74, 17)
$PR1 = GUICtrlCreateRadio("Low", 96, 368, 49, 17)
$PR2 = GUICtrlCreateRadio("Normal", 152, 368, 57, 17)
GUICtrlSetState($PR2, $GUI_CHECKED)
$PR3 = GUICtrlCreateRadio("High", 216, 368, 49, 17)
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)
$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))
$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)
$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))
$Rms2 = GUICtrlCreateButton("Remove from list", 310, 287, 100, 25, 0)
$Clr2 = GUICtrlCreateButton("Clear list", 440, 287, 70, 25, 0)
;$PTS3 = GUICtrlCreateTabItem("Browse Net")
GUICtrlCreateTabItem("")
$HLP = GUICtrlCreateButton("Help", 345, 350, 75, 25, 0)
$EX = GUICtrlCreateButton("Execute", 440, 350, 75, 25, 0)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Browse1
            ;If browse buttong is selected will read selection and set data to input box
            $browse11 = FileOpenDialog("Browse", "C:\", "All Files (*.*)")
            GUICtrlSetData($App, $browse11)
        Case $Add
            ;check if remote computer was specified
            $PC = GUICtrlRead($RPC)
            _GUICtrlListView_AddItem($List1, $PC)
        Case $Clr1
            ;Clears list1 on Enter name tab if clear button is pressed
            Clear($List1)
        Case $Clr2
            ;Clears list2 on Enter name tab if clear button is pressed
            Clear($List2)
        Case $Browse2
            ;If load button is selected will read selection and set data to input box
            $Browse22 = FileOpenDialog("Browse", "C:\", "All Files (*.*)")
            GUICtrlSetData($CL, $Browse22)
            $PCL = GUICtrlRead($CL)
        Case $Load
            ;loads file for load pc list tab list2 box
            load($PCL)
        Case $Rms1
            ;removes selected item
            _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List1))
        Case $Rms2
            ;removes selected item
            _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($List2))
        Case $HLP
            _IECreate('http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx')
        Case $EX
            ;reads app input box
            $AP = GUICtrlRead($App)
            ;sees if don't wait for process is checked
            $C6 = GUICtrlRead($PCH6)
            If $C6 = 1 Then
                $d = ' -d'
            Else
                $d = ''
            EndIf
            ;sees if copy file to remote pc was checked
            $C3 = GUICtrlRead($PCH3)
            If $C3 = 1 Then
                $c = ' -c'
            Else
                $c = ''
            EndIf
            ;sees if copy if newer version or date is checked
            $C5 = GUICtrlRead($PCH5)
            If 1 = $C5 And 1 = $C3 Then
                $v = ' -v'
            Else
                $v = ''
            EndIf
            ;sees if force overwrite is checked
            $C4 = GUICtrlRead($PCH4)
            If 1 = $C4 And 1 = $C3 Then
                $f = ' -f'
            Else
                $f = ''
            EndIf
            ;sees if run under system account is checked
            $C2 = GUICtrlRead($PCH2)
            If 1 = $C2 Then
                $s = ' -s'
            Else
                $s = ''
            EndIf
            ;sees if interact with desktop is checked
            $C1 = GUICtrlRead($PCH1)
            If 1 = $C1 Then
                $i = ' -i'
            Else
                $i = ''
            EndIf
            ;reads any command line options were specified
            $CO = GUICtrlRead($CLO)
            ;sees what priority was selected
            $P1 = GUICtrlRead($PR1)
            $P2 = GUICtrlRead($PR2)
            $P3 = GUICtrlRead($PR3)
            If $P1 = 1 Then
                $P = ' -low'
            ElseIf $P2 = 1 Then
                $P = ' -normal'
            ElseIf $P3 = 1 Then
                $P = ' -high'
            EndIf
            ;sees is display output was selected
            $C7 = GUICtrlRead($PCH7)
            If $C7 == 1 Then
                $sd = @SW_SHOW
            Else
                $sd = @SW_HIDE
            EndIf
            ;sees is workstation id was selected
            $C8 = GUICtrlRead($PCH8)
            If $C8 == 1 Then
                $wstn = 1
            Else
                $wstn = ''
            EndIf
            ;Execution loop
            While 2
                If $AP = '' Then
                    MsgBox(0, "", "No application was specified")
                    ExitLoop
                Else
                    ;depending on what tab is selected sets the correct list box
                    If _GUICtrlTab_GetItemState($PT1, 1) = 0 Then
                        ;BuildArray($list1)
                        $list = $List1
                    ElseIf _GUICtrlTab_GetItemState($PT1, 1) = 1 Then
                        ;BuildArray($list2)
                        $list = $List2
                    EndIf
                    $IC = _GUICtrlListView_GetItemCount($list)
                    For $item = 0 To $IC - 1
                        ;checks if alternate username was specified
                        $USN = GUICtrlRead($Usrnm)
                        If $USN <> '' And $wstn >= '' Then
                            $USN = '-u ' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item) & '\' & GUICtrlRead($Usrnm)
                            $PAS = ' -p ' & GUICtrlRead($Pw)
                        ElseIf $USN <> '' And $Domain == '' Then
                            $USN = '-u ' & GUICtrlRead($Usrnm)
                            $PAS = ' -p ' & GUICtrlRead($Pw)
                        ElseIf $USN <> '' Then
                            $USN = '-u ' & GUICtrlRead($Domain) & '\' & GUICtrlRead($Usrnm)
                            $PAS = ' -p ' & GUICtrlRead($Pw)
                        Else
                            $USN = ''
                            $PAS = ''
                        EndIf
                        $FL = @ComSpec & ' /c psexec.exe \\' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item) & ' ' & $USN & ' (pass is not logged)' & $TO & $s & $i & $c & $v & $f & $d & $P & ' "' & $AP & '" ' & $CO
                        _FileWriteLog(@TempDir & '\PSexec.log', $FL)
                        RunWait(@ComSpec & ' /c psexec.exe \\' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item) & ' ' & $USN & $PAS & $TO & $s & $i & $c & $v & $f & $d & $P & ' "' & $AP & '" ' & $CO & ' >>' & @TempDir & '\psexeccommand.' & _GUICtrlListView_GetItemText(GUICtrlGetHandle($list), $item) & '.log', @TempDir, $sd)
                    Next
                EndIf
                ;asks if the user would like to execute
                If 6 = MsgBox(4, 'Remote Program GUI', 'Done executing, do you want to exit?') Then
                    Exit
                Else
                    ;clears both lists if users selects yes
                    If 6 = MsgBox(4, 'Remote Program GUI', 'Do you want to clear the computer list?') Then
                        Clear($List1)
                        Clear($List2)
                        ExitLoop
                    Else
                        ExitLoop
                    EndIf
                EndIf
            WEnd
    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($List2, $FRPCL)
    WEnd
EndFunc   ;==>Load
;clears array and list
Func Clear($listview)
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listview))
EndFunc   ;==>Clear
Edited by 5t0n3r
Posted

Thanks for the gui interface for psexec but my script still does not work if I push it through the network. The script is set to run the workstation setup through a mapped drive and automatically install the program. It does work if I put it in a login script but I prefer to push install it at night.

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
  • Recently Browsing   0 members

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