<p>I'm currently running Vista and I would like to manually complete the same operations as my Windows Service. Since the Windows Service is running under the Local System Account, I would like to emulate this same behavior. Basically, I would like to run CMD.EXE under the Local System Account.</p>

<p>I found information online which suggests lauching the CMD.exe using the DOS Task Scheduler AT command, but I received a Vista warning that "due to security enhancements, this task will run at the time excepted but not interactively."  Here's a sample command:</p>

<pre><code>AT 12:00 /interactive cmd.exe
</code></pre>

<p>Another solution suggested creating a secondary Windows Service via the Service Control (sc.exe) which merely launches CMD.exe.  </p>

<pre><code>C:\sc create RunCMDAsLSA binpath= "cmd" type=own type=interact
C:\sc start RunCMDAsLSA
</code></pre>

<p>In this case the service fails to start and results it the following error message:</p>

<pre><code>FAILED 1053: The service did not respond to the start or control request in a timely fashion.
</code></pre>

<p>The third suggestion was to launch CMD.exe via a Scheduled Task. Though you may run scheduled tasks under various accounts, I don't believe the Local System Account is one of them.</p>

<p>I've tried using the Runas as well, but think I'm running into the same restriction as found when running a scheduled task.</p>

<p>Thus far, each of my attempts have ended in failure. Any suggestions?</p>

[{'answer_id': 77615, 'author': 'Bryant', 'author_id': 10893, 'author_profile': 'https://Stackoverflow.com/users/10893', 'pm_score': 3, 'selected': False, 'text': '<p>Found an answer <a href="http://blogs.msdn.com/adioltean/articles/271063.aspx" rel="noreferrer">here</a> which seems to solve the problem by adding /k start to the binPath parameter. So that would give you:</p>\n\n<p><code>sc create testsvc binpath= "cmd /K start" type= own type= interact</code></p>\n\n<p>However, Ben said that didn\'t work for him and when I tried it on Windows Server 2008 it did create the cmd.exe process under local system, but it wasn\'t interactive (I couldn\'t see the window). </p>\n\n<p>I don\'t think there is an easy way to do what you ask, but I\'m wondering why you\'re doing it at all? Are you just trying to see what is happening when you run your service? Seems like you could just use logging to determine what is happening instead of having to run the exe as local system...</p>\n'}, {'answer_id': 77623, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>if you can write a batch file that does not need to be interactive, try running that batch file as a service, to do what needs to be done.</p>\n'}, {'answer_id': 78691, 'author': 'Ben Griswold', 'author_id': 4115, 'author_profile': 'https://Stackoverflow.com/users/4115', 'pm_score': 9, 'selected': True, 'text': '<p>Though I haven\'t personally tested, I have good reason to believe that the above stated AT COMMAND solution will work for XP, 2000 and Server 2003. Per my and Bryant\'s testing, we\'ve identified that the same approach does not work with Vista or Windows Server 2008 -- most probably due to added security and the /interactive switch being deprecated. </p>\n\n<p>However, I came across this <a href="http://verbalprocessor.com/2007/12/05/running-a-cmd-prompt-as-local-system" rel="noreferrer">article</a> which demonstrates the use of <a href="http://download.sysinternals.com/files/PSTools.zip" rel="noreferrer">PSTools</a> from <a href="http://sysinternals.com/" rel="noreferrer">SysInternals</a> (which was acquired by Microsoft in July, 2006.) I launched the command line via the following and suddenly I was running under the Local Admin Account like magic:</p>\n\n<pre><code>psexec -i -s cmd.exe\n</code></pre>\n\n<p>PSTools works well. It\'s a lightweight, well-documented set of tools which provides an appropriate solution to my problem.</p>\n\n<p>Many thanks to those who offered help.</p>\n'}, {'answer_id': 5063705, 'author': 'James5001', 'author_id': 626221, 'author_profile': 'https://Stackoverflow.com/users/626221', 'pm_score': 2, 'selected': False, 'text': '<p>an alternative to this is Process hacker if you go into run as... (Interactive doesnt work for people with the security enhancments but that wont matter) and when box opens put Service into\nthe box type and put SYSTEM into user box and put C:\\Users\\Windows\\system32\\cmd.exe leave the rest click ok and boch you have got a window with cmd on it and run as system now do the other steps for yourself because im suggesting you know them</p>\n'}, {'answer_id': 16974787, 'author': 'raven', 'author_id': 2461825, 'author_profile': 'https://Stackoverflow.com/users/2461825', 'pm_score': 6, 'selected': False, 'text': '<ol>\n<li><a href="https://technet.microsoft.com/en-us/sysinternals/bb896649" rel="noreferrer">Download psexec.exe from Sysinternals</a>.</li>\n<li>Place it in your C:\\ drive.</li>\n<li>Logon as a standard or admin user and use the following command: <code>cd \\</code>. This places you in the root directory of your drive, where psexec is located.</li>\n<li>Use the following command: <code>psexec -i -s cmd.exe</code> where -i is for interactive and -s is for system account.</li>\n<li>When the command completes, a cmd shell will be launched. Type <code>whoami</code>; it will say \'system"</li>\n<li>Open taskmanager. Kill explorer.exe.</li>\n<li>From an elevated command shell type <code>start explorer.exe</code>.</li>\n<li>When explorer is launched notice the name "system" in start menu bar. Now you can delete some files in system32 directory which as admin you can\'t delete or as admin you would have to try hard to change permissions to delete those files.</li>\n</ol>\n\n<p>Users who try to rename or deleate System files in any protected directory of windows should know that all windows files are protected by DACLS while renaming a file you have to change the owner and replace TrustedInstaller which owns the file and make any user like a user who belongs to administrator group as owner of file then try to rename it after changing the permission, it will work and while you are running windows explorer with kernel privilages you are somewhat limited in terms of Network access for security reasons and it is still a research topic for me to get access back</p>\n'}, {'answer_id': 30543362, 'author': 'raven', 'author_id': 2461825, 'author_profile': 'https://Stackoverflow.com/users/2461825', 'pm_score': 3, 'selected': False, 'text': '<h2>Using Secure Desktop to run <code>cmd.exe</code> as <code>system</code></h2>\n\n<p>We can get kernel access through <code>CMD</code> in Windows XP/Vista/7/8.1 easily by attaching a debugger: </p>\n\n<pre><code>REG ADD "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\osk.exe" /v Debugger /t REG_SZ /d "C:\\windows\\system32\\cmd.exe"\n</code></pre>\n\n<ol>\n<li><p>Run <code>CMD</code> as Administrator</p></li>\n<li><p>Then use this command in Elevated:</p>\n\n<pre><code> CMD REG ADD "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\osk.exe" /v Debugger /t REG_SZ /d "C:\\windows\\system32\\cmd.exe"\n</code></pre></li>\n<li><p>Then run <code>osk</code> (onscreenkeyboard). It still does not run with system Integrity level if you check through process explorer, but if you can use OSK in service session, it will run as <code>NT Authority\\SYSTEM</code></p></li>\n</ol>\n\n<p>so I had the idea you have to run it on Secure Desktop.</p>\n\n<p>Start any file as Administrator. When UAC prompts appear, just press <kbd>Win</kbd>+<kbd>U</kbd> and start <code>OSK</code> and it will start <code>CMD</code> instead. Then in the elevated prompt, type <code>whoami</code> and you will get <code>NT Authority\\System</code>. After that, you can start Explorer from the system command shell and use the System profile, but you are somewhat limited what you can do on the network through SYSTEM privileges for security reasons. I will add more explanation later as I discovered it a year ago.</p>\n\n<h2>A Brief Explanation of how this happens</h2>\n\n<p>Running <code>Cmd.exe</code> Under Local System Account Without Using <code>PsExec</code>. This method runs Debugger Trap technique that was discovered earlier, well this technique has its own benefits it can be used to trap some crafty/malicious worm or malware in the debugger and run some other exe instead to stop the spread or damage temporary. here this registry key traps onscreen keyboard in windows native debugger and runs cmd.exe instead but cmd will still run with Logged on users privileges, however if we run cmd in session0 we can get system shell. so we add here another idea we span the cmd on secure desktop remember secure desktop runs in session 0 under system account and we get system shell. So whenever you run anything as elevated, you have to answer the UAC prompt and UAC prompts on dark, non interactive desktop and once you see it you have to press <kbd>Win</kbd>+<kbd>U</kbd> and then select <code>OSK</code> you will get <code>CMD.exe</code> running under Local system privileges. There are even more ways to get local system access with <code>CMD</code></p>\n'}, {'answer_id': 50329723, 'author': 'Alexander Haakan', 'author_id': 9214134, 'author_profile': 'https://Stackoverflow.com/users/9214134', 'pm_score': 2, 'selected': False, 'text': '<p>There is another way. There is a program called PowerRun which allows for elevated cmd to be run. Even with TrustedInstaller rights. It allows for both console and GUI commands. </p>\n'}, {'answer_id': 50881442, 'author': 'anton_rh', 'author_id': 5447906, 'author_profile': 'https://Stackoverflow.com/users/5447906', 'pm_score': 1, 'selected': False, 'text': '<p>I use the <a href="https://github.com/jschicht/RunAsTI" rel="nofollow noreferrer"><em>RunAsTi</em></a> utility to run as <em>TrustedInstaller</em> (high privilege). The utility can be used even in recovery mode of Windows (the mode you enter by doing <code>Shift</code>+<code>Restart</code>), the <em>psexec</em> utility doesn\'t work there. But you need to add your <code>C:\\Windows</code> and <code>C:\\Windows\\System32</code> (not <code>X:\\Windows</code> and <code>X:\\Windows\\System32</code>) paths to the <code>PATH</code> environment variable, otherwise <em>RunAsTi</em> won\'t work in recovery mode, it will just print: <em>AdjustTokenPrivileges for SeImpersonateName: Not all privileges or groups referenced are assigned to the caller</em>.</p>\n'}, {'answer_id': 56399430, 'author': 'Paul Harris', 'author_id': 11584338, 'author_profile': 'https://Stackoverflow.com/users/11584338', 'pm_score': 1, 'selected': False, 'text': '<p>Using task scheduler, schedule a run of CMDKEY running under SYSTEM with the appropriate arguments of /add: /user: and /pass:</p>\n\n<p>No need to install anything.</p>\n'}, {'answer_id': 66005881, 'author': 'Alex Roberts', 'author_id': 5016790, 'author_profile': 'https://Stackoverflow.com/users/5016790', 'pm_score': 2, 'selected': False, 'text': "<p>(Comment)</p>\n<p>I can't comment yet, so posting here... I just tried the above OSK.EXE debug trick but regedit instantly closes when I save the filled &quot;C:\\windows\\system32\\cmd.exe&quot; into the already created Debugger key so Microsoft is actively working to block native ways to do this. It is really weird because other things do not trigger this.</p>\n<p>Using task scheduler does create a SYSTEM CMD but it is in the system environment and not displayed within a human user profile so this is also now defunct (though it is logical).</p>\n<p>Currently on Microsoft Windows [Version 10.0.20201.1000]</p>\n<p>So, at this point it has to be third party software that mediates this and further tricks are being more actively sealed by Microsoft these days.</p>\n"}, {'answer_id': 73283420, 'author': 'HandyManny', 'author_id': 7356180, 'author_profile': 'https://Stackoverflow.com/users/7356180', 'pm_score': 0, 'selected': False, 'text': '<p>i used Paul Harris recommendation and created a batch file .cmd or .bat with what ever command i needed to run under system and used the schedule task run one time.\nthan trigger it as needed. and updated the batch as needed. so any command i need to run under system i just update the batch.</p>\n'}]
['https://Stackoverflow.com/questions/77528', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4115/']