Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

VBS to SendKeys after app loads

Original Message
Name: keridbey
Date: March 25, 2008 at 12:00:26 Pacific
Subject: VBS to SendKeys after app loads
OS: WinXP
CPU/Ram: 1.83 Ghz / 1 Gb
Model/Manufacturer: Dell
Comment:
I've been fiddling with some code recently to automatically bring up an IE page, then use SendKeys to tab to the "username" field, enter the info, tab to the "password" field, enter the info, then finally hit ENTER. My code worked fine, but the IE page doesn't always load at the same speed, so I made some modifications based on a few code bits I found from various sources in an attempt to have the script wait until IE was completely loaded before proceeding with the SendKeys portion:

Option Explicit
Dim objShell, objIE
Set objShell = CreateObject("WScript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate ("http://URLOnMyIntranet//?cid=6&c=12&cpc=dt2wJiVUfnQ2")
While objIE.Busy
wscript.sleep 2000
Wend
objShell.AppActivate "Internet Explorer"
objShell.SendKeys "{TAB}"
objShell.SendKeys "{TAB}"
objShell.SendKeys "username"
objShell.SendKeys "{TAB}"
objShell.SendKeys "password"
objShell.SendKeys "{ENTER}"
set objIE=Nothing
Set objShell=Nothing
WScript.Quit

The problem is that the script seems to do absolutely nothing. Where might I have gone wrong here? Thanks!


Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: March 25, 2008 at 20:20:25 Pacific
Subject: VBS to SendKeys after app loads
Reply: (edit)
Well, for one, you didn't set objIE.Visible = True.

Also, you're using SendKeys when InternetExplorer.Application provides its own text input.

Option Explicit
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://URLOnMyIntranet//?cid=6&c=12&cpc=dt2wJiVUfnQ2"
Do While .Busy
WScript.Sleep 100
Loop
.Document.getElementByID("usernameInput").Value = username
.Document.getElementByID("passwordInput").Value = password
'Note: You could just get the form and submit it, but
'you'll miss out on any special JavaScript associated
'with the Submit button.

.Document.getElementByID("SubmitButton").Click
End With


Report Offensive Follow Up For Removal

Response Number 2
Name: keridbey
Date: March 26, 2008 at 04:41:46 Pacific
Subject: VBS to SendKeys after app loads
Reply: (edit)
I really need to either find a decent VBS guide or class; so far everything I know has been based off of picking apart other scripts I've run across (which is fine for learning how to write batch files, but VBS seems to be a different animal entirely).

I'm gathering that "usernameInput" is the defined name of the field, and that "username" is the actual username to be entered. When I ran it, I got an error stating that the variable "username" (after I changed it to the actual username, of course) was undefined. I may have this backwards; I'm just not familiar with some of these commands. Here's the relevant code for the web page:

<tr>
<td align=right class="defaultText">Username : </td>
<td><input type=text name="username" value=""></td>
</tr>
<tr>
<td align=right class="defaultText">Password : </td>
<td><input type=password name="password" value=""></td>
</tr>

This may be something simple, but I haven't been able to figure out why I'm getting this message yet. Thanks for your help!


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: March 26, 2008 at 17:42:08 Pacific
Subject: VBS to SendKeys after app loads
Reply: (edit)
That form uses the name property, not id. You'll need to adjust the script accordingly
Option Explicit
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://URLOnMyIntranet//?cid=6&c=12&cpc=dt2wJiVUfnQ2"
Do While .Busy
WScript.Sleep 100
Loop
.Document.getElementsByName("username").Item(0).Value = username
.Document.getElementsByName.("password").Item(0).Value = password

'Note: You could just get the form and submit it, but
'you'll miss out on any special JavaScript associated
'with the Submit button.

.Document.getElementsByName("Submit").Item(0).Click
End With

VBScript is easy; the problem is everything VBS can interface with.

Report Offensive Follow Up For Removal

Response Number 4
Name: keridbey
Date: March 28, 2008 at 13:22:43 Pacific
Subject: VBS to SendKeys after app loads
Reply: (edit)
The powers that be have just saddled me with a new project that takes precedence over this one, so I'm going to have to shelve this for now, but I've saved everything, and will definitely try it out when I get the chance. Thanks for your help!!!

Report Offensive Follow Up For Removal

Response Number 5
Name: keridbey
Date: April 3, 2008 at 07:02:52 Pacific
Subject: VBS to SendKeys after app loads
Reply: (edit)
Okay, I got the web browser bit working; I was wondering how it might be adapted to other third-party applications (run a program, wait for the login dialog window to appear, enter the info, then send a carriage return or click a button.

Thanks!


Report Offensive Follow Up For Removal


Response Number 6
Name: Razor2.3
Date: April 4, 2008 at 08:08:19 Pacific
Subject: VBS to SendKeys after app loads
Reply: (edit)
Unless the application has a script-able ActiveX interface, you'll need to use SendKeys, which you already know how to use.

Quick note, though. You can use "~" as a shortcut for "{ENTER}".


Report Offensive Follow Up For Removal

Response Number 7
Name: keridbey
Date: April 7, 2008 at 04:12:02 Pacific
Subject: VBS to SendKeys after app loads
Reply: (edit)
Good to know. Thanks for your help!!!

Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: VBS to SendKeys after app loads

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs

Best WinMo phone of 2008


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC