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

20 Jun 2012   #1

Windows 7 Professional SP1 64bit
 
 
Run "cmd.exe" as a given user and "as administrator" in command line

Hello and thank you for reading my post.

If I'm logged in Windows as user "u1", I can execute "cmd.exe" "as administrator" by choosing
Code:
 "Start" -> "cmd.exe" and right-click "Run as administrator".
I would like to start another "cmd.exe" console as "u2" and "as administrator".
(So, "u2" is not the current logged in user).

The following command:
Code:
u1 cmd.exe> runas /user:u2 "cmd.exe"
runs "cmd.exe" as "u2" but not "as administrator".

I would like to do this in command line. Can you tell me how?

Best regards.

Nota:
u1 cmd.exe> means: I'm running "cmd.exe" as "u1".


My System SpecsSystem Spec
.

22 Jun 2012   #2

Windows 7 (XP, by Virtualization)
 
 

Hi Lea,

I don't believe that what you want to accomplish is possible. This is because Windows only "runs" one login at a time, unlike some true multi user operating systems, such as Linux.

If your logged in as U1, then you can only perform operations as U1, or as the Administrator. As far as running things as the Administrator is concerned, I believe in this case that you simply inherit the Administrators permission levels, thus permitting you to perform elevated activities.

If your U1 login has Administrator privileges then running as Administrator will be no different to running as U1!

Good luck

Davo
My System SpecsSystem Spec
22 Jun 2012   #3

Windows 8.1 Pro (x64)
 
 

Quote   Quote: Originally Posted by Mr Davo View Post
I don't believe that what you want to accomplish is possible. This is because Windows only "runs" one login at a time, unlike some true multi user operating systems, such as Linux.
That is incorrect. Windows is a multi-user OS. Has been since Windows NT first rolled off the printing presses.

Code:
> runas [/profile | /noprofile] /user:[domainname\]username "C:\Windows\System32\cmd.exe"
If you do not need the user profile data (Regirstry, etc.) you can use the /noprofile switch. It is faster that way.

Using the above command I ran Internet Explorer with a TestUser account I created that is just a Standard User. You can see in the image below iexplorer.exe is running under a different user with different privileges.


Attached Thumbnails
Run "cmd.exe" as a given user and "as administrator" in command line-untitled.png  
My System SpecsSystem Spec
.


22 Jun 2012   #4

Windows 7 Ultimate x64
 
 

This isn't exactly what you want, but it may help: if you do a Shift + Right-click on an item in the start menu, it will give more options. One of these options is 'Run as different user' which does what it says. I think you need the other user's credentials, however.
My System SpecsSystem Spec
22 Jun 2012   #5

Windows 7 Professional SP1 64bit
 
 

Thank you for your answers and for the screen capture.

Regardless of my weak understanding of what exactly is that "Run as administrator" functionality,
and given the fact that this functionality can be triggered by right-clicking on an item and then choose "Run as administrator",
I would like to know how this functionality can be triggered in command line.

As any ".exe" file can be "run as administrator" as described above,
I wonder how this can be done in command line.
For example:
- I'm logged in the OS as "u1" who is a member of the "Administrators" group (*).
- "u2" is a member of the "Administrators" group too.
- I start a command line "cmd.exe".
- I want to run (for example):
-- "mkdir",
-- "gvim",
-- "runas /user:u2 'cmd.exe'"
-- etc.
"as administrator".
In the "runas" case, I want to do just as if I was logged into the OS as "u2" and would run "cmd.exe" "as administrator".

I am also wondering why it's not enough to be part of the "Administrators" group and why do we need this extra "Run as administrator" functionality? Is it something like an extra security feature to protect resources like a "confirm you really want to do this action" in which case, maybe there is a way to bypass that behaviour...?

Thanks for your help. Best regards.


(*) Win. doc.: "Administrators have complete and unrestricted access to the computer/domain".
My System SpecsSystem Spec
22 Jun 2012   #6

W7 Pro SP1 64bit
 
 

It would probably be best if you detail exactly what you are attempting to do - what is the end result of all of this. Then we might be able to help you get there. There probably is a way to do what you outlined above, but there probably is an easier way to achieve your end goal.
My System SpecsSystem Spec
22 Jun 2012   #7

Windows 7 Ultimate x64
 
 

I dont think its possible from the command line as because the cmd.exe is already running as a normal user so how can it then run again as root user.

Its windows man not linux. Its very easy in linux but I dont think its possible in windows. May be there is a way who knows.
My System SpecsSystem Spec
09 Oct 2013   #8

Windows 7 Ultimate 64bit
 
 
How to use admin account

Quote   Quote: Originally Posted by Lea Massiot View Post
Thank you for your answers and for the screen capture.

Regardless of my weak understanding of what exactly is that "Run as administrator" functionality,
and given the fact that this functionality can be triggered by right-clicking on an item and then choose "Run as administrator",
I would like to know how this functionality can be triggered in command line.

As any ".exe" file can be "run as administrator" as described above,
I wonder how this can be done in command line.
For example:
- I'm logged in the OS as "u1" who is a member of the "Administrators" group (*).
- "u2" is a member of the "Administrators" group too.
- I start a command line "cmd.exe".
- I want to run (for example):
-- "mkdir",
-- "gvim",
-- "runas /user:u2 'cmd.exe'"
-- etc.
"as administrator".
In the "runas" case, I want to do just as if I was logged into the OS as "u2" and would run "cmd.exe" "as administrator".

I am also wondering why it's not enough to be part of the "Administrators" group and why do we need this extra "Run as administrator" functionality? Is it something like an extra security feature to protect resources like a "confirm you really want to do this action" in which case, maybe there is a way to bypass that behaviour...?

Thanks for your help. Best regards.


(*) Win. doc.: "Administrators have complete and unrestricted access to the computer/domain".
Hi,


I ran cmd as admin and ran


net user


this shows your user accounts. Do you have an administrator account listed?


You may need to activate it (net user administrator /active:yes)
and set a password (net user administrator *)
you can hide accounts by adding the username as DWORD (value=0) to


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList


Finally, to save a credential
runas.exe /savecred /user:administrator "defrag c:"


Hope this helps.




for shortcuts, I highly recommend SlickRun (magic words, too many keyboard shortcuts!) hotkey master, and the extremely flexible AutoHotkey.


Thanks
My System SpecsSystem Spec
09 Oct 2013   #9

W7 Pro SP1 64bit
 
 

Greetings jonnyhotchkiss,

Maybe the OP will stop back by to read this old discussion...
...or maybe not.

I think that the OP wanted to use one batch file to do several things:
The batch file was launched with the medium integrity level of user1...
It needed to do some things that required the high integrity level (run as admin)...
Then the OP wanted the batch file to do somethings as if user2 was logged on...
And finally, to do some things as user2's high integrity level (run as admin).

The high integrity level (run as admin) is not related to the built in administrator account. That administrator account should remain disabled. The high integrity level is just elevated privileges for an app, service or operation.

There are probably better ways to do what the OP wanted done; but sadly, I don't think that we were given enough details to help.

BTW, I concur with the usefulness of AutoHotKey. I used AutoIt1 and AutoIt2 for many years and then AHK was born from AutoIt in a not so happy split among the developers. I stuck with AutoIt because I liked the syntax change in AutoIt3. AHK stayed with the syntax of AutoIt2.
My System SpecsSystem Spec
15 Oct 2013   #10

Windows 7 Professional SP1 64bit
 
 

Hello and thank you for contributing.

Indeed, I was quite disconnected from that thread but I'm still interested in the initial problem I submitted (for which I haven't found a solution yet).

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.
If I'm not clear enough on a specific point you should tell me which.
In turn, I do not understand why you're talking about "SlickRun" and "AutoHotkey" since I'm interested in submitting a command in a shell "as administrator" ; I'm not interested in pressing a set of keys (keyboard shortcut) to trigger a specific action...

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.
My System SpecsSystem Spec
Reply

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




Thread Tools




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 10:41 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33