I'm usually prefering not to use CMD-Commands out of VBS if not necessary (there are many areas where it's really handy, but a ping is not one of them).
You can also use WMI to ping the machine - works fast and you don't have to text-analyze the output of the ping-command. I've just dug out an example for you at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/ wmi_tasks__networking.asp - look at the last example. Gruesse - Sincerely, Ulf B. Simon-Weidner Profile & Publications: http://mvp.support.microsoft.com/profile=35E388DE-4885-4308-B489-F2F1214C811 D Weblog: http://msmvps.org/UlfBSimonWeidner Website: http://www.windowsserverfaq.org >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] On Behalf Of >Bernier, Brandon (.) >Sent: Thursday, May 25, 2006 6:59 PM >To: [email protected] >Subject: RE: [ActiveDir] OT help with VBS/WMI Script > > >If your concerned about the server being up, incorporate this >into your script. It will ping the box and execute your logic >if its up. This is just an example, it wouldn't actually work >if you cut and paste it. > > >Set objShell = CreateObject("WScript.Shell") > >For Each strServerName in colServerList > Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & >servername) > strPingResults = LCase(objScriptExec.StdOut.ReadAll) > If InStr(strPingResults, "reply from") Then > Put your OS version WMI code here, call >a function preferably. > Else > Wscript.Echo "Error:" & >Err.Description (something like this) > > End if >Next > >Set objShell = Nothing > >-Brandon > >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] On Behalf Of Hutchins, Mike >Sent: Thursday, May 25, 2006 12:46 PM >To: [email protected] >Subject: RE: [ActiveDir] OT help with VBS/WMI Script > >If I use this, everything gets "Server1++" nothing ever gets anywhere. >:-) > >-----Original Message----- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] On Behalf Of Timo Ed >Sent: Wednesday, May 24, 2006 4:22 PM >To: [email protected] >Subject: Re: [ActiveDir] OT help with VBS/WMI Script > >'========================================= >For Each strComputer In serverList > Set colSettings = "" > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & strComputer & >"\root\cimv2") > Set colSettings = objWMIService.ExecQuery _ > ("Select * from Win32_OperatingSystem") > > If err then > WScript.Echo strComputer + "++" > else > Set colSettings = objWMIService.ExecQuery _ > ("Select * from Win32_OperatingSystem") > For Each OS In colSettings' > WScript.Echo strComputer + "+" + OS.Caption + "+" + >OS.Version > Next > end if >Next >'========================================= > >Rgds, >Tim > > >On 5/25/06, Hutchins, Mike <[EMAIL PROTECTED]> wrote: >> So I am trying to get some information from a gigantic list of >machines. >> Problem is that if the machine isn't up, the script retains the >> previous values. Example >> >> server1+Microsoft(R) Windows(R) Server 2003, Enterprise >> server1+Edition+5.2.3790 >> server2+Microsoft(R) Windows(R) Server 2003, Enterprise >> server2+Edition+5.2.3790 >> >> In this example Server1 is Accurate (the "+" is a delimiter) >> Server2 is not online so the script retained the OS.Caption and >> OS.Version part. I would rather it be blank like; >> >> server2++ >> >> Here is the script part that this lies in. Any suggestions greatly >> appreciated. >> >> For Each strComputer In serverList >> Set colSettings = "" >> Set objWMIService = GetObject("winmgmts:" _ >> & "{impersonationLevel=impersonate}!\\" & strComputer & >> "\root\cimv2") >> Set colSettings = objWMIService.ExecQuery _ >> ("Select * from Win32_OperatingSystem") >> For Each OS In colSettings >> WScript.Echo strComputer + "+" + OS.Caption + "+" + OS.Version >> Next >> Next >List info : http://www.activedir.org/List.aspx >List FAQ : http://www.activedir.org/ListFAQ.aspx >List archive: >http://www.mail-archive.com/activedir%40mail.activedir.org/ > >List info : http://www.activedir.org/List.aspx >List FAQ : http://www.activedir.org/ListFAQ.aspx >List archive: http://www.activedir.org/ml/threads.aspx > > >List info : http://www.activedir.org/List.aspx >List FAQ : http://www.activedir.org/ListFAQ.aspx >List archive: http://www.activedir.org/ml/threads.aspx List info : http://www.activedir.org/List.aspx List FAQ : http://www.activedir.org/ListFAQ.aspx List archive: http://www.activedir.org/ml/threads.aspx
