batch-file - 使用当前用户名发送密钥
问题描述
我正在尝试制作一个将打开特定站点并输入用户名的批处理文件。
我目前有以下代码,但问题是您必须自己输入用户名。
我想知道您是否可以使用 %USERNAME% 变量并转换它的每个字母并在浏览器输入窗口中自动输入。
@if (@CodeSection == @Batch) @then
@echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
start chrome "https://servicedesk.sa.gov.ge/"
rem the script only works if the application in question is the active window. Set a timer to wait for it to load!
timeout /t 3
rem use the tab key to move the cursor to the login and password inputs. Most htmls interact nicely with the tab key being pressed to access quick links.
rem now you can have it send the actual username/password to input box
%SendKeys% "{s}"
%SendKeys% "{o}"
%SendKeys% "{m}"
%SendKeys% "{e}"
%SendKeys% "{u}"
%SendKeys% "{s}"
%SendKeys% "{e}"
%SendKeys% "{.}"
%SendKeys% "{s}"
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
PS 我的用户名格式取自域,例如:“otarashvili.e”
解决方案
我确实设法使用以下代码完成了它:
@if (@CodeSection == @Batch) @then
@echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
start chrome -new-window --incognito "https://servicedesk.sa.gov.ge/"
rem the script only works if the application in question is the active window. Set a timer to wait for it to load!
timeout /t 3
rem use the tab key to move the cursor to the login and password inputs. Most htmls interact nicely with the tab key being pressed to access quick links.
rem now you can have it send the actual username/password to input box
%SendKeys% "%USERNAME%"
%SendKeys% "{TAB}"
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
推荐阅读
- service - 在 centos7 上停止 mosquitto 自动重启
- flutter - Flutter:按钮周围的 SizedBox 破坏了文本对齐
- xamarin - 根据样式测量文本大小
- c# - EF 核心中是否有更好的方法用于我的查询(仅因为父键而加入父表)?
- c - 不能在 Contiki 中使用 malloc
- jquery - Jquery数据表子表页面长度下拉菜单不可点击
- python-3.x - 尝试从站点打印元素
- python - 慢速文件拖网渔船——python
- angularjs - Angular 8.2.14 中 coreJS 的合适版本
- javascript - 网页上的 JSON 格式