自动从批处理文件运行方式回应 [英] Automatically respond to runas from batch file

查看:127
本文介绍了自动从批处理文件运行方式回应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个批处理文件来自动输入密码进入运行方式的计划,但我不能得到它的工作。这里是我的批处理文件,到目前为止:

I'm trying to get a batch file to automatically enter the password into the "runas" program, but I can't get it to work. Here's my batch file so far:

echo password | runas /user:testuser c:/path/to/my/program.exe

不过,我得到一个错误说未知的用户名或密码错误。我也曾尝试:

However, I get an error saying "unknown user name or bad password". I have also tried:

runas /user:testuser c:/path/to/my/program.exe < c:/path/to/file/containing/password.txt

这回来了同样的错误。有谁知道一个办法做到这一点?我试图最终做的就是批处理文件读取配置文件用户名和密码,然后启动的Program.exe作为该用户。

This comes back with the same error. Does anyone know a way to do this? What I'm trying to do eventually is get the batch file to read a username and password from a config file, and then start "program.exe" as that user.

推荐答案

下批次的JScript脚本混合做你想做的。与.bat扩展名保存它。

The Batch-JScript hybrid script below do what you want. Save it with .bat extension.

@if (@CodeSection == @Batch) @then
@echo off
start "" runas /user:testuser c:/path/to/my/program.exe
CScript //nologo //E:JScript "%~F0"
goto :EOF
@end
WScript.CreateObject("WScript.Shell").SendKeys("password{ENTER}");

有关详细信息,请参阅this帖子

For further details, see this post

这篇关于自动从批处理文件运行方式回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆