首页 > 解决方案 > 使用当前用户名发送密钥

问题描述

我正在尝试制作一个将打开特定站点并输入用户名的批处理文件。

我目前有以下代码,但问题是您必须自己输入用户名。

我想知道您是否可以使用 %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”

标签: batch-fileunified-service-desk

解决方案


我确实设法使用以下代码完成了它:

@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));

推荐阅读