Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enabledelayedexpansion
- rem Calculate the number of passed-in arguments.
- set run_gui_over_admin_ssh_argc=0
- for %%x in (%*) do Set /A run_gui_over_admin_ssh_argc+=1
- rem Print a help message if the user did not provide at least a session ID and a command, or run the PsExec otherwise.
- if %run_gui_over_admin_ssh_argc% lss 2 (
- @echo on
- echo Insufficient number of arguments provided to "run_gui_over_admin_ssh.cmd"^^!
- echo.
- echo usage: run_gui_over_admin_ssh.cmd session_num cmd [cmd_args]
- echo session_num: Active GUI session ID to run the GUI app into.
- echo cmd: The command name from the "Path" environment variable or the full path to the command to execute.
- echo cmd_args: List of command line arguments for the command to execute.
- exit /B 1
- @echo off
- ) else (
- rem Set the login user.
- if "%user%" == "" (
- for /F "tokens=* USEBACKQ" %%g in (`C:\Windows\System32\whoami.exe`) DO (
- set run_gui_over_admin_ssh_myuser=%%g
- )
- ) else (
- set run_gui_over_admin_ssh_myuser=%user%
- )
- if /I "!run_gui_over_admin_ssh_myuser!" == "%computername%\%username%" (
- set run_gui_over_admin_ssh_myuser=%username%
- )
- rem Set the login user's password for automatic login.
- if exist "%HOMEDRIVE%%HOMEPATH%\.run_gui_over_admin_ssh\mypass" (
- set /p run_gui_over_admin_ssh_mypass=<"%homedrive%%homepath%\.run_gui_over_admin_ssh\mypass"
- )
- rem Run the command with manual login if "%HOMEDRIVE%%HOMEPATH%\.run_gui_over_admin_ssh\mypass" does not exist,
- rem or use the password loaded in that file for automatic login otherwise.
- if "!run_gui_over_admin_ssh_mypass!" == "" (
- @echo on
- PsExec.exe \\127.0.0.1 -u "!run_gui_over_admin_ssh_myuser!" -accepteula -nobanner -h -d -i %*
- @echo off
- ) else (
- @echo on
- 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 %*
- @echo off
- )
- )
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement