Search code examples
batch-fileunified-service-desk

Send keys with current username


I'm trying to make a batch file that will open a specific site and type in the username.

I have the following code at the moment, but problem is that you have to type in user name yourself.

I was wondering if you could use %USERNAME% variable and convert each letter of it and type in automatically in the browser input window.

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

P.S. User name format in my case is taken from domain, for example: "otarashvili.e"


Solution

  • I did manage to get it done with the following code:

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