Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3.  
  4. rem Calculate the number of passed-in arguments.
  5. set run_gui_over_admin_ssh_argc=0
  6. for %%x in (%*) do Set /A run_gui_over_admin_ssh_argc+=1
  7.  
  8. rem Print a help message if the user did not provide at least a session ID and a command, or run the PsExec otherwise.
  9. if %run_gui_over_admin_ssh_argc% lss 2 (
  10. @echo on
  11. echo Insufficient number of arguments provided to "run_gui_over_admin_ssh.cmd"^^!
  12. echo.
  13. echo usage: run_gui_over_admin_ssh.cmd session_num cmd [cmd_args]
  14. echo session_num: Active GUI session ID to run the GUI app into.
  15. echo cmd: The command name from the "Path" environment variable or the full path to the command to execute.
  16. echo cmd_args: List of command line arguments for the command to execute.
  17. exit /B 1
  18. @echo off
  19. ) else (
  20. rem Set the login user.
  21. if "%user%" == "" (
  22. for /F "tokens=* USEBACKQ" %%g in (`C:\Windows\System32\whoami.exe`) DO (
  23. set run_gui_over_admin_ssh_myuser=%%g
  24. )
  25. ) else (
  26. set run_gui_over_admin_ssh_myuser=%user%
  27. )
  28. if /I "!run_gui_over_admin_ssh_myuser!" == "%computername%\%username%" (
  29. set run_gui_over_admin_ssh_myuser=%username%
  30. )
  31.  
  32. rem Set the login user's password for automatic login.
  33. if exist "%HOMEDRIVE%%HOMEPATH%\.run_gui_over_admin_ssh\mypass" (
  34. set /p run_gui_over_admin_ssh_mypass=<"%homedrive%%homepath%\.run_gui_over_admin_ssh\mypass"
  35. )
  36.  
  37. rem Run the command with manual login if "%HOMEDRIVE%%HOMEPATH%\.run_gui_over_admin_ssh\mypass" does not exist,
  38. rem or use the password loaded in that file for automatic login otherwise.
  39. if "!run_gui_over_admin_ssh_mypass!" == "" (
  40. @echo on
  41. PsExec.exe \\127.0.0.1 -u "!run_gui_over_admin_ssh_myuser!" -accepteula -nobanner -h -d -i %*
  42. @echo off
  43. ) else (
  44. @echo on
  45. PsExec.exe \\127.0.0.1 -u "!run_gui_over_admin_ssh_myuser!" -p "!run_gui_over_admin_ssh_mypass!" -accepteula -nobanner -h -d -i %*
  46. @echo off
  47. )
  48. )
  49. endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement