Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem -- ver.02 --
- setlocal
- if [%1] EQU [] (
- echo %~n0 -exec path_to_exec [-user user [-pass pass]] [-command commandline] [-system] remote_system
- echo starts a process as a certain user
- echo to start a hidden process set user to SYSTEM
- echo by Vasil "npocmaka" Arnaudov
- goto :eof
- )
- if [%1] EQU [-help] (
- echo %~n0 -exec path_to_exec [-user user [-pass pass]] [-command commandline] [-system] remote_system
- echo starts a process as a certain user
- echo to start a hidden process set user to SYSTEM
- echo by Vasil "npocmaka" Arnaudov
- goto :eof
- )
- set /A shifter=1
- ::set spaces to params that is possible to stay unused
- set set user_param=
- set pass_param=
- set exec=
- set command=
- ::they're same for SCHTASKS and EVENTCREATE
- set remote_params=
- :argParser
- if [%1] EQU [-exec] (
- set executable=%~s2
- set inpath=%~dp$PATH:2
- )
- if [%1] EQU [-user] (
- set user=%2
- )
- if [%1] EQU [-pass] (
- set pass=%2
- )
- if [%1] EQU [-command] (
- set command='%~2'
- )
- if [%1] EQU [-system] (
- set system=%2
- )
- shift
- shift
- set /A shifter=%shifter% + 1
- if %shifter% EQU 5 (
- goto :endArgParser
- )
- goto :argParser
- :endArgParser
- :: parameters with user and no pass is ommited to avoid pass prompting
- if "%user%" NEQ "" (
- set user_param=/RU %user%
- if "%pass%" NEQ "" (
- set pass_param=/RP %pass%
- if "%system%" NEQ "" (
- set remote_params= /S %system% /U %user% /P %pass%
- set pass_param=
- set user_param=
- goto :skipExCheck
- )
- ) else (
- set user_param=
- )
- ) else (
- if "%system%" NEQ "" (
- set remote_params= /S %system%
- goto :skipExCheck
- )
- )
- ::there cannot be set password on system user
- if "%user%" EQU "SYSTEM" (
- set pass_param=
- )
- if "%system%" NEQ "" (
- set remote_params= /S %system% /U %user% /P %pass%
- goto :skipExCheck
- )
- ::the idea behind this ugly if is
- :: to get the path in 8.3 format because there are problems between
- :: SCHTASKS and spaces
- if not exist %executable% (
- if "%inpath%" equ "" (
- echo path to executable item does not exist
- exit /B 1
- ) else (
- for %%f in ("%inpath%\%executable%") do set executable=%%~snf
- )
- ) else (
- for %%f in ("%executable%") do set executable=%%~snf
- )
- :: if task is executed against remote machine existence checking is unnecessary
- :skipExCheck
- ::getting the current time
- FOR /F "skip=1 tokens=1-3" %%A IN ('WMIC Path Win32_LocalTime Get Hour^,Minute^,Second /Format:table') DO (
- SET /A hours=%%A > nul 2>&1
- SET /A minutes=%%B > nul 2>&1
- SET /A seconds=%%C > nul 2>&1
- )
- set /a time_stamp=%hours%%minutes%%seconds%
- if "%time_stamp%" equ "" (
- echo "some kind of error"
- exit /B 2
- )
- ::the heart of the script
- SCHTASKS /Create /SC ONEVENT /EC Application /MO *[System/EventID=101] /TN start_at_%time_stamp% /TR "'%executable%' %command%" %user_param% %pass_param% /F /RL HIGHEST %remote_params%
- EVENTCREATE /ID 101 /T INFORMATION /D start_task %remote_params%
- SCHTASKS /Delete /TN start_at_%time_stamp% /f %remote_params%
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement