Computing.Net > Forums > Programming > VBS to SendKeys after app loads

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBS to SendKeys after app loads

Reply to Message Icon

Name: keridbey
Date: March 25, 2008 at 12:00:26 Pacific
OS: WinXP
CPU/Ram: 1.83 Ghz / 1 Gb
Product: 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!



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: March 25, 2008 at 20:20:25 Pacific
Reply:

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


0

Response Number 2
Name: keridbey
Date: March 26, 2008 at 04:41:46 Pacific
Reply:

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!


0

Response Number 3
Name: Razor2.3
Date: March 26, 2008 at 17:42:08 Pacific
Reply:

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.

0

Response Number 4
Name: keridbey
Date: March 28, 2008 at 13:22:43 Pacific
Reply:

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!!!


0

Response Number 5
Name: keridbey
Date: April 3, 2008 at 07:02:52 Pacific
Reply:

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!


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: April 4, 2008 at 08:08:19 Pacific
Reply:

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}".


0

Response Number 7
Name: keridbey
Date: April 7, 2008 at 04:12:02 Pacific
Reply:

Good to know. Thanks for your help!!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

scripting /win xp /noobis... Scripting opinion



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBS to SendKeys after app loads

converting values of vb to word doc www.computing.net/answers/programming/converting-values-of-vb-to-word-doc/9875.html

Migration from VB to C www.computing.net/answers/programming/migration-from-vb-to-c/8407.html

VBS to Rename Files www.computing.net/answers/programming/vbs-to-rename-files/19550.html