Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Run "cmd.exe" as a given user and "as administrator" in command line

15 Oct 2013   #11
UsernameIssues

W7 Pro SP1 64bit
 
 

Quote   Quote: Originally Posted by Lea Massiot View Post
...I have to say that despite I'm not an English speaking native I think I described my problem quite clearly in my two previous posts in this very same thread....
Your English is great. You did describe a task that I assume is a simplified version of the real task. And you are correct, there does not seem to be a native way to impersonate another user (runas) to launch an app at the high integrity level. AutoIt scripts can request an elevation to the high integrity level... but I'm not sure that this would work while impersonating another user.

Quote   Quote: Originally Posted by Lea Massiot View Post
...Now, I'm really confused about:
1) the "administrator account" you're talking about ;
2) the "Administrators" group ;
3) the "Run as administrator" functionality.

Best regards.
1) The administrator account that I mentioned is described here:
Built-in Administrator Account - Enable or Disable

2 & 3) If a user is a member of the "Administrators" group...
...they can do somethings without being asked for credentials.

User1 is in the "Administrators" group.
User1 starts notepad.
Notepad runs at the medium integrity level.
(assumes default UAC settings)

User100 is not in the "Administrators" group.
User100 starts notepad.
Notepad runs at the medium integrity level.
(assumes default UAC settings)

User1 starts notepad using "Run as administrator".
User1 answers yes to the UAC prompt.
Notepad runs at the high integrity level.

User100 starts notepad using "Run as administrator".
User100 is prompted for the credentials of one of the user in the "Administrators" group.
If those credentials are correctly entered, notepad runs at the high integrity level.

User1 and user100 can do most of the same things.


My System SpecsSystem Spec
.
16 Oct 2013   #12
Lea Massiot

Windows 7 Professional SP1 64bit
 
 

Thank you for all this useful and clear information.
Best regards.
My System SpecsSystem Spec
13 Jan 2015   #13
jonnyhotchkiss

Windows 7 Ultimate 64bit
 
 

Thank you for being so polite, and for returning to reciprocate your gratitude - excellent example of how 'manners cost nothing'...

I wondered if you ever achieved your objective - 'run cmd as different user' with admin rights?
My System SpecsSystem Spec
.

13 Jan 2015   #14
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Sorry, but I'm absolutely certain that it's impossible (through the command prompt) to start a command prompt as another user and with elevated privileges, because there is no such command line command that allows one to start a new process as elevated using credentials other than the builtin Administrator at least, and the Runas command does not accept multiple user credentials.

The question posed by the OP cannot be achieved via the Command Prompt. What else can we try then? Let's take a look at Windows Powershell instead...

Powershell is the future scripting language and command line interface for Windows. It is much more robust than the Command Prompt which uses different parsing tools to process each unique command and Powershell is more flexable with a larger set of built-in commands and only one command parser for all of them. Anyone from Windows XP and later may use it.

The following powershell command, in theory, should start a command prompt instance running as the user "User01", while at the same time run as an elevated process:
Code:
Start-Process cmd -Credential User01 -Verb RunAs
... but in practise, this raises an exception.

It seems that the switches '-Credential' (specify a user to run as) and '-Verb' ((potentially) specify that the executable should run elevated) cannot be used together; it's as if Microsoft never wanted users to be able to start processes as other users and run the process as administrator at the same time, anyhow.

But with a dab of tricky involved, there is a well known powershell command going around that does exactly what you need, Jonnyhotchkiss and Lea Massiot, here it is (this is a slimed down version of the same command you might find elsewhere on the internet):
Code:
Start-Process powershell 'Start-Process cmd -Verb RunAs' -Credential User01
(Replacing "User01" with the user to run as (and "cmd" with the program of your choice) as needed)

It works by calling a new instance of Powershell as a specified user (User01 in this case), then it executes another Start-Process command (aka Cmdlet) inside the new Powershell instance which invokes cmd.exe with 'Run as Administrator' privileges. So it's as if that other user had typed out that second command (Start-Process cmd -Verb RunAs) into a Powershell prompt.

The above powershell command is one of the very few ways in Windows to start a new process as another user, while at the same time running it with administrative (elevated) permissions. All done in one go.


I'm sorry that the solution could not involve simple commands typed at the command prompt. If it was possible I would share, but Powershell is the only way to go here.
My System SpecsSystem Spec
Reply

 Run "cmd.exe" as a given user and "as administrator" in command line




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Need to add "TASKBARS" (MSese for "Launchpads", "Docks" NOT "Toolbars"
My office just upgraded, and I can no longer use Windows XP. On this system, I was able to add a separate taskbar to facilitate quick access to commonly-browsed folder locations on our vast network, and another one expedited the launching of useful programs and lists. Each task on each taskbar...
General Discussion
AMD ATI Radeon "Varibright": how to command-line turn off?
have the latest AMD driver installed on my thinkpad but I loathe loading .NET 4 just to run CCC for one reason only: to disable varibright. Anyone know what the registry key is for this? or some way to command-line turn off?
Drivers
How to "Duplicate These Displays" via command line or registry?
Is there a simple, silent, non-interactive way to switch from "Extend These Displays" to "Duplicate These Displays"?
Customization
"Mail to" shortcut in Send To context menu fails command line argument
Hi All, Previous PC was an XP and we had a shortcut within the Send To context menu called "Mail To" which when clicked on a file would open a new email with the file attached and with the default email (as done from within Outlook), not the crappy text "mail recipient" one that is standard in...
Browsers & Mail
"Create Dump File" command line
Is there a command line for the task manager right click on the process and executing a "Create Dump File"? I'm aware we can use ADPlus, wondering how Windows 7 does it without debug diag or windows debug tools I ran some initial trend on my end as well. I tried capturing procmon while issuing...
BSOD Help and Support
"there was a problem sending a command line to program"
when i try to open my yahoo messenger account or a html doc. i get this pop up message: "there was a problem sending a command line to program". any suggestions? thanks
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 09:42.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App