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

Page 1 of 2 12 LastLast

  1. Posts : 26
    Windows 7 Professional SP1 64bit
       #1

    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 Computer


  2. Posts : 173
    Windows 7 (XP, by Virtualization)
       #2

    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 Computer


  3. Posts : 5,642
    Windows 10 Pro (x64)
       #3

    Mr Davo said:
    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 Attached Thumbnails Run "cmd.exe" as a given user and "as administrator" in command line-untitled.png  
      My Computer


  4. Posts : 370
    Windows 7 Ultimate x64
       #4

    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 Computer


  5. Posts : 26
    Windows 7 Professional SP1 64bit
    Thread Starter
       #5

    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 Computer


  6. Posts : 10,485
    W7 Pro SP1 64bit
       #6

    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 Computer


  7. Posts : 8
    Windows 7 Ultimate x64
       #7

    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 Computer


  8. Posts : 260
    Windows 7 Ultimate 64bit
       #8

    How to use admin account


    Lea Massiot said:
    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 Computer


  9. Posts : 10,485
    W7 Pro SP1 64bit
       #9

    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 Computer


  10. Posts : 26
    Windows 7 Professional SP1 64bit
    Thread Starter
       #10

    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 Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 07:10.
Find Us