Automatically starting a Windows app that requires a username and password

390

Solution 1

You could potentially do this using VBScript. I know there's a SendKeys command that can send pretty much any kind of keyboard input to a program launched via the script.

Here's one way of using it:

set WshShell = WScript.CreateObject("WScript.Shell") 

WshShell.run "runas /user:domain\user %comspec%" 'Open command prompt  
WScript.Sleep 1000 
WshShell.SendKeys "password" 'send password   
WshShell.SendKeys "{ENTER}"    
WScript.Sleep 1000 

'Open IE 
WshShell.SendKeys Chr(34) + "C:\PROGRAM FILES\INTERNET EXPLORER\IEXPLORE.EXE"_
  + Chr(34) 
WshShell.SendKeys "{ENTER}" 

WshShell.SendKeys "exit"  'Close command prompt 
WshShell.SendKeys "{ENTER}" 
WScript.Sleep 1000 

WshShell.SendKeys "{TAB}" 
WshShell.SendKeys "http://www.microsoft.com" 'Send internet page to open to IE 
WshShell.SendKeys "{ENTER}" 

Here's another method of using it without WshShell:

Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
' Send the keystrokes to the Calculator application.
My.Computer.Keyboard.SendKeys("22", True)
My.Computer.Keyboard.SendKeys("*", True)
My.Computer.Keyboard.SendKeys("44", True)
My.Computer.Keyboard.SendKeys("=", True)
' The result is 22 * 44 = 968.

Solution 2

I'd recommend using the Windows 'Task Scheduler' or 'Scheduled Tasks' depending on your version of windows. It's great for starting programs or launching scripts without user intervention. You can configure your task to start based on different 'triggers' or 'events' such as time of day or after a reboot. It can do this without being logged on. Here is a tutorial that will show you how to setup a task to start a program following a system reboot. You may need to change a few of the perameters, but it's easy to use.

Share:
390

Related videos on Youtube

Q.H.
Author by

Q.H.

Updated on September 18, 2022

Comments

  • Q.H.
    Q.H. over 1 year

    Note, I've already looked at:

    Understanding the evaluate function in CasperJS

    I am trying to write a simple web-scraper to download all pdf's on my professor's webpage.

    Here is my code:

    var casper = require('casper').create({verbose: true , logLevel: "debug" });
    var url = "https://www.cs.rit.edu/~ib/Classes/CSCI264_Fall16-17/assignments.html";
    casper.start(url);
    
    var elements; 
    try {
        casper.then(function(){
            try {
            // statements
            elements = this.evaluate(function(){ return __utils__.findAll('body ul li a'); });
            console.log("elements: " + elements);
            console.log(this.getCurrentUrl());
    
            } catch(e) {
                // statements
                console.log(e);
            }   
        });
    } catch(e) {
    
        console.log(e);
    }
    casper.run();
    

    The elements array size given back is always zero but when I put

    __utils__.echo(__utils__.findAll('body ul li a').length);

    I get the correct amount of links.

    Is this because the evaluate function won't return an array of elements?

    Any help would be appreciated.

    • iglvzx
      iglvzx about 12 years
      Which operating system?
  • Q.H.
    Q.H. over 7 years
    Okay, before I had "querySelectAll" outside the evaluate function but this is incorrect because then it wouldn't execute within the page document object. Now it does, thank you.