Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 KB | None | 0 0
  1. c:Program Files (x86)PSTools>psexec -u administrator -p force \135.20.230.160 -s -d cmd.exe /c -c "C:Amtrabogus.bat"
  2.  
  3. PsExec v2.11 - Execute processes remotely
  4. Copyright (C) 2001-2014 Mark Russinovich
  5. Sysinternals - www.sysinternals.com
  6.  
  7.  
  8. cmd.exe started on 135.24.237.167 with process ID 1520.
  9.  
  10. psexec -u administrator -p force \135.20.230.160 -s -d cmd.exe /c "C:Amitrabogus.bat"
  11.  
  12. @echo off
  13. :: by Ralph Buchfelder, thanks to Mark Russinovich and Rob van der Woude for their work!
  14. :: requires PsExec.exe to be in the same directory (download from http://technet.microsoft.com/de-de/sysinternals/bb897553.aspx)
  15. :: troubleshoot remote commands with PsExec arguments -i or -s if neccessary (see http://forum.sysinternals.com/pstools_forum8.html)
  16. :: will run *in parallel* on a list of remote pcs (if given); to run serially please remove 'START "" CMD.EXE /C' from the psexec call
  17.  
  18.  
  19. :: help
  20. if '%1' =='-h' (
  21. echo.
  22. echo %~n0
  23. echo.
  24. echo Runs a command on one or many remote machines. If no input parameters
  25. echo are given you will be asked for a target remote machine.
  26. echo.
  27. echo You will be prompted for remote credentials with elevated privileges.
  28. echo.
  29. echo UNC paths and local paths can be supplied.
  30. echo Commands will be executed on the remote side just the way you typed
  31. echo them, so be sure to mind extensions and the path variable!
  32. echo.
  33. echo Please note that PsExec.exe must be allowed on remote machines, i.e.
  34. echo not blocked by firewall or antivirus solutions.
  35. echo.
  36. echo Syntax: %~n0 [^<inputfile^>]
  37. echo.
  38. echo inputfile = a plain text file ^(one hostname or ip address per line^)
  39. echo.
  40. echo.
  41. echo Example:
  42. echo %~n0 mylist.txt
  43. exit /b 0
  44. )
  45.  
  46.  
  47. :checkAdmin
  48. >nul 2>&1 "%SYSTEMROOT%system32cacls.exe" "%SYSTEMROOT%system32configsystem"
  49. if '%errorlevel%' neq '0' (
  50. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%getadmin.vbs"
  51. echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%getadmin.vbs"
  52. "%temp%getadmin.vbs"
  53. del "%temp%getadmin.vbs"
  54. exit /B
  55. )
  56. set ADMINTESTDIR=%WINDIR%System32Test_%RANDOM%
  57. mkdir "%ADMINTESTDIR%" 2>NUL
  58. if errorlevel 1 (
  59. cls
  60. echo ERROR: This script requires elevated privileges!
  61. echo.
  62. echo Launch by Right-Click / Run as Administrator ...
  63. pause
  64. exit /b 1
  65. ) else (
  66. rd /s /q "%ADMINTESTDIR%"
  67. echo Running with elevated privileges...
  68. )
  69. echo.
  70.  
  71.  
  72. :checkRequirements
  73. if not exist "%~dp0PsExec.exe" (
  74. echo PsExec.exe from Sysinternals/Microsoft not found
  75. echo in %~dp0
  76. echo.
  77. echo Download from http://technet.microsoft.com/de-de/sysinternals/bb897553.aspx
  78. echo.
  79. pause
  80. exit /B
  81. )
  82.  
  83.  
  84. :environment
  85. setlocal
  86. echo.
  87. echo %~n0
  88. echo _____________________________
  89. echo.
  90. echo Working directory: %cd%
  91. echo Script directory: %~dp0
  92. echo.
  93. SET /P REMOTE_USER=DomainAdministrator :
  94. SET "psCommand=powershell -Command "$pword = read-host 'Kennwort' -AsSecureString ; ^
  95. $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
  96. [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
  97. for /f "usebackq delims=" %%p in (`%psCommand%`) do set REMOTE_PASS=%%p
  98. if NOT DEFINED REMOTE_PASS SET /P REMOTE_PASS=Password :
  99. echo.
  100. if '%1' =='' goto menu
  101. SET REMOTE_LIST=%1
  102.  
  103.  
  104. :inputMultipleTargets
  105. if not exist %REMOTE_LIST% (
  106. echo File %REMOTE_LIST% not found
  107. goto menu
  108. )
  109. type %REMOTE_LIST% >nul
  110. if '%errorlevel%' neq '0' (
  111. echo Access denied %REMOTE_LIST%
  112. goto menu
  113. )
  114. set batchProcessing=true
  115. echo Batch processing: %REMOTE_LIST% ...
  116. ping -n 2 127.0.0.1 >nul
  117. goto runOnce
  118.  
  119.  
  120. :menu
  121. if exist "%~dp0last.computer" set /p LAST_COMPUTER=<"%~dp0last.computer"
  122. if exist "%~dp0last.listing" set /p LAST_LISTING=<"%~dp0last.listing"
  123. if exist "%~dp0last.directory" set /p LAST_DIRECTORY=<"%~dp0last.directory"
  124. if exist "%~dp0last.command" set /p LAST_COMMAND=<"%~dp0last.command"
  125. if exist "%~dp0last.timestamp" set /p LAST_TIMESTAMP=<"%~dp0last.timestamp"
  126. echo.
  127. echo.
  128. echo (1) select target computer [default]
  129. echo (2) select multiple computers
  130. echo -----------------------------------
  131. echo last target : %LAST_COMPUTER%
  132. echo last listing: %LAST_LISTING%
  133. echo last path : %LAST_DIRECTORY%
  134. echo last command: %LAST_COMMAND%
  135. echo last run : %LAST_TIMESTAMP%
  136. echo -----------------------------------
  137. echo (0) exit
  138. echo.
  139. echo ENTER your choice.
  140. echo.
  141. echo.
  142. :mychoice
  143. SET /P mychoice=(0, 1, ...):
  144. if NOT DEFINED mychoice goto promptSingleTarget
  145. if "%mychoice%"=="1" goto promptSingleTarget
  146. if "%mychoice%"=="2" goto promptMultipleTargets
  147. if "%mychoice%"=="0" goto end
  148. goto mychoice
  149.  
  150.  
  151. :promptMultipleTargets
  152. echo.
  153. echo Please provide an input file
  154. echo [one IP address or hostname per line]
  155. SET /P REMOTE_LIST=Filename :
  156. goto inputMultipleTargets
  157.  
  158.  
  159. :promptSingleTarget
  160. SET batchProcessing=
  161. echo.
  162. echo Please provide a hostname
  163. SET /P REMOTE_COMPUTER=Target computer :
  164. goto runOnce
  165.  
  166.  
  167. :runOnce
  168. cls
  169. echo Note: Paths are mandatory for CMD-commands (e.g. dir,copy) to work!
  170. echo Paths are provided on the remote machine via PUSHD.
  171. echo.
  172. SET /P REMOTE_PATH=UNC-Path or folder :
  173. SET /P REMOTE_CMD=Command with params:
  174. SET REMOTE_TIMESTAMP=%DATE% %TIME:~0,8%
  175. echo.
  176. echo Remote command starting (%REMOTE_PATH%%REMOTE_CMD%) on %REMOTE_TIMESTAMP%...
  177. if not defined batchProcessing goto runOnceSingle
  178.  
  179.  
  180. :runOnceMulti
  181. REM do for each line; this circumvents PsExec's @file to have stdouts separately
  182. SET REMOTE_LOG=%~dp0log%REMOTE_LIST%
  183. if not exist %REMOTE_LOG% md %REMOTE_LOG%
  184. for /F "tokens=*" %%A in (%REMOTE_LIST%) do (
  185. if "%REMOTE_PATH%" =="" START "" CMD.EXE /C ^(%~dp0PSEXEC -u %REMOTE_USER% -p %REMOTE_PASS% -h -accepteula \%%A cmd /c "%REMOTE_CMD%" ^>"%REMOTE_LOG%%%A.log" 2^>"%REMOTE_LOG%%%A_debug.log" ^)
  186. if not "%REMOTE_PATH%" =="" START "" CMD.EXE /C ^(%~dp0PSEXEC -u %REMOTE_USER% -p %REMOTE_PASS% -h -accepteula \%%A cmd /c "pushd %REMOTE_PATH% && %REMOTE_CMD% & popd" ^>"%REMOTE_LOG%%%A.log" 2^>"%REMOTE_LOG%%%A_debug.log" ^)
  187. )
  188. goto restart
  189.  
  190.  
  191. :runOnceSingle
  192. SET REMOTE_LOG=%~dp0log
  193. if not exist %REMOTE_LOG% md %REMOTE_LOG%
  194. if "%REMOTE_PATH%" =="" %~dp0PSEXEC -u %REMOTE_USER% -p %REMOTE_PASS% -h -accepteula \%REMOTE_COMPUTER% cmd /c "%REMOTE_CMD%" >"%REMOTE_LOG%%REMOTE_COMPUTER%.log" 2>"%REMOTE_LOG%%REMOTE_COMPUTER%_debug.log"
  195. if not "%REMOTE_PATH%" =="" %~dp0PSEXEC -u %REMOTE_USER% -p %REMOTE_PASS% -h -accepteula \%REMOTE_COMPUTER% cmd /c "pushd %REMOTE_PATH% && %REMOTE_CMD% & popd" >"%REMOTE_LOG%%REMOTE_COMPUTER%.log" 2>"%REMOTE_LOG%%REMOTE_COMPUTER%_debug.log"
  196. goto restart
  197.  
  198.  
  199. :restart
  200. echo.
  201. echo.
  202. echo Batch completed. Finished with last errorlevel %errorlevel% .
  203. echo All outputs have been saved to %~dp0log%REMOTE_TIMESTAMP%.
  204. echo %REMOTE_PATH% >"%~dp0last.directory"
  205. echo %REMOTE_CMD% >"%~dp0last.command"
  206. echo %REMOTE_LIST% >"%~dp0last.listing"
  207. echo %REMOTE_COMPUTER% >"%~dp0last.computer"
  208. echo %REMOTE_TIMESTAMP% >"%~dp0last.timestamp"
  209. SET REMOTE_PATH=
  210. SET REMOTE_CMD=
  211. SET REMOTE_LIST=
  212. SET REMOTE_COMPUTER=
  213. SET REMOTE_LOG=
  214. SET REMOTE_TIMESTAMP=
  215. ping -n 2 127.0.0.1 >nul
  216. goto menu
  217.  
  218.  
  219. :end
  220. SET REMOTE_USER=
  221. SET REMOTE_PASS=
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement