如何切换到具有管理权限

Tim*_*Tim 6 windows-7 command-line

可能重复:
Windows 是否有任何“Sudo”命令?

我想知道如何在 Windows 的命令行窗口中切换到具有管理权限?Linux下有没有类似于“su”或“sudo”的方法?

例如,我被困在这里:

Q:>fsutil fsinfo 驱动器

FSUTIL 实用程序要求您具有管理权限。

感谢致敬!


更新:

  1. 我不确定出了什么问题:

    C:\D>runas /user:Tim "fsutil fsinfo drives"
    Enter the password for Tim:
    Attempting to start fsutil fsinfo drives as user
    
    Run Code Online (Sandbox Code Playgroud)

    “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.
    
    Run Code Online (Sandbox Code Playgroud)

    如果最后没有给命令加上引号,第一个例子会输出runas的帮助文档,第二个例子会输出和quote一样的内容。

  2. 我还想知道是否可以像 Linux 中的“su”一样在命令行窗口的当前会话中一次性切换为拥有管理权限?

Den*_*son 3

你可以尝试一下RUNAS命令。

Q:>runas /user:Tim "fsutil fsinfo drives"
Run Code Online (Sandbox Code Playgroud)

来自帮助:

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.
Run Code Online (Sandbox Code Playgroud)

dir是一个内置命令。你需要这样做:

runas /user:Tim "cmd /c dir"
Run Code Online (Sandbox Code Playgroud)

以另一个用户身份运行 CMD shell:

runas /user:Tim "cmd"
Run Code Online (Sandbox Code Playgroud)