View Full Version : windows script (All)
racerrunner
06-22-2006, 03:15 AM
is it possible to write a script to automate task?
I.E
1.Starts Application,
2.Click on combox,
3.enter date in(dd/mm/yyyy) in a textbox and
4.click on the command button?
Thanks
josefz
06-23-2006, 12:37 AM
ad 1: Search MSDN for <a target="_blank" href=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/4b032417-ebda-4d30-88a4-2b56c24affdd.asp> "Run Method"</a>
E.G.
private objShell
Set objShell=wscript.createobject ("wscript.shell")
objShell.run ("msimn.exe")
Success = objShell.AppActivate("Notepad")
Do Until Success = True
Success = objShell.appactivate ("msimn.exe")
Wscript.Sleep 1000
Loop
ad 2..4: <a target="_blank" href=http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_hilv.mspx?mfr=true> Sending Keystrokes to a Program</a>
E.G.
objShell.sendkeys"{home}"
wscript.sleep 300
racerrunner
06-29-2006, 06:41 PM
Thank You josefz.
I manage to come up with this code
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "vantiv32.exe"
Do Until Success = True
Success = objShell.AppActivate("vantiv32.exe")
Wscript.Sleep 1000
Loop
after I execute it, the PeopleSoft CRM System Login screen pop out(ask me for password)
Since normally, i would enter the password, follows by a "tab" and "Enter" keys to log onto the system. Therefore, I added another piece of code into the script
objShell.sendkeys"p"
objShell.sendkeys"a"
objShell.sendkeys"s"
objShell.sendkeys"s"
objShell.sendkeys"w"
objShell.sendkeys"o"
objShell.sendkeys"r"
objShell.sendkeys"d"
objShell.sendkeys"{TAB}"
objShell.SendKeys "{ENTER}"
For instance, my password is "password". However, it couldnt work. I mean the PeopleSoft CRM System Login screen stays where it was, waiting for me to enter the password by hand. Can anyone please advise. Thank you. <P ID="edit"><FONT class="small">Edited by racerrunner on 06/29/06 18:07.</FONT></P>
josefz
06-30-2006, 12:35 AM
Put the next line
wscript.sleep 100
behind each line with objShell.sendkeys (You can try another delay period than 100).
There was a mistake in my previous advice (the line with notepad). You have fathomed it - good job!
racerrunner
06-30-2006, 02:27 AM
Thank you josefz.
When you say Put the next line
wscript.sleep 100
I suppose it is:
objShell.sendkeys"p"
wscript.sleep 100
objShell.sendkeys"a"
wscript.sleep 100
objShell.sendkeys"s"
wscript.sleep 100
etc...
but it cannot work. Therefore, does that mean sendkey cannot work on vantives?
Thank You
josefz
06-30-2006, 04:33 AM
Another mistake. Mea culpa, mea maxima culpa.
We must use the AppActivate method to set the focus on an application, to bring the specified window to the foreground so that you can then start using the WshShell SendKeys method to send keystrokes to the application.
The AppActivate method takes a single parameter that can be either a string containing the title of the application as it appears in the title bar or the process ID of the application.
So, there in the objShell.AppActivate("vantiv32.exe") entry should be another notation used instead of "vantiv32.exe". Use the window name instead of the executable filename.
HTH.
Yeah.... so suppose the vantiv32.exe application pops up a window with the title "Logon to Vantive", then your appactivate should look like this:
objShell.AppActivate("Logon to Vantive")
josefz
07-01-2006, 10:34 AM
IMHO you are right.
' Next script runs new instance of notepad whenever it is launched
private objShell
Set objShell = wscript.createobject ("wscript.shell")
retrun = objShell.run ("notepad.exe")
' Next script does not run new instance of notepad, but activates running one instead
private objShell
Set objShell = wscript.createobject ("wscript.shell")
Success = objShell.AppActivate("Untitled - notepad")
If Success Then
retrun = -1
Else
retrun = objShell.run ("notepad.exe")
End If
WScript.Echo "retrun = " & retrun
Although SendKeys can be used effectively, there are several potential problems with this approach:
• The script might have difficulty determining which window to send the keystrokes to.
• Because the application runs in GUI mode, a user might close the application prematurely. Unfortunately, this will not terminate the script, and the script could end up sending keystrokes to the wrong application.
• The script might have difficulty synchronizing with the application.
Let try use ProcessID Property to determine it in better manner, like in next example script:
'[VBScript]
Sub delayedSendKeys(str)
WScript.Sleep 100
WshShell.SendKeys str
End Sub
Dim WshShell, oCalc, oNotepad
Set WshShell = CreateObject("WScript.Shell")
Set oCalc = WshShell.Exec("calc")
Set oNotepad = WshShell.Exec("notepad")
WScript.Sleep 500
WshShell.AppActivate oCalc.ProcessID
delayedSendKeys "1{+}1~"
delayedSendKeys "^C"
delayedSendKeys "%{F4}"
WshShell.AppActivate oNotepad.ProcessID
delayedSendKeys "1 {+} 1 = ^V"
Notice WshShell.AppActivate arguments in this case: oCalc.ProcessID and oNotepad.ProcessID
There we could effectively test the existence of right application before sending keys to it!
racerrunner
07-03-2006, 06:12 PM
Thank You josefz and Brf for your kind reply.
I've a number of questions for both of you.
1. Is it possible to log mouse click? My answer is No.
2. What happen if I want to start the vantive exe manually, I only want the script to perform until I arrive to a form calls “New Entry”. Is that possible?
If it is possible, then suppose I want the script to execute once for every 1 hr interval(automatically) in this form. Can that be done?
Please assist if possible. Thank You.
<P ID="edit"><FONT class="small"><EM>Edited by racerrunner on 07/03/06 18:03.</EM></FONT></P><P ID="edit"><FONT class="small"><EM>Edited by racerrunner on 07/03/06 18:16.</EM></FONT></P><P ID="edit"><FONT class="small">Edited by racerrunner on 07/03/06 19:26.</FONT></P>
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.