Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 14th, 2003, 01:11 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default strcomputer value inserted from WinBatch File

I am trying to take a .txt file populated with servers and
populate a .vbs script with these names. For some reason it
is always reporting my local computer. I know the "." value
is for my local computer, but everything I put in (ie %1)
comes back with a syntax error. Is there an easier way
of doing this?

          Thanks for your help! Tom
Reply With Quote
  #2 (permalink)  
Old October 14th, 2003, 01:13 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, I am invoking the script with a batch file. Example below:
The Problem:

Using a batch file to invoke a .VB script I use the %1 variable and insert the computer name from a text file. My VB script keeps on assuming I am running on the local machine. The script works fine with hardcoded servernames, but I can't seem to find a way of inserting the remote machine variable.

Batch File text=

for /f %%a in (client.txt) do call :sub %%a
goto :eof

:sub
echo %1 >> c:\sms\verification\smsresults.txt
cscript //nologo smsclientcheck1.vbs %1 >> c:\sms\verification\smsresults.txt

goto :eof

VB Script text=

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'clisvcl.exe'")
If colProcesses.Count = 1 Then
    Wscript.Echo "SMS Client is running."
Else
    Wscript.Echo "SMS Client is not running."
End If


Reply With Quote
  #3 (permalink)  
Old October 15th, 2003, 02:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Why don't you just use the FileSystemObject to read client.txt directly from your VBS?
Reply With Quote
  #4 (permalink)  
Old October 15th, 2003, 10:40 AM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much! Somebody wouldn't happen to have a sample of this in operation?

Reply With Quote
  #5 (permalink)  
Old October 17th, 2003, 04:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try this (assuming client.txt contains each server name on a separate line and nothing else)
Code:
Option Explicit
Dim fso, ts, strComputer, colProcesses
Const ForReading = 1
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
' CHANGE THE PATH ON THE NEXT LINE
Set ts = fso.OpenTextFile("path to client.txt", ForReading) 

Do While Not ts.AtEndOfStream 
  strComputer = Trim(ts.ReadLine)
  Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'clisvcl.exe'")
  If colProcesses.Count = 1 Then
    Wscript.Echo "SMS Client is running on " & strComputer
  Else
    Wscript.Echo "SMS Client is not running on " & strComputer
  End If
Loop

ts.Close
Set ts = Nothing
Set fso = Nothing
Reply With Quote
  #6 (permalink)  
Old October 21st, 2003, 02:12 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Again, thank you so much for the help! Unfortunately the script has issues on a line of the script.

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\SMS\Verification\smsclientcheck2.vbs(23, 3) Microsoft VBScript runtime error: Variable is undefined: 'objWMIService'

Exit code: 0 , 0000h

This is the line it is referencing. I have tried some different things to no avail. Any help is again appreciated! Thanks, Tom

 Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Reply With Quote
  #7 (permalink)  
Old October 23rd, 2003, 03:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Its because the script has "Option Explicit" at the start, you are forced to declare all variables. Just add objWMIService to the list of declared variables (that's the Dim statement on line 2).
Reply With Quote
  #8 (permalink)  
Old October 28th, 2003, 03:22 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you pgtips for all your help!!!

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Edit record right after it was Inserted? aladov ASP.NET 2.0 Professional 4 December 11th, 2007 03:18 PM
How to get last inserted record in a table?? dayaananthanm SQL Server 2005 6 June 11th, 2007 09:15 PM
Inserted Identities hossrad SQL Server 2005 1 May 21st, 2007 09:48 AM
Record is Inserted Twice donevco Access 1 February 27th, 2007 12:28 PM
How can I get the last inserted rows? fraijo SQL Server 2000 4 November 23rd, 2006 07:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.