Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


function will only run once then bombs out :(

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1177
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> function will only run once then bombs out :(
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 function will only run once then bombs out :( - 7/24/2004 7:28:13 PM   
  mikejc

 

Posts: 1
Score: 0
Joined: 7/24/2004
From:
Status: offline
Thanks in advance for any help/suggestions...

I wrote a pretty basic function to check how many times a specific process is running on a machine. It passes the host name to a local variable called strComputerName.

Inside the function is a locally set variable called objWMIService. The first time this line is run it works fine, but any additional times it will error out if i pass a different host to it. I can re-run it many times if I never change what is set to objWMIService.

I included the output after the code...
please note if you try to run the code to reproduce, make sure u replace the ip addresses with ones valid for your network

---

dim strComputer(2)

for x = 1 to 2

strComputer(x)="192.168.0.10" & x

ProcessChecker(strComputer(x))

next


function ProcessChecker(strComputerName)
set objWMIService = nothing
msgbox strComputerName
set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE Name = 'svchost.exe' ")

wscript.echo "svchost.exe is running " & colProcesses.Count & " times on " & strComputerName & "."

end function

---

The output will look like this for run through 1:

popup 1: 192.168.0.101
(used for tracing the error to make sure the host name gets passed through)


popup 2: 'svchost is running on 192.168.0.101 5 times."


Now the second time:

popup 1: 192.168.0.102
the second hostname still passes through fine...once again this is here for testing

popup 2: Line 16
Char 1
Error 0x8004100A
Code 8004100A
Source Null


----
 
 
Post #: 1
 
 Re: function will only run once then bombs out :( - 7/26/2004 8:56:45 AM   
  jbird

 

Posts: 33
Score: 0
Joined: 6/25/2004
From: USA
Status: offline
I have two questions:
Is the first machine your local machine?
Are the machines set to allow remote scripts?

(in reply to mikejc)
 
 
Post #: 2
 
 Re: function will only run once then bombs out :( - 7/27/2004 12:30:03 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Are all PC's WinXP/2000? If I am not mistaken, svchost is not present on NT4.
Also, try wrapping line 16 in an on error resume next and if there is an error display the description.

(in reply to mikejc)
 
 
Post #: 3
 
 Re: function will only run once then bombs out :( - 7/28/2004 7:53:13 AM   
  rhcsgcsc

 

Posts: 4
Score: 0
Joined: 7/28/2004
From:
Status: offline
your problem is in these two lines:

dim strComputer(2)
for x = 1 to 2

you are only allowing for an arry of two items...

strComputer(0)
strComputer(1)

for a total of two array items.

When you try to call strComputer(1), it is able to refernce the array index. Whey you try to call strComputer(2), you are calling an index that is out of your arrays range.

Try using a larger arry size. This will fix your problem.

(in reply to mikejc)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> function will only run once then bombs out :( Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts