-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReadme.html
11 lines (11 loc) · 5.46 KB
/
Readme.html
1
2
3
4
5
6
7
8
9
10
11
<p><strong>What does this do?</strong><br /><br /> RunAsUser/RunAsActiveUser is a utility I conceived to run programs or commands under a user account logged into a computer, without needing to know their password.</p>
<p><strong>*WARNING!*</strong></p>
<p>In order to use this program as a true command line program, you must manually LINK the compiled EXE, either using the VBScript or by doing it yourself!</p>
<p><strong>*WARNING!*</strong></p>
<p>What does that mean? Example: Assume I'm logged into a computer but have since locked my computer. You log into my computer with your account (which must have Administrator permissions), and open an elevated command prompt and type <br /><em>RunAsUser.exe "calc.exe" -u "bradley"</em> -- This assumes that my account name is "bradley". If the account is found logged into the machine, calc.exe will open up on the desktop for that user. If the account isn't running, nothing will happen. <br /><br /> If you would like to wait for a specific account, you can use the -w switch: <em>RunAsUser.exe "calc.exe" -w -u "bradley"</em> -- this will cause the program to run silently, checking every few seconds until the user "bradley" is found. If you omit <em>-u "bradley"</em> it will run in the background and wait for any active session to be started on the computer. Or, you could go further and run your desired program for every account that logs into the computer until it has been restarted (or the RunAsUser process is terminated): <em>-p</em> <br /> <br /> You can run much more than just a calculator. You can open webpages, or run other programs local to the machine, from a web URL, or from a network share. <br /> <br /> There are many other uses. You can couple this with a remote execution program like <a href="https://technet.microsoft.com/en-us/sysinternals/psexec.aspx">PsExec</a>.<br /><br />Here's an example command that I use at work:<br /><em>PsExec.exe \\bradley-desktop -u Administrator -p ******** -h -f -c RunAsUser.exe "\\bf-filesvr\Departments\IT\TestClient\SetupFile.exe" -c "C:\Test\" -w"</em><br /><br /> Essentially, this will connect to the computer "bradley-desktop" with the account and password, copy the "RunAsUser.exe" to the remote machine, run it, and pass it the arguments <em>"\\bf-filesvr\Departments\IT\TestClient\SetupFile.exe" -c "C:\Test\"</em>, which contains a network file path for "SetupFile.exe" and a directory of <em>"C:\Test\"</em>. <br /><br /> This means that RunAsUser will run on the remote machine, copy the <em>SetupFile.exe</em> from the network share to the directory <em>"C:\Test\"</em> (creating it if it does not exist) and then run it as the currently logged in user, or wait for a user to log in if there are none. <br /><br /> Other fancy things:<br />Actual command line application<br /> Copy the file to a directory before running (web/network share)<br /> Kill all process matching the destination file name if the file is in use<br /> Pass arguments to the command or program you are executing<br /> Terminate any running instances of RunAsUser.exe (should they be stuck waiting for a user to log in)<br /> Display message boxes with titles and buttons<br /> Run a program:<br /> when a specific user logs in<br /> when any user logs in<br /> for all users logged in<br /> <br /> <strong>A bit more technical</strong></p>
<p>When run, this program attempts to create an exclusive global mutex at each stage of the process. if it cannot do this it closes itself. (It means it is already running in that stage, which we don't want)<br />It checks if it was executed with a special switch that tells it to execute its command (or message box) as the final step, and then exits.<br />It checks whether it's running with Elevated rights or running as the System account.<br />If it is not running as the System account, it attempts to elevate itself to the System account using a scheduled task.<br />If this is successful, the new process running as the System account creates its own global mutex and beings to process the arguments that it was passed.<br />At this stage, it checks whether it will display a message box and if so, launches a new process in the target user's session with a special switch added and exits.<br />It checks if a file is to be copied or downloaded and where to put it.<br />It checks whether it needs to wait for a specific user, any user, all users, or run indefinitely.<br />It checks whether it will run as a command and if so, launches a new process in the target user's session with a special switch added and exits.</p>
<p><br /> <strong>Credit</strong></p>
<p>GetCommandArgs - © Nik Keso 2009<br /> MConsole.bas - © Karl E. Peterson<br /> Other bits from all over the internet.</p>
<p><strong>Extra VBScript</strong></p>
<p>VBScript file for quickly and easily linking RunAsUser.exe to the Console subsytem:<br />(Included below just in case it is removed during the upload.)<br />(Name it something like LinkConsole.vbs, make certain the path to LINK.EXE is correct, save the script, and drag the RunAsUser compiled EXE over top of the script you just saved.)</p>
<p>Option Explicit<br />Dim strLINK, strEXE, WSHShell<br />' Be sure to set up strLINK to match your VB6 installation.<br />strLINK = """C:\Program Files (x86)\Microsoft Visual Studio\VB98\LINK.EXE"""<br />strEXE = """" & WScript.Arguments(0) & """"<br />Set WSHShell = CreateObject("WScript.Shell")<br />WSHShell.Run strLINK & " /EDIT /SUBSYSTEM:CONSOLE " & strEXE<br />Set WSHShell = Nothing<br />WScript.Echo "Complete!"</p>