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

Command line 命令行:双击时使程序以管理员身份运行,command-line,admin,execution,Command Line,Admin,Execution,在Windows 7中,我有一个可执行文件A.exe。我希望当用户启动它时(通过双击),它会提示管理员权限。我知道可以通过选择“以管理员身份运行此程序”,然后在“属性”对话框中按“更改所有用户的设置”以图形方式完成,如下所示: 但是我需要一个命令行来做完全相同的事情。如何做到这一点 编辑:我不想从命令行以管理员身份运行.exe。目前,A.exe在启动期间不会提示管理员权限。我想要一个批处理程序B.bat,这样当我启动B.bat时,它将改变a.exe的这种行为。因此,在成功执行B.bat之后,当

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

但是我需要一个命令行来做完全相同的事情。如何做到这一点


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

您可以从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.
>runas.exe
运行方式使用:
运行方式[[/noprofile |/profile][/env][/savecred |/netonly]]
/用户:程序
RUNAS[[/noprofile |/profile][/env][/savecred]]
/智能卡[/user:]程序
运行方式/信任级别:程序
/noprofile指定不应加载用户的配置文件。
这会使应用程序加载更快,但是
可能导致某些应用程序出现故障。
/配置文件指定应加载用户的配置文件。
这是默认设置。
/env使用当前环境而不是用户的环境。
/仅当指定的凭据用于远程登录时使用
仅限访问。
/savecred使用用户以前保存的凭据。
/如果凭据是由供应商提供的,则使用智能卡
智能卡。
/用户应该在表单中USER@DOMAIN或域\用户
/ShowTrustLevel显示可以用作参数的信任级别
到信任级别。
/信任级别应为枚举的级别之一
in/ShowTrustLevel。
EXE的程序命令行。参见下面的示例
示例:
>runas/noprofile/user:mymachine\administrator cmd
>runas/profile/env/user:mydomain\admin“mmc%windir%\system32\dsa.msc”
>运行方式/环境/用户:user@domain.microsoft.com“记事本\“我的文件.txt\”
注意:仅在出现提示时输入用户密码。
注意:/profile与/netonly不兼容。
注意:/savecred与/smartcard不兼容。

找到了解决方案!关键是要访问exe。

恐怕您不明白:我不想从命令行以管理员身份运行它。我希望当任何用户双击它运行它时,它会提示管理员权限。