PDA

View Full Version : Login for Vitrix



SmoiL
06-18-2002, 10:56 PM
At my work I have to clock in/out using Vitrix (myvitrix.centralservers.com). Im working on a script that I can leave running at home that will clock me in, lunch, and out. Im sure it helps that Im new to scripting, so Im taking it a step at a time.
Currently I found some code her that will open IE for me and go to the login page:

set ie = createObject("internetExplorer.application")

ie.navigate "myvitrix.centralservers.com"

do
loop while ie.readyState <> 4

ie.visible = true

So now I need to figure out how to send keystrokes to the form within the page, on start up the cursor is already within the first field, I tried sending a string using WshShell.SendKeys "A" but the A will not show up in the form. I had planned to send a string, tab to next field, send string, tab, send string then hit enter.

If anyone has any ideas on what I might need to accomplish this I would be appreciative.

(After I get this working Ill try moving on to the next step)

SmoiL
06-18-2002, 11:12 PM
I figured that part out, seems that if I have any other windows open the new IE window will appear but will be in the back, anyone have a suggestion as to how I can force it to open as the active window?

current script:

set WshShell = CreateObject("WScript.Shell")


set ie = createObject("internetExplorer.application")

ie.navigate "myvitrix.centralservers.com"

do
loop while ie.readyState <> 4

ie.visible = true

WScript.Sleep 500

WshShell.SendKeys "WORK{TAB}"
WScript.Sleep 500
WshShell.SendKeys "MYNAME{TAB}"
WScript.Sleep 500
WshShell.SendKeys "PASSWORD~"
WScript.Sleep 500

<P ID="edit"><FONT class="small">Edited by SmoiL on 06/18/02 17:13.</FONT></P>

Jama
06-19-2002, 12:30 AM
I’ve seen quit a few cheeky questions, but never imagined anything like this. /images/forums/icons/shocked.gif

Anyway, here is what you need;


Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "AppName"
Set WshShell = Nothing

Where AppName is the title of the window you want activated (as it appears in the title bar)

If you get caught, you don’t know me, ok? /images/forums/icons/wink.gif

<a target="_blank" href=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsoriMethods.asp> Windows Script Host Methods </a>

Jama

adamdelves
06-19-2002, 09:35 AM
If you are using windows 2000 the wSHShell.AppActivate method will not bring the Ie form to the foreground. However as you have a reference to the Document Object model of the web page you can interact with it directly through your script.

SmoiL
06-19-2002, 09:27 PM
The AppActivate did work with win2k, you mentioned something about interacting with the the page directly...could you elaborate more or perhaps send me a nice link where I could explore this further?

adamdelves
06-23-2002, 12:13 PM
Sorry for the delay in the reply.basically when you user the CreateObject method to open internet explorer the varaiable you assign the object to. Thats the one just after the set keyword:

<pre>set <font color=red>ie</font color=red> = CreateObject("internetExplorer.application")</pre>

ieExplorer.exe is a COM object and can be called by a script through createobject as internetexplorer.application returning an Iwebbrowser2 object.

this object allows you to access internet explorer and its current webpage if any displayed thourhg the (Document Object Module) DOM. These days a HTML document is as an object and so are all the tags inside. In other words you can do as you please with the HTML document.

You can see this by opening any webpage the way you did in the code example you gave earlier and adding thefollowing code.

<pre>
set ie = createobject("internetexplorer.application")

ie.navigate "www.yahoo.com"

do
loop until ie.readystate = 4

ie.visible = true

set alltags = ie.document.all

for each tag in alltags
msg = msg & tag.tagname & " "
next

msgbox msg

ie.quit

set ie = nothing
</pre>

All these tags can be accssed through a varity of
properties and methods.
The folowing link has all the documentation on the DOM and how to access it.
If you need anymore help just let me know.

<a target="_blank" href=http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/mshtml.asp>MSHTML.dll Documentation</a>

Nana
06-25-2002, 07:26 PM
Smoil,

I sure hope your boss (or someone at Vitrix) doesn't read this forum and decide to check which ISPs are sending what information.

And then. . .
Which IP addresses are sending what. . .
And then. . .
Whose computer is at that IP address. . .
And then. . .

Oops! The jig is up, so they say!

Good luck,
Nana /images/forums/icons/laugh.gif

Jama
06-27-2002, 03:15 PM
Adam, thank you.

I came across DOM before. In fact, I hade a script that retrieved user input from Internet explorer. At the time, I thought that’s all you could do with DOM.

Because of your earlier post, I decided to investigate the inner workings of the Document Object Model (DOM).

I’m nowhere near learning every aspect of DOM, but so far I’ve learned how to control certain aspects of Internet Explorer from a script.

As a result, I have created a few handy scripts that automate IE and make my browsing experience easier and faster. And for that, I’m thanking you.

I would like to share my scripts with you and other members of this forum.

First is the Google search script (My favourite).

Once installed, it adds a “Google Search” option to Internet Explorer’s context menu (the one you get when you high-light text and right-click it in IE).

1- Right-click a high-lighted text in IE and select “Google Search”, the script will open a new IE window, navigate to Google’s web page, enter the text in the search box and submits the query, all in less than 5 seconds!

2- If you come across a file on your PC that you would like to know more about, such as what is it and what program install it, just right-click it, select SendTo and choose “Google Search”. Dead easy!

Try it, if you don’t like it, just uninstall it.

To install or uninstall, just double-click the script.

Tested with Windows ME, Windows 2000 and Windows XP professional.

‘================= Google Search.vbs ==================

If WScript.Arguments.count &gt; 0 Then
Set objArgs = WScript.Arguments
For Each arg In objArgs
If InStr(arg, "\") &gt; 0 then
myarray = Split(arg, "\")
s = s + myarray(UBound(myarray)) & " "
Else
s = s + arg & " "
End If
Next
Input = s
Else
Input = InputBox("To install or uninstall this script, click CANCEL now. ====&gt;&gt;" &_
vbNewline & vbNewline & vbNewline &_
"To search Google.com, inter the search string below and click OK.",_
"Google Search Script")

If Input = "" Then
Check
End If
End If
Set Goo = WScript.CreateObject("InternetExplorer.Application")
Goo.navigate "http://www.google.com/"
Goo.visible = 1
Do While (Goo.Busy)
WScript.Sleep 200
Loop
Goo.document.f.q.value = Input
Goo.document.f.submit()
Do While (Goo.Busy)
WScript.Sleep 200
Loop

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Google Search: " + Input

Set WshShell = Nothing
Set objArgs = Nothing
Set Goo = Nothing

Function Check()
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
RegKey = "HKCU\Software\Microsoft\" &_
"Internet Explorer\MenuExt\&Google Search\"
WshShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\MenuExt\&Google Search\")
If Err.number &lt;&gt; 0 Then
Err.Clear
On Error GoTo 0

MyVar = MsgBox ("DO YOU WANT TO INSTALL THIS SCRIPT?", 68, "INSTALL")
If MyVar = 6 Then
Setup 0
MyVar = MsgBox ("INSTALLED" & Vbnewline & Vbnewline &_
"TO UNINSTALL, DOUBLE-CLICK THIS SCRIPT!", 64, "INSTALLED")
Title = "Send To X as Shortcut"
Usage = "USAGE:" & vbcrlf & " Right click on file(s) or folder(s)" & vbcrlf & _
" Click " & chr(34) & "Send To" & chr(34) & vbCrlf & _
" Click " & chr(34) & "Google Search" & _
chr(34) & vbcrlf & " Select Target Folder"
Sel = MsgBox("THIS UTILITY CAN NOT BE RUN DIRECTLY." & vbcrlf & vbcrlf & _
Usage & vbcrlf & vbcrlf & _
"DO YOU WANT TO UNINSTALL " & Title & "?",64 + 256, Title)

Wscript.quit
Else
Wscript.quit
End If
Else
MyVar2 = MsgBox ("DO YOU WANT TO UNINSTALL THIS SCRIPT?" ,_
68, "UNINSTALL")
If MyVar2 = 6 Then
Setup 1
wscript.echo "UNINSTALLED"
Wscript.quit
Else
MyVar = MsgBox ("TO UNINSTALL LATER, DOUBLE-CLICK THIS SCRIPT!",_
64, "UNINSTALL THIS SCRIPT")
Wscript.quit
End If
End If
Set WshShell = Nothing

End Function

Function Setup(s)
Err.Clear
On Error goto 0
Set oFSo = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
ProgFolder = WshShell.Environment("Process")("windir")
InstalDrive = ProgFolder
If InStr(InstalDrive, "\") &gt; 0 then
myarray = Split(InstalDrive, "\")
InstalDrive = myarray(LBound(myarray))
End If
InstalFolder = InstalDrive & "\SearchScript"
If s = 0 Then
Set oFoldr = oFSo.CreateFolder(InstalFolder)
Set hf = oFSo.OpenTextFile(InstalFolder & "\Google Search.html", 2, True)
hf.WriteLine "&lt;SCRIPT LANGUAGE=" & chr(34) & "JavaScript" & chr(34) & " defer&gt;"
hf.WriteLine " var parentwin = external.menuArguments;"
hf.WriteLine " var doc = parentwin.document;"
hf.WriteLine " var sel = doc.selection;"
hf.WriteLine " var rng = sel.createRange();"
hf.WriteLine " var str = new String(rng.text);"
hf.WriteLine " if(str.length == 0)"
hf.WriteLine " rng.text =" & chr(34) & " " & chr(34) & ";"
hf.WriteLine " else"
sPath = InstalDrive & "/SearchScript/GoogleSearch.vbs"
hf.WriteLine "var WshShell = new ActiveXObject(" & chr(34) &_
"WScript.Shell" & chr(34) & ");"
hf.WriteLine "WshShell.Run(" & chr(34) & sPath & chr(34) &_
" + " & chr(34) & " " & chr(34) & " + rng.text, 1, true);"
hf.WriteLine "&lt;/SCRIPT&gt;"
hf.Close
Set vf = oFSo.OpenTextFile(InstalFolder &_
"\GoogleSearch.vbs", 2, True)
Set ts = oFSo.OpenTextFile(WScript.ScriptFullName, 1)
Script = ts.ReadAll
vf.WriteLine Script
vf.Close
ScriptPath = "file://" & InstalFolder & "\Google Search.html"
WshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\" &_
"MenuExt\&Google Search\", ScriptPath, "REG_SZ"
WshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\" &_
"MenuExt\&Google Search\Contexts", 16, "REG_DWORD"

Shrtcut = WshShell.SpecialFolders("SendTo") & "\Google Search.lnk"
With WshShell.CreateShortcut(Shrtcut)
.TargetPath = InstalFolder & "\GoogleSearch.vbs"
.IconLocation = "explorer.exe, 7"
.Save
End With
Set oFSo = Nothing
Set WshShell = Nothing
Set hf = Nothing
Set vf = Nothing
Set ts = Nothing


Else

' Uninstall the script.
Set hf = oFSO.GetFile(InstalFolder & "\Google Search.html")
hf.delete
Set vf = oFSO.GetFile(InstalFolder & "\GoogleSearch.vbs")
vf.delete
Set iFoldr = oFSO.GetFolder(InstalFolder)
iFoldr.delete
WshShell.RegDelete "HKCU\Software\Microsoft\Internet Explorer" &_
"\MenuExt\&Google Search\"
Set sf = oFSO.GetFile(WshShell.SpecialFolders("SendTo") &_
"\Google Search.lnk")
sf.delete
Set sf = Nothing
Set hf = Nothing
Set vf = Nothing
Set ts = Nothing
Set iFoldr = Nothing
End If

End Function



‘==================== Script eNd =====================

this is a Hotmail log-in script. It will open a new IE window, go to Hotmail and log you in.
replace the user name and password with yours.

No installations requ

‘================= Hotmail login.vbs ==================

UserName = "JoeNextDoor"
PassWord = "MySecretPassword"

Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "http://www.hotmail.com"
oIE.visible = 1

' Important: wait till MSIE Is ready
Do While (oIE.Busy)
WScript.Sleep 200
Loop
oIE.document.passwordform.login.value = UserName
oIE.document.passwordform.passwd.value = PassWord
oIE.document.passwordform.submit()
Set oIE = Nothing
wscript.quit

‘=================== Script eNd ======================

Same as Hotmail’s script, but logs you in Yahoo’s service instead.

‘================= Yahoo login.vbs ==================


UserName = "JoeNextDoor"
PassWord = "MySecretPassword"


Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "http://mail.yahoo.com/?.intl=us"
oIE.visible = 1

' Important: wait till MSIE Is ready
Do While (oIE.Busy)
WScript.Sleep 200
Loop


oIE.Document.login_form.login.value = UserName
oIE.Document.login_form.passwd.value = PassWord
WScript.Sleep 2000
oIE.Document.login_form.submit(_
oIE.Document.script.hash(oIE.Document.login_form,"'http://login.yahoo.com/config/login'"))
Set oIE = Nothing
wscript.quit

‘=================== Script eNd ======================

I have a couple more; I’ll share them once I finish polishing them!


Jama

Jama
06-27-2002, 07:33 PM
BUG: Unknown error messages when installing Google Search script. (O319947)

The information in this article applies to:

Google Search script.

SYMPTOMS

By default, when you first install the script, you might receive a message box titled; "Send To X as Shortcut".
The message states; "THIS UTILITY CAN NOT BE RUN DIRECTLY".


CAUSE

This message came from another script and somehow found its way to this script.
MickySoft is currently investigating this matter and would like to assure our customers that we will terminate the employee responsible for this blunder “As soon as we find him!”
We also like to stress that the message is incorrect and you can indeed run the script directly!


RESOLUTION

This feature is under review and will be considered for inclusion in a future update.
Joke!

To fix this problem, open the script in Notepad, click Edit on the menu, or click Control + F. type “Title” without quotes and hit enter.
Once you locate this line;

Title = "Send To X as Shortcut"

Delete it as well as the next seven lines. That’s line 56 through to line 63.

If you have difficulties counting, then delete up to & including this line;
"DO YOU WANT TO UNINSTALL " & Title & "?",64 + 256, Title)


STATUS

MickySoft has confirmed this to be a bug in the MickySoft products listed at the beginning of this article.

MORE INFORMATION

This issue has been corrected in MickySoft Winkows 2000 and MickySoft Winkows Xb.

BG

Nana
06-28-2002, 10:25 PM
Excellent!

Nana /images/forums/icons/laugh.gif