我想在执行bat文件时写。
执行命令后,我必须输入用户名和密码。执行命令时,我将显示以下输出:
You have been directed successfully.
Usernae =
用户手动输入用户名后,会要求输入密码。
You have been directed successfully.
Usernae = user
password =
如何创建批处理脚本来写入此用户名和密码,而无需输入?
答案 0 :(得分:1)
您可以在VBS中使用SendKey
发送此输入。
只需将以下代码中的占位符值替换为实际值:
set "_user_=user-x" & set "_pwd_=password-y"
set "_exec_=drive:\path\to\your\executable.exe"
@echo off & setlocal enabledelayedexpansion & cls
mode con cols=70 lines=20 & color 9F
set "_user_=user-x" & set "_pwd_=password-y"
set "_exec_=drive:\path\to\your\executable.exe"
>"%temp%\_temp_file_4vbs_.vbs"^
(
echo/ Set WshShell = WScript.CreateObject^("WScript.Shell"^)
echo/ Set objShell = WScript.CreateObject^("WScript.Shell"^)
echo/ StrUser = "!_user_!"
echo/ StrPwd = "!_pwd_!"
echo/ Wscript.Sleep 1000
echo/ Wscript.Sleep 1000
echo/ for h=1 To Len^(StrUser^)
echo/ x = Mid^(StrUser,h,1^)
echo/ WshShell.SendKeys x
echo/ Wscript.Sleep 200
echo/ Next
echo/ Wscript.Sleep 200
echo/ WshShell.SendKeys "({ENTER})"
echo/ Wscript.Sleep 200
echo/ for j=1 To Len^(StrPwd^)
echo/ x = Mid^(StrPwd,j,1^)
echo/ WshShell.SendKeys x
echo/ Wscript.Sleep 200
echo/ Next
echo/ Wscript.Sleep 200
echo/ WshShell.SendKeys "({ENTER})"
echo/ Wscript.Sleep 200
echo/ WshShell.SendKeys "({ENTER})"
)
set "_temp_vbs=%temp%\_temp_file_4vbs_.vbs" & cls && start "" /b "!_exec_!"
@"%Windir%\System32\cScript.exe" //nologo "!_temp_vbs!" & del /q /f "!_temp_vbs!" & goto :eof