可以自动输入密码的Runas

 

一 Runas

在使用批处理实现自动化的工程中,我们也许会遇到某些操作必须要在拥有权限的某个用户下才能执行。但是这时windows自带的Runas在批处理中调用时不能完成自动输入密码。 这时需要使用免费的第三方工具:

 

1)lsrunas (http://www.moernaut.com/default.aspx?item=lsrunas)

LSrunas can be used to run a command using another user account and passing the password as a parameter

Parameters:
-----------
  /user:          specifies the username
  /password:      specifies the password
  /domain:        specifies the domain
  /command:       specifies the command to execute and the parameters
  /runpath:       specifies the path where the command should start

Examples:
---------
lsrunas /user:administrator /password:s3cr3tp@ssw0rd /domain:Mydomain /command:notepad.exe /runpath:c:\

lsrunas /user:administrator /password:s3cr3tp@ssw0rd /domain:Mydomain /command:"C:\Program Files\Internet Explorer\iexplore.exe" /runpath:c:\

lsrunas /user:administrator /password:s3cr3tp@ssw0rd /domain:Mydomain /command:"C:\Program Files\Internet Explorer\iexplore.exe http://www.google.cn" /runpath:c:\

 

2)sanur (http://www.commandline.co.uk/sanur_unsupported/index.html)

Sanur is a tiny Win32 console utility that 'pipes' a password into the Windows 2000/XP/2003 Runas utility, thereby making Runas scriptable.

Usage
Pipe your normal Runas commandline into Sanur and specify the password on Sanur's commandline or use the /i switch to have Sanur read the password from a file:-

RUNAS | SANUR password
RUNAS | SANUR /i [drive:][path]filename

In otherwords, just add  | SANUR password  to the end of your working Runas command.

Examples
Pipe the password 'pa55w0rd' into Runas:
runas /u:domain\username program.exe | sanur pa55w0rd

Pipe the password from the file named password.txt into Runas:
runas /u:domain\username program.exe | sanur /i password.txt

Same as above but any Runas errors, such as a logon failure, will be displayed:
runas /u:domain\username program.exe >&2 | sanur /i password.txt

 

二使用shellrunas来为windows增加右键使用不同的用户来运行程序。

SysinternalsSuite-ShellRunas - Launch programs as a different user via a convenient shell context-menu entry.
 

完!

 

你可能感兴趣的:(可以自动输入密码的Runas)