Jump to content

Command line


Recommended Posts

#RequireAdmin

#include <MsgBoxConstants.au3>
#include "ProcessEx.au3"
$sOutput = _Process_RunCommand($PROCESS_RUNWAIT, $PROCESS_COMMAND & "dhcpbat.bat") ; Record the output
$iExitCode = @extended ; Note the exit code

if not @error and $iExitCode = 0 then ; if exitcode  = 0 i have reach end of the script
    ProcessClose($sOutput ) ; i can close the process even if there is a pause
    MsgBox('0',"","can exit now")
Else
    MsgBox('0',"","script did NOT complete - re-start exit now")
EndIf

This work for me, thanks  you both

Link to comment
Share on other sites

  • 2 weeks later...

hi can anyone improve on the code below or provide some advice

1. I have to run dos command prompt as admin at directory D:\Merchant\Connect"

2. the copyfile.exe have a space then the Ip address, not sure how to express that

Func addEpson()
;~$sMasterFolderPath = ("D:\Merchant\Connect")
$EpsonSilent= "epson.exe -f silent.properties"
$UpdateIP = "10.20.30.45"

if IsAdmin Then RunWait(@ComSpec & 'D:\Merchant\Connect' & $EpsonSilent, "", @SW_HIDE)
if isadmin Then RunWait (@ComSpec & 'D:\Merchant\Connect' & 'copyfile.exe' & $UpdateIP, "", @SW_HIDE)


EndFunc

 

IpEpsonCapture.JPG

Link to comment
Share on other sites

You should add /c and backslashes and space to your strings for example

Func addEpson()
    Local $EpsonSilent= "-f silent.properties"
    Local $UpdateIP = "10.20.30.45"
    If IsAdmin Then
        RunWait(@ComSpec & ' /c "D:\Merchant\Connect\epson.exe" ' & $EpsonSilent, "", @SW_HIDE)
        RunWait (@ComSpec & ' /c "D:\Merchant\Connect\copyfile.exe" ' & $UpdateIP, "", @SW_HIDE)
    EndIf
EndFunc

;~ Another way allows you to change folder path if required 
Func addEpson($sMasterFolderPath = 'D:\Merchant\Connect')
    Local $sEpsonSilent= '"' & $sMasterFolderPath & '\epson.exe" -f silent.properties'
    Local $sUpdateIP = '"' & $sMasterFolderPath & '\copyfile.exe" 10.20.30.45'
    If IsAdmin Then
        RunWait(@ComSpec & ' /c ' & $sEpsonSilent, "", @SW_HIDE)
        RunWait(@ComSpec & ' /c ' & $sUpdateIP, "", @SW_HIDE)
    EndIf
EndFunc

 

Link to comment
Share on other sites

hi big improvement Subzs  and thank you for the quick response  I prefer the second method however "Local $sUpdateIP"  the Ip address is a  variable and  NOT  static, therefore should be express as below

Local $sUpdateIP = '"' & $sMaster;~ Another way allows you to change folder path if required 

Func addEpson($sMasterFolderPath = 'D:\Merchant\Connect')
local $ipadress= 10.20.30.45
    Local $sEpsonSilent= '"' & $sMasterFolderPath & '\epson.exe" -f silent.properties'
    
    Local $sUpdateIP = '"' & $sMasterFolderPath & '\copyfile.exe" 10.20.30.45'
  ;~  Local $sUpdateIP = '"' & $sMasterFolderPath & '\copyfile.exe" '"' & $Ipaddress
   
   If IsAdmin Then
        RunWait(@ComSpec & ' /c ' & $sEpsonSilent, "", @SW_HIDE)
        RunWait(@ComSpec & ' /c ' & $sUpdateIP, "", @SW_HIDE)
    EndIf

 

 

Link to comment
Share on other sites

You can then use something like this:

addEpson('10.20.30.45')

Func addEpson($sUpdateIP, $sMasterFolderPath = 'D:\Merchant\Connect')
    If FileExists($sMasterFolderPath) = 0 Then Return 1
    Local $sEpsonSilent= '"' & $sMasterFolderPath & '\epson.exe" -f silent.properties'
    Local $sEpsonUpdate = '"' & $sMasterFolderPath & '\copyfile.exe" ' & $sUpdateIP
    If IsAdmin Then
        RunWait(@ComSpec & ' /c ' & $sEpsonSilent, "", @SW_HIDE)
        RunWait(@ComSpec & ' /c ' & $sEpsonUpdate, "", @SW_HIDE)
    EndIf
EndFunc

 

Link to comment
Share on other sites

i am trying to use this at a command line, it works however  I would like use the @desktop with the  @homedrive

Local $OracleRetail = FileGetShortName("c:\Users\rssupport\Desktop\POS Client Installer.exe") ;  cuurent running  pinpad desktop 
$OracleRetail = FileGetShortName (@UserProfileDir & "\desktop\POS Client Installer.exe") ; propose change
    
Local $Pinpad = ("c:\Users\rssupport\Desktop\Personalize.cmd") ; current running  personalize desktop

Local $Pinpad = ("%userprofile%\desktop\Personalize.cmd") ;propose change

 

Edited by antonioj84
error
Link to comment
Share on other sites

  • 2 weeks later...

is there a better way to check to confirm the   'runwait' was completed successfully ?. I understand  success =0  and failure is 1  thanks ahead

;~RunWait(@ComSpec & ' /c ' & $sEpsonSilent, "", @SW_HIDE)
;~RunWait(@ComSpec & ' /c ' & $sEpsonUpdate, "", @SW_HIDE)



$resultA= RunWait(@ComSpec & ' /c ' & $sEpsonSilent, "", @SW_HIDE)
if $resultA = 0  and not @error then

$resultB=RunWait(@ComSpec & ' /c ' & $sEpsonUpdate, "", @SW_HIDE)
if $ResultB = 0 and not @error then 
endif
endif

 

Edited by antonioj84
Link to comment
Share on other sites

;If IsAdmin() Then RunWait(@ComSpec & ' /c ' & $sDestination & "\SetModules.bat", @SystemDir, "", @SW_HIDE) ; must add system directory otherwise will not rum command
Global $sDestination = 'D:\Installers\EpsonJavaPosAdk\'
Global $SetmoduleBat=(@SystemDir & $sDestination &"\SetModules.Bat")

Personalize( $SetmoduleBat)



Func Personalize($PersORPInpad)

    $sOutput = _Process_RunCommand($PROCESS_RUNWAIT, $PROCESS_COMMAND & $PersORPInpad) ; Record the output for personalize or pinpad or setmodulesbat
    $iExitCode = @extended ; Note the exit code
    ;MsgBox(0,"",$sOutput)
    Sleep(500)

    If Not @error And $iExitCode = 0 Then ; if exitcode  = 0 i have reach end of the  of process for Pinpad or POS Installer or setmodulesbat script
        _Process_WaitUntil($sOutput) ; i can close the process after completion, even if there is a pause

    EndIf



EndFunc   ;==>personalize

here is my change, can you comment thanks

Edited by antonioj84
Link to comment
Share on other sites

  • 3 weeks later...

thanks for your continuous support. I am running the script debug work fine, however I am not able to have the  dos window close upon completion. bottom line if exit code is 0 to close window and if it 1 the window stay open

MsgBox($MB_ICONINFORMATION, "Demo", 'Demo for _Process_RunCommand in RUN mode and Demo for _Process_DebugRunCommand, This is the function line: _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "tracert google.com")' & @CRLF & @CRLF & "This will be a fun ride :D")
$hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "tracert google.com") ; Capture the Process Handle
$iPID = @extended ; Note the PID
_Process_DebugRunCommand($hProcessHandle, $iPID) ; Display the results in real-time

 

pinpadCapture.JPG

Edited by antonioj84
ok
Link to comment
Share on other sites

function moded will run debug mode the dos window command will close if the exit code = 0 , if the exit code = 1 window will stay open. hope it can help someone.  Feel free to make comment or suggestion.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.0
 Author:         TheDcoder

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

; Run this script to launch the interactive example :)

; Includes
#include <MsgBoxConstants.au3>
#include "ProcessEx.au3"

; MODIFIED 17th June 2017
; Replaced all original _Process_DebugRunCommand function calls with modified _Process_DebugRunCommandMod

MsgBox($MB_ICONINFORMATION, "Welcome", "Welcome to the demo of Process UDF :)" & @CRLF & @CRLF & "Lets start!")

MsgBox($MB_ICONINFORMATION, "Demo", 'Demo for _Process_RunCommand in RUNWAIT mode, This is the function line: _Process_RunCommand($PROCESS_RUNWAIT, $PROCESS_COMMAND & "ping 127.0.0.1")' & @CRLF & @CRLF & "(This will take some time)")
$sOutput = _Process_RunCommand($PROCESS_RUNWAIT, $PROCESS_COMMAND & "ping 127.0.0.1") ; Record the output
$iExitCode = @extended ; Note the exit code
MsgBox($MB_ICONINFORMATION, "Demo", "This is the result: " & @CRLF & @CRLF & $sOutput & @CRLF & @CRLF & "The exit code was: " & $iExitCode)

MsgBox($MB_ICONINFORMATION, "Demo", 'Demo for _Process_RunCommand in RUN mode and Demo for _Process_DebugRunCommand, This is the function line: _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "tracert google.com")' & @CRLF & @CRLF & "This will be a fun ride :D")
$hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "tracert google.com") ; Capture the Process Handle
$iPID = @extended ; Note the PID
$iMode1=_Process_DebugRunCommandMod($hProcessHandle, $iPID) ; Display the results in real-time
;*********************new code*****************************
$iExitCode = @extended ;
if not @error and $iExitCode =0 Then   _Process_WaitUntil($iMode1, $hProcessHandle)
;*********************new code*****************************


MsgBox($MB_ICONINFORMATION, "Demo", "This is the end of demo...")
If MsgBox($MB_ICONINFORMATION + $MB_YESNO, "Demo", "Would you like to run a custom command? Press 'No' to exit the demo.") = $IDNO Then Exit

While 1
    $sCommand = InputBox("Demo", "Please enter a command to run") ; Prompt the user...
    If Not @error Then ; If the user does NOT cancels...
        $hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & $sCommand) ; Capture the process handle
        $iPID = @extended ; Note the PID
        _Process_DebugRunCommandMod($hProcessHandle, $iPID) ; Display the results in real-time
    EndIf
    If MsgBox($MB_ICONINFORMATION + $MB_YESNO, "Demo", "Would you like to run another custom command?") = $IDNO Then Exit ; If the user wants to quit
WEnd

; MODIFIED: 17th June 2017
; This is the modified version of the original _Process_DebugRunCommand function
; It exits after 10 seconds if the $iExitCode is 0
; It also displays tray tips after the execution of commands
Func _Process_DebugRunCommandMod($hProcessHandle, $iPID)
    Local $aGrayCmdColor[3] = [197, 197, 197] ; Gray Color's combination in RGB
    Local $iGrayCmdColor = _ColorSetCOLORREF($aGrayCmdColor) ; Get the COLORREF code of Gray Color
    Local $hGUI = GUICreate("Command Prompt Simulator", 639, 299, -1, -1, $WS_OVERLAPPEDWINDOW) ; Create the GUI
    Global $g__Process_hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 0, 0, 639, 299, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL)) ; Create the RichEdit :)
    _GUICtrlRichEdit_SetBkColor($g__Process_hRichEdit, 0x000000) ; Set the background
    GUIRegisterMsg($WM_SIZE, "__Process_WM_SIZE") ; Register the resizing function
    GUISetState(@SW_SHOW, $hGUI) ; Reveal the GUI
    _GUICtrlRichEdit_AppendText($g__Process_hRichEdit, "The Process: " & _Process_GetPath($iPID) & @CRLF) ; Append the process information
    Local $sOutput = "", $sPartialOutput = "" ; Declare the output variable
    While ProcessExists($iPID) ; Loop until the process finishes
        $sPartialOutput = StdoutRead($iPID) ; Record the output
        $sOutput &= $sPartialOutput
        _GUICtrlRichEdit_AppendText($g__Process_hRichEdit, $sPartialOutput) ; Append the output
        _GUICtrlRichEdit_SetSel($g__Process_hRichEdit, 0, -1, True) ; Select all the text
        _GUICtrlRichEdit_SetFont($g__Process_hRichEdit, Default, "Fixedsys") ; Set the font
        _GUICtrlRichEdit_SetCharColor($g__Process_hRichEdit, $iGrayCmdColor) ; Set the font color
        Sleep(250) ; Don't kill the CPU
    WEnd
    $sPartialOutput = StdoutRead($iPID) ; Record the output
    $sOutput &= $sPartialOutput
    _GUICtrlRichEdit_AppendText($g__Process_hRichEdit, $sPartialOutput) ; Append any remaining chunks of output
    Local $iExitCode = _Process_GetExitCode($hProcessHandle)
    ;************new code *****************
    If $iExitCode = 0 Then
        Sleep(10 * 1000)
        GUIDelete($hGUI)
        TrayTip("", "Completed successfully and dos window close and continue", 5, $TIP_ICONASTERISK)
        Return SetExtended($iExitCode, $sOutput)
    Else
        TrayTip("", "did not complete successfully and window say open", 5, $TIP_ICONASTERISK)
    EndIf
    ;***************new code ****************
    _GUICtrlRichEdit_AppendText($g__Process_hRichEdit, @CRLF & @CRLF & "Debug Complete! The Exit Code was: " & $iExitCode) ; Display the exit code
    ; Same steps as in the above loop
    _GUICtrlRichEdit_SetSel($g__Process_hRichEdit, 0, -1, True)
    _GUICtrlRichEdit_SetFont($g__Process_hRichEdit, Default, "Fixedsys")
    _GUICtrlRichEdit_SetCharColor($g__Process_hRichEdit, $iGrayCmdColor)
    Local $nMsg = 0
    While 1 ; Wait for user to close the window
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd
    GUIDelete($hGUI) ; Delete the GUI
    Return SetExtended($iExitCode, $sOutput) ; Return True
EndFunc

 

Edited by antonioj84
error
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

×
×
  • Create New...