Jerry Yeo
Jerry Yeo

Reputation: 1

VBscript - anyone can help to check what wrong with my script below

Dim Nagios
Nagios = http://gl-nagios.fciconnect.com/centreon/index.php
set WshShell = WScript.CreateObject("WScript.Shell")
call WshShell.Run(nagios, 1, false)

WScript.Sleep 2000
WshShell.SendKeys ""
WScript.Sleep 1000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys ""
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 5000
'Browse to DownHost
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WScript.Sleep 2000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 5000
WshShell.SendKeys "{PRTSC}"
WScript.Sleep 5000
WshShell.AppActivate"C:\AutoScreenCapture\IECapt --url="nagios" --out=C:\AutoScreenCapture\Warning.jpg"
WScript.Quit

I intend to use vbscript to login to website and do screenshot on its active webpage and also using IEcapt freeware to capture its screenshot. Not sure where do I go wrong with the script. Any experts advise.

Upvotes: 0

Views: 74

Answers (1)

joehanna
joehanna

Reputation: 1489

You have several issues, but before I get to them, let me declare that I am unfamiliar with IECapt and how it works.

First, as @bond stated, you need to enclose the Nagios assignment in quotes:-

Nagios = "http://gl-nagios.fciconnect.com/centreon/index.php"

Second, AppActivate simply switches to another already-running application window. It looks like you need to run the application with a command line to export the image from the clipboard (you can't switch to an app and apply arguments). Therefore, I suggest you remove the call to Run from line 4 and change the AppActivate call to the Run method so you can start it up with arguments. Again, not exactly sure how the app works so this may need review.

Third, you have a problem with your string concatenation to insert the url. You need to use the concatenation operator &. To maintain good convention, try to use variable names with the same case as you declared them, in this instance, Nagios:

'Start up the screen-capture app and minimise it
WshShell.Run "C:\AutoScreenCapture\IECapt --url=" & Nagios & " --out=C:\AutoScreenCapture\Warning.jpg", 2

Fourth, I always recommend declaring every variable to avoid runtime bugs and errors. Therefore, you should always make line 1 of your VBScript files this:-

Option Explicit  'Enforce variable declaration

Fifth, you haven't declared a variable for WshShell:

Dim WshShell

Finally, you should always release memory for variables that you Set:

  Set WshShell = Nothing
  Set Nagios = Nothing

Upvotes: 0

Related Questions