windows - 从批处理文件自动响应 runas

标签 windows batch-file runas

我试图让一个批处理文件自动将密码输入“runas”程序,但我无法让它工作。到目前为止,这是我的批处理文件:

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

但是,我收到一条错误消息“未知的用户名或错误的密码”。我也试过:

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

这会返回相同的错误。有谁知道这样做的方法吗?我最终要做的是让批处理文件从配置文件中读取用户名和密码,然后以该用户身份启动“program.exe”。

最佳答案

下面的 Batch-JScript 混合脚本可以满足您的需求。使用 .bat 扩展名保存。

@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 post

关于windows - 从批处理文件自动响应 runas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22866137/

相关文章:

Windows 批处理 : findstr not setting ERRORLEVEL within a for loop

windows - 为什么没有 ReadDirectoryChangesA?

windows - 在脚本中以管理员身份运行 cmd.exe

powershell - 通过 powershell 以管理员身份启动 msiexec

c++ - CreateProcessWithLogonW 和 mmc.exe

windows - 调用 "set"后,Cmake "find_path"对同一变量不起作用

php - WP-CLI.phar "could not open input file"

git - TortoiseGit Hook 脚本无法阻止启动提交

java - 如何从批处理脚本检查 Java 安装?

batch-file - 管道之后 "set -P"为什么不起作用?