Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enabledelayedexpansion
- if {%~1} NEQ {} (
- if {%~1} NEQ {-help} (
- call :proc %*
- exit /b %ERRORLEVEL%
- )
- )
- call :echoHelp
- exit /b
- :proc
- call :argParser %*
- if {%exec%} EQU {} (
- call :err 1000
- exit /b %ERRORLEVEL%
- )
- if {%host%} NEQ {} (
- set host=/NODE:%host%
- if {%user%} NEQ {} (
- set user=/USER:%user%
- if {%pass%} NEQ {} (
- set pass=/PASSWORD:%pass%
- )
- )
- )
- if {%record%} NEQ {} (
- set record=/RECORD:%record%
- )
- set global_params=%record% %host% %user% %pass%
- for /f "usebackq tokens=*" %%G IN (`wmic %global_params% process call create "%exec% %commandline%"^,"%workdir%"`) do (
- rem echo %%G
- echo %%G | find "ProcessId" > nul && (
- for /f "tokens=2 delims=;= " %%H in ('echo %%G') do (
- call set /A PID=%%H
- )
- )
- echo %%G | find "ReturnValue" > nul && (
- for /f "tokens=2 delims=;= " %%I in ('echo %%G') do (
- call set /A RETCOD=%%I
- )
- )
- call :concat "%%G"
- )
- rem successful execution
- if %PID% NEQ 0 (
- echo %PID%
- exit /b
- rem exit /B %PID%
- ) else (
- call :err %RETCOD%
- )
- exit /b %ERRORLEVEL%
- :argParser
- set comstr=-exec-commandline-workdir-host-user-pass-record
- for /L %%i in (1,1,7) do (
- echo %comstr% | find "%~1" > nul && (
- set _tmp=%~1
- set !_tmp:-=!=%~2
- )
- shift
- shift
- )
- set _tmp=
- exit /b
- :echoHelp
- echo creates a process and returns it's PID
- echo %~n0 -exec executubale {-commandline command_line} { -workdir working_directory}
- echo {-host remote_host {-user user {-pass password}}} {-record path_to_xml_output}
- echo\
- echo localhost cant' be used as in -host variable
- echo Examples:
- echo %~n0 -exec "notepad" -workdir "c:/" -record "test.xml" -commandline "/A startpid.txt"
- echo %~n0 -exec "cmd" -workdir "c:/" -record "test.xml" -host remoteHost -user User
- echo by Vasil "npocmaka" Arnaudov
- exit /b
- :concat
- call set output=%output% ^& echo %~1
- exit /b
- :err
- if %1 EQU 2 (set errmsg=Access Denied)
- if %1 EQU 3 (set errmsg=Insufficient Privilege)
- if %1 EQU 8 (set errmsg=Unknown failure ^& echo Hint: Check if the executable and workdit exists or if command line parameters are correct.)
- if %1 EQU 9 (set errmsg=Path Not Found ^& echo Hint: check if the work exists on the remote machine.)
- if %1 EQU 21 (set errmsg=Invalid Parameter ^& echo Hint: Check executable path.Check if host and user are corect.)
- if %1 EQU 1000 (set errmsg=Executable not defined.)
- if {%errmsg%} EQU {} (set errmsg=%output% ^& echo Hint: brackets,quotes or commas in the password may could breack the script.)
- echo %errmsg%
- exit /b %1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement