Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a .vbs log in script

Status
Not open for further replies.

novareborn

IS-IT--Management
Oct 11, 2010
10
US
Hi, i really could use some help, i have been working on this script for a few days now. Basically i have been creating a vbs that will log in to multiple tools within tabs if Ie. I have managed to get most of them working. My main problem is that i am trying to set a log in for the log in button does not have a id so i can not use the normal click for a id. also the page for what ever reasons always open in the background so i can not use the send keys to send a enter command once the pass is filled. can i please get some help the simple code is as follows. i stopped it after the pass part because nothing i have tried seem to work. if anyone know how to call the ie to the front then i can use the send keys or if anyone know how to make the code click the button that would be great.

Set objShell = WScript.CreateObject("WScript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.Navigate "objIE.Visible = True
Wscript.Sleep 2000
objIE.Document.All.Item("username").Value = "username"
objIE.Document.All.Item("password").Value = "pass
 
which one? i am new here and i am not sure what you may be refering to with http post, i figured i would write here since i have a issue with the vbs working for me, but i will be glad to look at any sugestions
 
if it helps more, i am creating a simple script that can be clicked on from my desktop, that will open about 7 tools that i use, some are web some are applications, i have had success with all but this one because of the no id for the log in button.
 
Seems like you have to call the clkLgn() function in the document.

If you insist on SendKeys then you may consider the AppActivate method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thanks for some sugestions, My job has limited access to admin rights on computers so installing any applications is like pulling teeth from a croc.

i am still trying to learn Vsb which is why i turned to here for help, i was hoping someone knew the exact code that may do the job.

when you say call the clkLgn() function, what string of text would be used to do that?

I do not need send keys, I just need a method that works. once i get it working i can finally have a fully working way of opening my daily tools with clicking 1 things.
 
[tt]set cinputs=objIE.document.getElementsByTagName("input")
for each obj in cinputs
if strcomp(obj.type,"submit",1)=0 and strcomp(obj.value,"sign in",1)=0 then
obj.click()
exit for
end if
next
set cinputs=nothing
[/tt]
 
'?
objIE.Document.getElementByID("button_name").Click

 
'?
oIE.Document.Script.clkLgn()

tsuji, didnt see your last post
 
The law of rare events may turn out not be so rare.
 
i am very grateful for the help, but i am still running into errors, with Tsuji's code i get a error: expected end of statement

the objIE.Document.getElementByID("button_name").Click will not work because there is not button id on the page

when i add
'?
oIE.Document.Script.clkLgn()
or
'?
objIE.Document.Script.clkLgn()

it just sit there with no errors, but it does not submit either by some change am i just adding the coding to my code improper?

Set objShell = WScript.CreateObject("WScript.Shell")
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.Navigate "objIE.Visible = True
Wscript.Sleep 2000
objIE.Document.All.Item("username").Value = "user"
objIE.Document.All.Item("password").Value = "pass"
'?
objIE.Document.Script.clkLgn()
 
>with Tsuji's code i get a error: expected end of statement
Not that kind of error with my code, if any.
 
Hi, Tsuji, maybe I am just placing it wrong, can you please paste how you would set up the full code including mine? as i said earlier i am new to the script and this kind of coding works because it can make a .vbs file on my desktop and click it without having to battle my boss for rights to install a application that would do what i am trying to do. a example is below of what i managed to get working for every other page, i mainly ran into the issue with that mail page because of the no id....

Set objShell = WScript.CreateObject("WScript.Shell")
navOpenInBackgroundTab = &h1000
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.top = 0
objIE.left = 1370
objIE.Height = 770
objIE.Width = 650
objIE.Navigate "objIE.Visible = True
Wscript.Sleep 4000
objIE.Document.All.Item("AdminCenterLoginControl$UserNameTextBox").Value = "username"
objIE.Document.All.Item("AdminCenterLoginControl$PasswordTextbox").Value = "pass"
objIE.Document.All.Item("AdminCenterLoginControl_ActionButton").Click
 
hi, did you guys give up on me? are the codes not working because of my arangement of them?
 
If you change every time the target page without saying why and which is actually you want to go to and what difficulies encounted on handling that page, we can't take the question seriously; and the answers given have given you sufficient clue to adopt to your needs by yourself (isn't that what you desire at the end? by hiding and changing all the time?) Each page has their own design and poses different challenges. This is the microsoft page you originally said you want to go to. This shows you what you would get without actually submitting.
[tt]
[green]surl= "[ignore][/ignore]"[/green]

set oie=createobject("internetexplorer.application")
with oie
.navigate "about:blank"
do while .readystate<>4 : wscript.sleep 50 : loop
.navigate surl
do while .readystate<>4 : wscript.sleep 50 : loop
.visible=true
end with

set cinputs=oie.document.getElementsByTagName("input")
for each obj in cinputs
if strcomp(obj.type,"submit",1)=0 and strcomp(obj.value,"sign in",1)=0 then
wscript.echo obj.type & vbcrlf & obj.value & vbcrlf & "find it"
'obj.click()
'exit for
end if
if strcomp(obj.type,"text",1)=0 then
obj.value="username"
end if
if strcomp(obj.type,"password",1)=0 then
obj.value="password"
end if
next
set cinputs=nothing
set oie=nothing
[/tt]
 
i love this saying:

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Hi i did not change anything, i do apologies if i am unclear in my post, so let me say it like this and hopefully it will clear up any issues....

What i am doing is creating a .vbs file that will be on my desktop.

the way i posted the code is what i have in the file, when i double click the file it runs the code to open pages and log me in to all but the mail page.

the problem i keep keep running into is that the ie pages when open, load in the back ground and that is ok for some of the pages, i am able to still have the code fill in user pass and click.

the microsoft page is where i have a issue because the log in is not a button with a id to click, but if the window is able open on top i can use send keys to just simply highlight the pass field then send a enter commmand, that would work but because i can not figure a way to front load the ie it causes a issue.

If you take my code, drop it in a .vbs and double click it on the desktop you will see that i loads the page and input the user and pass but you will see the window load in the back so if you add the send keys for enter or try to navagate with send keys i does not work unless you are fast enough to click the ie window to bring it to thr front.

all i am trying to do it to make a clickable file on my desktop that opens my programs and log me in. i do not have permission to install programs or aps on my work computer so the bath or vbs was my best thought. my vbs code works but it has some issues because i do not know how to call the ie window to the front or set the focus to the ie window so i can send keys to it.

i even developed the code to open in tabs but again the whole window is in the background when open, so i can't use send keys, i can open tabe in the background but not the froreground.

Understand?

the second code i provided was just more code to show you what i had that worked for my other pages.

 
when it comes to your code tsuji, i am unsure of how to run it or process it, because it does not function like the code i have where i just simple drop it in a .vbs then double click the file. i am not a programmer and make things as i learn them on a research and find out how to do it kind of way. for your code to work what would i need to run it with?

i am sure that maybe the way i am doing things are very caveman like and i am always earger to evolve the way i do things.
 
novareborn,
tsuji's last post, if you copy and past that code into a .vbs file, then run that vbs file it will execute tsuji's code.
i tried it myself, it works but does have a timing issue, e.g. the part at the top:

with oie
.navigate "about:blank"
do while .readystate<>4 : wscript.sleep 50 : loop
.navigate surl
do while .readystate<>4 : wscript.sleep 50 : loop
.visible=true
end with

doesnt seem to be waiting till a time when the .document controls are available.

i put a msgbox "" immediately after, waited for the page to 'fully' load, then clicked the OK, then the rest of tsuji's code populates the username and password...but doesnt click the button because tsuji commented that out with a ' (and gladly commented out the Exit For as i fear it might click the button before populating the username and password)



I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top