6

Possible Duplicate:
is there any 'Sudo' command for windows ?

I was wondering how to switch to having administrative privileges in a command line window of Windows? Is there any way similar to "su" or "sudo" under Linux?

For example, I was stuck here:

Q:>fsutil fsinfo drives

The FSUTIL utility requires that you have administrative privileges.

Thanks and regards!


Update:

  1. I am not sure what is wrong:

    C:\D>runas /user:Tim "fsutil fsinfo drives"
    Enter the password for Tim:
    Attempting to start fsutil fsinfo drives as user
    

    "TIM-THINK\Tim" ...

    C:\D>runas /user:Tim "dir"
    Enter the password for Tim:
    Attempting to start dir as user "TIM-THINK\Tim" ...
    RUNAS ERROR: Unable to run - dir
    2: The system cannot find the file specified.
    

    if without the quote for the command in the end, the first example will output the help document for runas, and the second example will output the same as with quote.

  2. I was also wondering if I can switch to having administrative privileges once for all in the current session of the command line window, just as "su" in Linux?
Tim
  • 17,743

2 Answers2

4

Search command prompt in the Start Menu and right click on the entry->Run as administrator.

digitxp
  • 14,884
3

You can try the RUNAS command.

Q:>runas /user:Tim "fsutil fsinfo drives"

From the help:

C:\> runas /?
RUNAS USAGE:

RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]
        /user:<UserName> program

RUNAS [ [/noprofile | /profile] [/env] [/savecred] ]
        /smartcard [/user:<UserName>] program

RUNAS /trustlevel:<TrustLevel> program

   /noprofile        specifies that the user's profile should not be loaded.
                     This causes the application to load more quickly, but
                     can cause some applications to malfunction.
   /profile          specifies that the user's profile should be loaded.
                     This is the default.
   /env              to use current environment instead of user's.
   /netonly          use if the credentials specified are for remote
                     access only.
   /savecred         to use credentials previously saved by the user.
                     This option is not available on Windows Vista Home or Windo
ws Vista Starter Editions
                     and will be ignored.
   /smartcard        use if the credentials are to be supplied from a
                     smartcard.
   /user             <UserName> should be in form USER@DOMAIN or DOMAIN\USER
   /showtrustlevels  displays the trust levels that can be used as arguments
                     to /trustlevel.
   /trustlevel       <Level> should be one of levels enumerated
                     in /showtrustlevels.
   program         command line for EXE.  See below for examples

Examples:
> runas /noprofile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:user@domain.microsoft.com "notepad \"my file.txt\""

NOTE:  Enter user's password only when prompted.
NOTE:  /profile is not compatible with /netonly.
NOTE:  /savecred is not compatible with /smartcard.

dir is a builtin command. You would need to do:

runas /user:Tim "cmd /c dir"

To run a CMD shell as another user:

runas /user:Tim "cmd"