Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


newb syntax problem

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> newb syntax problem
  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 >>
 newb syntax problem - 6/24/2008 4:35:48 AM   
  o2flow

 

Posts: 7
Score: 0
Joined: 1/24/2008
Status: offline
Hey all -

I've been staring at this for a while and can't seem to figure out why there is a problem with line 54. Keeps returning a syntax error. It's a small script to determine WMI status and the local accounts on each machine. Help?


      
 
 
Post #: 1
 
 RE: newb syntax problem - 6/24/2008 4:49:43 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi o2flow,

there are 2 "For Each" and only 1 "Next" in your script. If you use proper indention,
you'll sure find the line to add the missing "Next".

Good luck!

ehvbs

(in reply to o2flow)
 
 
Post #: 2
 
 RE: newb syntax problem - 6/24/2008 4:54:00 AM   
  o2flow

 

Posts: 7
Score: 0
Joined: 1/24/2008
Status: offline
quote:

Hi o2flow,

there are 2 "For Each" and only 1 "Next" in your script. If you use proper indention,
you'll sure find the line to add the missing "Next".

Good luck!

ehvbs


hmm well when I originally placed one here:


      

I get an unexpected 'Next' error. This is the reasoning behind me using an 'Exit For' in my original post. I think I am missing some of the understanding behind For Each

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: newb syntax problem - 6/24/2008 5:05:53 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
Here is your code properly indented. My comments are in red


Option Explicit
Set WshShell = CreateObject("WScript.Shell")
Set colComputers = GetObject("LDAP://OU=Civic, DC=Honda, DC=win")
For Each objComputer in colComputers
strComputer = objComputer.CN
Wscript.Echo strComputer
Wscript.Echo "------------"
If CheckConnection(strComputer) = True Then  This If has no matching End If
   'WScript.Echo "connected " & strComputer
   'On Error Resume Next 
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   If Err.Number <> 0 Then
       Wscript.Echo "WMI not working on: " & strComputer
   End If
   On Error Goto 0
   On Error Resume Next
   Set colAccounts = objWMIService.ExecQuery _
   ("Select * From Win32_UserAccount Where LocalAccount = TRUE")
   If Err.Number <> 0 Then
       Wscript.Echo "Null value from user_acct: " & strComputer
   End If
   On Error Goto 0
   On Error Resume Next
   For Each objAccount in colAccounts
       If Left (objAccount.SID, 6) = "S-1-5-" and Right(objAccount.SID, 4) = "-500" Then
           Wscript.Echo objAccount.Name
           If Err.Number <> 0 Then
               Wscript.Echo "Null value from objacct: " & strComputer
           End If
           Exit For
           On Error Goto 0
       Else
           Wscript.Echo "no conn to " & strComputer
       End If  
       Wscript.Echo "____________"
   Next

'This function pings strComputer and returns a false if the ping was unsuccessful
Function CheckConnection(strComputer)
   PINGFlag = Not CBool(WshShell.run("ping -n 1 " & strComputer, 0, True))
   CheckConnection = PINGFlag
End Function

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to o2flow)
 
 
Post #: 4
 
 RE: newb syntax problem - 6/24/2008 5:33:52 AM   
  ehvbs

 

Posts: 2201
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ebgreen,

I think you missed this For Each:

Option Explicit
Set WshShell = CreateObject("WScript.Shell")
Set colComputers = GetObject("LDAP://OU=Civic, DC=Honda, DC=win")
For Each objComputer in colComputers

Hi o2flow,

I think you missed forgot an End If and your indentation is all over
the place (so you got what you derserve):

On Error Resume Next
      For Each objAccount in colAccounts
          If Left (objAccount.SID, 6) = "S-1-5-" and Right(objAccount.SID, 4) = "-500" Then
          Wscript.Echo objAccount.Name
          End If
      Next
          If Err.Number <> 0 Then
          Wscript.Echo "Null value from objacct: " & strComputer
          End If
     
      On Error Goto 0

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: newb syntax problem - 6/24/2008 5:55:33 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
Yup, I sure did miss it. And yes the indentation makes finding the problems very hard.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 6
 
 RE: newb syntax problem - 7/9/2008 3:16:18 AM   
  o2flow

 

Posts: 7
Score: 0
Joined: 1/24/2008
Status: offline
thanks guys, got it working. Any idea on how I would go about setting a variable equal to the objAccount.name? Right now in my output it would seem the value from


      

is carrying over to the next iteration...ie its not exactly working. I'd rather set a variable equal to the value contained inside objAccount.Name , display it, then reset it at each iteration.

Thoughts?

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: newb syntax problem - 7/9/2008 4:22:51 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
so something like:

For Each
   strName = objAccount.Name
   'Do things with strName
Next

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to o2flow)
 
 
Post #: 8
 
 RE: newb syntax problem - 7/9/2008 4:28:03 AM   
  o2flow

 

Posts: 7
Score: 0
Joined: 1/24/2008
Status: offline
yep, exactly

(in reply to ebgreen)
 
 
Post #: 9
 
 
 
  

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 >> newb syntax problem 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