Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


help with this script

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> help with this script
  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 >>
 help with this script - 5/29/2006 1:12:41 AM   
  avipenina

 

Posts: 102
Score: 0
Joined: 4/24/2006
Status: offline
Hi,

i've this script

On Error Resume Next
Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName
strComputer = Wscript.Arguments.Item(0)
If strComputer = "" then
Wscript.echo "You didn't specified any machine to connect to..."
   Wscript.quit
End If
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'application' AND " _
& "EventCode = '0'")
For each objEvent in colLoggedEvents
Wscript.echo "Computer: " & objEvent.ComputerName & _
vbnewline & _
"Time : " & objEvent.TimeWritten & _
vbnewline & _
"Event ID: " & objEvent.EventCode & _
vbnewline & _
vbnewline & _
"Description: " & objEvent.Message & _
vbnewline & _
"Source: " & objEvent.SourceName & _
vbnewline & _
"Type: " & objEvent.Type & _
vbnewline & _
"User: " & objEvent.User & _
vbnewline
next
wscript.echo "Can't connect to the specified machine"


this script needs Argument like machine name to show this info only local machine name work it's ok.
my problem is that i use this line "On Error Resume Next" now under the next i've this line "wscript.echo "Can't connect to the specified machine""
i put this line if the user put wrong machine name or there is an error that will go to this line, the problem is even if the script work it show this line "Can't connect to the specified machine"
in the end of the script WHY?
and how i resolved that will show the error only if the machine name is incorrect?

Thanks
 
 
Post #: 1
 
 RE: help with this script - 5/29/2006 7:06:14 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
Ideally, you want to be doing some sort of error checking so that you don't NEED to use On Error Resume Next.  In this case you would be best checking that the machine exists in Active Directory first.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to avipenina)
 
 
Post #: 2
 
 
 
  

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 >> help with this script 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