Windows运行方式命令-使用不同的用户帐户执行程序

runas 是一个特殊命令,用于运行或执行具有不同权限和用户的应用程序。应用程序的执行方式将不同于当前用户或登录用户。Runas首先随Windows Vista操作系统提供,后来被所有现代Windows操作系统采用,如Windows XP、Windows 7、Windows 8、Windows 10、Windows Server 2003、Windows Server 2008、Windows Server 2012、Windows Server 2016、Windows Server 2019。

null

在使用runas时,尝试使用较少特权的帐户来限制权限以防止安全漏洞。runas命令最流行的用例之一是为普通用户运行具有管理员权限的命令和工具。

runas命令语法

runas命令使用选项、用户和应用程序的语法如下。

runas OPTION USER APPLICATION
  • 选项 用于为runas命令提供不同的行为。下面详细解释该选项。
  • 用户 将在其中执行应用程序的用户帐户和权限。用户参数提供为 /user:ismail .
  • 应用 将使用提供的用户权限和给定选项执行的应用程序。此应用程序可以是二进制文件、可执行文件、命令或脚本。

运行方式命令选项

runas命令提供以下选项或参数来更改用法。

期权 说明
/简介 加载用户配置文件。此参数不能与 /仅网络 参数。
/非营利组织 不要加载用户配置文件。使执行速度更快。
/环境 指定与用户不同的网络环境。
/仅网络 指示指定的用户信息仅用于远程访问。此参数不能与 /简介 参数。
/储蓄信用 保存提供的用户凭据。此参数不能与 /智能卡 参数。
/智能卡 从智能卡提供凭据。此参数不能与 /储蓄信用 参数。
/显示信任级别 显示可以用作的参数的信任级别 /信任级别 .
/信任级别 设置应用程序的信任级别。使用 /显示信任级别 查看可用的信任级别。
/用户:< 用户帐户名> “< 程序名> 指定用户名
/? 显示帮助信息

显示运行方式帮助信息

有关runas命令的帮助信息可以通过 /? 选项如下。此帮助信息还提供了一些用法示例。

C:Usersismail>runas /?RUNAS USAGE:RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]        /user:<UserName> programRUNAS [ [/noprofile | /profile] [/env] [/savecred] ]        /smartcard [/user:<UserName>] programRUNAS /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 [email protected] or DOMAINUSER   /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 examplesExamples:> runas /noprofile /user:mymachineadministrator cmd> runas /profile /env /user:mydomainadmin "mmc %windir%system32dsa.msc"> runas /env /user:[email protected] "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.

使用不同的用户帐户运行应用程序

我们将从一个简单的示例开始,在这个示例中,我们将使用不同的用户运行或执行应用程序。我们将提供 /用户 用户ismail的选项。我们还将指定要运行的应用程序或可执行文件。此外,脚本也可以按同样的方式执行。

> runas /user:ismail cmd.exe

当我们执行这个命令时,我们将被要求输入指定用户的密码,在这个例子中,这个用户是ismail。顺便说一下,所有内容都将在命令行中,并且提供的密码不会显示,这是一种安全措施。此外,还提供了有关用户的完整信息,如作为本地帐户的用户域。

C:>runas /user:ismail cmd.exeEnter the password for ismail:Attempting to start cmd.exe as user "DESKTOP-HQVAMA3ismail" ...

下面您可以找到关于runas命令的不同示例。使用双引号对于具有多个空格和额外参数的命令非常有用。

> runas /user:ahmet cmd.exe> runas /user:ismail C:UsersismailDownloadspython-3.8.5-amd64> runas /user:ismail "C:UsersismailDownloadspython-3.8.5-amd64"> runas /user:ismail "C:WindowsSystem32cmd.exe" > runas /user:ismail "notepad.exe C:UsersismailDesktopfile.txt" 

保存凭据

如果您经常为相同的用户反复使用runas命令,那么键入凭据或密码是一项微不足道的任务。您可以保存一次凭据或密码,然后多次使用这些凭据,而无需反复键入。你需要提供 /储蓄信用 选项,该选项将保存当前用户的凭据或密码,以后不会请求此用户的密码。

> runas /user:ahmet /savecred cmd.exe

无用户配置文件的运行方式

默认情况下,将加载为运行方式指定的用户配置文件以执行提供的命令。用户配置文件只是用户配置、环境变量等。这会创建一些工作负载,这会使runas命令的速度慢一些。通过使用 /非营利组织 此选项可以被禁用,用户配置文件将不会被加载,并且将使用当前用户配置文件。

> runas /user:ahmet /noprofile cmd.exe

使用当前用户环境

/env选项可用于使用当前用户环境,即使命令将以指定的用户权限执行。

> runas /user:ahmet /env cmd.exe

使用域帐户运行应用程序

我们也可以在域或活动目录环境中使用runas命令。我们可以使用不同的域帐户运行可执行文件或应用程序。我们将只添加域名和域名帐户名。在下面的示例中,我们将运行 cmd.exe windowstect 域和用户 ismail .

C:>runas /user:windowstectismail cmd.exeEnter the password for ismail:Attempting to start cmd.exe as user "windowstectismail" ...

它还可以用于运行具有其他域用户权限的应用程序,而无需注销和使用不同的域用户登录。只提供其他域名和用户名作为当前域帐户信息。

相关文章: Windows中的“Program Files”和“Program Files(x86)”文件夹有什么区别?

运行应用程序本地管理员帐户

管理员帐户是当前系统中具有所有权限的最高级别帐户。本地管理员帐户是与域无关的本地系统的管理员帐户。通过使用runas命令,可以使用本地管理员帐户来安装应用程序和更改配置。

C:>runas /user:Administrator Chrome.exeEnter the password for Administrator:Attempting to start Chrome.exe as user "Administrator" ...

运行应用程序域管理员帐户

这个 Domain Administrator 帐户用于管理具有最高级别权限的域。域管理员帐户可用于安装应用程序并更改本地和域范围的配置。域管理员帐户由域名和 Administrator .

C:>runas /user:windowstectAdministrator Chrome.exeEnter the password for Administrator:Attempting to start Chrome.exe as user "windowstectAdministrator" ...

来自文件资源管理器或GUI的运行方式

这个 runas 该机制也可以从文件资源管理器的图形用户界面使用。我们可以用不同的用户权限和帐户运行不同的应用程序和可执行文件。这对于使用管理员帐户安装应用程序而无需登录管理员用户帐户尤其有用。要以运行方式运行,请右键单击可执行文件,同时按 班次 键打开菜单,如下所示。单击 Run as different user 指定要在其中执行的用户帐户。

图片[1]-Windows运行方式命令-使用不同的用户帐户执行程序-yiteyi-C++库
以不同用户身份运行应用程序

我们将看到下面的屏幕,其中它请求用户名和密码等用户权限来运行指定的可执行文件。

图片[2]-Windows运行方式命令-使用不同的用户帐户执行程序-yiteyi-C++库
指定运行方式的用户名和密码

流行的运行方式命令示例

在这一部分中,我们将提供一些有用且流行的命令,这些命令可以与runas一起使用。

# Start the cmd.exe or MS-DOS with administrator privileges> runas /noprofile /user:mypcadministrator cmd
.exe# Open the MMC without logging as Administrator> runas /profile /env /user:mydomainadmin "mmc %windir%system32dsa.msc"
# Open the myfile.txt as different user with notepad.exe> runas /user:[email protected] "notepad C:myfile.txt"
# Open Registery or regedit> runas /user:administrator regedit# Shutdown the system> runas /user:administrator /savecred "shutdown /i"

运行方式命令错误

使用runas命令时,可能会发生一些错误。例如,如果提供的密码错误或提供的用户帐户不存在 “1326:用户名或密码不正确。” .

C:>runas /user:Administrator cmd.exeEnter the password for Administrator:Attempting to start cmd.exe as user "DESKTOP-HQVAMA3Administrator" ...RUNAS ERROR: Unable to run - cmd.exe1326: The user name or password is incorrect.

此外,runas命令不适用于空密码。所以用户应该有一个不为空的密码。如果用户的密码为空,您将获得 “1327:登录失败:用户帐户限制。可能的原因是不允许空白密码、登录时间限制或已强制执行策略限制 错误。如您所见,登录时间限制或策略限制等可能会发生此错误。

C:>runas /user:ismail cmd.exeEnter the password for ismail:Attempting to start cmd as user "ABCismail" …RUNAS ERROR: Unable to run – cmd1327: Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced.
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享