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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question Do While Statements

Status
Not open for further replies.

boostaz1

Programmer
Aug 26, 2003
7
0
0
US
Why can't I run a do while statement from within a function?
Example:
Function pse()
objExplorer.Document.Body.All.IPAddress.setfocus
Do While objExplorer.Document.Body.All.scan.value = "Scan"
wscript.sleep 1000
Loop
End Function
 
Why are you saying you can't loop inside a function ?
You get error message ?
Have you displayed the value of the test variable before entering the loop ?

Hope This Help
PH.
 
My script just exits and never continues on. If i remove the do while from the function it works fine.... here is the full script:
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005

On Error Resume Next
'===================
'| Create IE Object
'===================

Set objCDO = wscript.CreateObject("CDO.Message")
Set objExplorer = WScript.CreateObject("InternetExplorer.Application", "IE_")
objExplorer.Navigate " objExplorer.Visible = 1
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=600
objExplorer.Height = 600
objExplorer.Left = 0
objExplorer.Top = 0
Wscript.Sleep 500
Call Updatestatus(now())
Call pse()
Function pse()
objExplorer.Document.Body.All.IPAddress.setfocus
Do While objExplorer.Document.Body.All.scan.value = "Scan"
wscript.sleep 1000
Loop
End Function
Call loader()

Function loader()
If Len(objExplorer.Document.Body.All.IPAddress.value) > 8 Then
sComputer = objExplorer.Document.Body.All.IPAddress.value
Else
sComputer = inputbox("Enter IP To scan")
End If
Call Updatestatus(vbCrlf & "Scanning: " & sComputer)
Call checkos(sComputer)
End Function

Function Checkos(ipaddress)

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}\\" & IPAddress & "\root\cimv2")

Set colSystem=objWMIService.ExecQuery ("Select * from Win32_operatingsystem")
For Each objSystem In colSystem
scaption = objSystem.caption
Next
Call Updatestatus("Found " & scaption)
Call Checkpatch(ipaddress, scaption)
End Function

Function Checkpatch(sComputer, os)
sMethod = "EnumKey"
hTree = HKEY_LOCAL_MACHINE
sKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\hotfix"
srckey = "KB824146" 'Inputbox("Enter Hot Fix ID")
Call Updatestatus("Checking for patch " & srckey)
Dim hFixes
Dim objWMIService, objSystem
Dim ColSystem

Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" & sComputer & "/root/default:StdRegProv")

Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)

For i=0 To UBound(oOutParam.Properties_("sNames"))
If instr(oOutParam.Properties_("sNames")(i), srckey) Then
fnd = True
i=UBound(oOutParam.Properties_("sNames"))
End If
Next
If FND = False Then
Call updatestatus("Applying patch")
sMethod = "SetStringValue"
hTree = HKEY_LOCAL_MACHINE
sKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
sValueName = "MS03039"
Select Case lcase(os)
Case lcase("Microsoft Windows 2000 Professional")
sValue = "\\mesafps01\pccommon\patches\MS03-039\Windows2000-KB824146-x86-ENU.exe -q"
Case lcase("Microsoft Windows XP Professional")
sValue = "\\mesafps01\pccommon\patches\MS03-039\WindowsXP-KB824146-x86-ENU.exe -q"
Case lcase("Microsoft Windows NT Workstation")
sValue = "\\mesafps01\pccommon\patches\MS03-039\WindowsNT4Workstation-KB824146-x86-ENU.EXE -q"
Case Else
sValue = inputbox("Enter patch to run:")
End Select

Call updatestatus("Applying patch " & sValueName)
Call updatestatus("Installing From " & sValue)

Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()
oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = sValueName
oInParam.sValue = sValue

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
Call updatestatus("Sending Notification to " & sComputer)
Call ExternalApp("net send " & scomputer & " Information Systems ask that you reboot your pc to apply new security patch for windows. This patch was just applied to your system. Questions please call 480.722.4736", 1 ,1)
Call updatestatus("Registery key edited.")
Else
Call updatestatus("update not required")
End If
Call closer()
End Function

Function closer()
checkclose = msgbox("Do you wish to scan another system?", vbYesno)
If checkclose = vbyes Then
objExplorer.Document.Body.All.scan.value = "Scan"
Else
wscript.sleep 3000
If objExplorer.Document.Body.All.wclose.checked Then
objExplorer.quit
End If
End If

End Function

Function Updatestatus(comments)
objExplorer.Document.Body.All.webpage.Value = objExplorer.Document.Body.All.webpage.Value & comments & vbCrlf
End Function

Function ExternalApp(appname, var1, var2)
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run appname, var1, var2
End Function
 
And what happens if you remove the On Error Resume Next ?
And what is displayed if you change your function like this ?
Code:
Function pse()
objExplorer.Document.Body.All.IPAddress.setfocus
Wscript.Echo objExplorer.Document.Body.All.scan.value
Do While objExplorer.Document.Body.All.scan.value="Scan"
  wscript.sleep 1000
Loop 
End Function


Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top