命令行:双击时使程序以管理员身份运行

时间:2014-05-23 09:59:33

标签: command-line admin execution

在Windows 7中,我有一个可执行的A.exe。我希望当用户启动它时(通过双击),它会提示管理员权限。我知道可以通过选择“以管理员身份运行此程序”然后在属性对话框中按“更改所有用户的设置”以图形方式完成,如下所示:

enter image description here

但我需要一个完全相同的命令行。如何实现?

编辑:我不想从命令行以管理员身份运行A.exe。目前,A.exe在启动期间不会提示管理员权限。我想要一个批处理程序B.bat,这样当我启动B.bat时,它将改变A.exe的这种行为。因此,在成功执行B.bat之后,当任何用户通过双击(而不是从命令行)启动A.exe时,它会提示输入管理员权限。 B.bat不执行A.exe,它只更改A.exe的“设置”。我现在不太容易理解......

2 个答案:

答案 0 :(得分:1)

您可以在CMD中使用runas.exe

>runas.exe

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.
   /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.

答案 1 :(得分:0)

找到解决方案!关键是embed a manifest file到exe。