troubleshooting Question

My VBscript goes Crazy, please help!!!!

Avatar of Lico_w
Lico_w asked on
ProgrammingVisual Basic ClassicVB Script
13 Comments1 Solution527 ViewsLast Modified:
I created the script below which simply runs a bat file to check an application is listening on a port. When the application is listening it works fine. However if the app isn't then the script goes a little crazy and opens loads of Windows.

It appears to be that the bat file it runs does not close via the sendkeys commands, and then it opens another dos window. This seems to cycle round about 30 times. Can anyone suggest what I could do to resolve this issue please? This is the final piece to a project so I would like to get completed asap.
checkSemaphor()

newLog = 1
for i = 1 to 10
	monitorSS(newLog)
	newLog = newLog + 1
next
checkLogs()
'wscript.echo "Script has completed"

Function checkSemaphor()
	'semFile = "D:\User-Applications\batch_processes\MonitorSorenson\semaphor\semaphor.txt"
	semFile = "C:\Documents and Settings\t104ahe\Desktop\monitor SS\semaphor\semaphor.txt"
	set fsObj = CreateObject("Scripting.FileSystemObject")
	if fsObj.FileExists(semFile) then
		wscript.quit
	end if
End Function

Function monitorSS(logNo)
	sCmd = "monitorSS.bat "
	Set oShell = CreateObject("WSCript.shell") 

	oShell.Run sCmd & logNo, 7
	WScript.Sleep 1000
	oShell.AppActivate "Telnet 10.210.136.218"
	oShell.SendKeys("^]")
	WScript.Sleep 1000
	oShell.AppActivate "Telnet 10.210.136.218"
	oShell.SendKeys("quit{ENTER}")
	WScript.Sleep 1000

	set oShell = nothing
End Function

Function checkLogs()
	'logDir = "D:\User-Applications\batch_processes\MonitorSorenson\logs"
	logDir = "C:\Documents and Settings\t104ahe\Desktop\monitor SS\logs"
	failures = 0
	set fso = CreateObject("Scripting.FileSystemObject")
	Set objFolder = fso.GetFolder(logDir)
	Set objFiles = objFolder.Files
	for each objFile in objFiles
		if objFile.Size < 1 then
			failures = failures + 1
			wscript.echo "File is smaller than 1000 bytes"		
		end if
		if failures > 9 then
			sendEmail()
		end if
	next
	set fso = nothing
	Set objFolder = nothing
	Set objFiles = nothing
End Function

Function sendEmail()
	'email details removed for online posting
	writeSemaphor()
End Function

Function writeSemaphor()
	'semDir = "D:\User-Applications\batch_processes\MonitorSorenson\semaphor\"
	semDir = "C:\Documents and Settings\t104ahe\Desktop\monitor SS\semaphor\"
	set semFso = CreateObject("Scripting.FileSystemObject")
	set semFile = semFso.CreateTextFile(semDir & "semaphor.txt", True)
	semFile.WriteLine("Email alert has been sent to CSI Internet team")
	set semFso = nothing
	set semFile = nothing
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 13 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros