Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

snufse2 (Programmer) (OP)
8 Nov 10 8:18
I currently have a vb script that is using MMC and retrieves events (Application, security etc) from my local desktop. The script is working fine.

Now, I need to connect to multiple servers and run the same script on each one (there will be a list if servers in either a table or text file). The script itself will reside in a central location only.

Is this possible and if so does someone have some links or code snippet that will help me get started? Thank you.
snufse2 (Programmer) (OP)
9 Nov 10 11:53
From my local desktop I need to connect to remote server and execute vb script that uses MMC and get events (application, security etc). For some reason it seems like the script on my local desktop does not execute the script on the remote server (which is a .BAT file calling a .VBS). If I call the .BAT file on the remote server directly it work fine.

............................................................
Script on local desktop:

dim strComputer, strCommand, objWMIService, objProcess, intProcessID
'strComputer = "."
strComputer = "vgiwpw03-sql3"
strCommand = "MMC Event Viewer Remote Server.bat"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
Wscript.Echo "MMC Event Viewer on remote server was started with a process ID: " & intProcessID
Else
Wscript.Echo "MMC Event Viewer on remote server could not be started due to error: " & errReturn
End If

This code should call a .bat file on the remote server. When I run the script I get that a process ID was created but it does not seem that the .BAT is calling the .VBS on th remote server:

............................................................
.BAT file on remote server - MMC Event Viewer Remote Server.bat

@ECHO OFF
cscript "MMC EVent Viewer Remote Server.vbs"

............................................................
Script file on remote server -MMC EVent Viewer Remote Server.vbs

Option Explicit
Dim Locator
Dim Service
Dim ManagementAgent
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Service = Locator.ConnectServer("vgiwpw03-sql3", "root\cimv2")

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

public objFso, objTextFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\EventLogFile.txt", ForAppending, True)

' Create the MMC Application object.
Dim objMMC
Set objMMC = Wscript.CreateObject("MMC20.Application")

' Load a console file.
' The console file in this case contains the Event Viewer snap-in.
' This console file ships with the operating system.
objMMC.Load("eventvwr.msc")
 
' Retrieve the Document object. The Document object provides access
' to the ScopeNamespace and ActiveView objects.
Dim objDoc
Set objDoc = objMMC.Document

' Retrieve the ScopeNamespace object. The ScopeNamespace object
' will be used when navigating the scope tree.
Dim objSN
Set objSN = objDoc.ScopeNamespace

' Get the console root node.
Dim objRoot
Set objRoot = objDoc.RootNode

' Using the console Root Node, get the Event Viewer node.
Dim objEvtVwrNode
Set objEvtVwrNode = objSN.GetChild(objRoot)

' Expand the Event Viewer Node.
objSN.Expand(objEvtVwrNode)

' Get the ActiveView, which is a View object.
' This object is used to access the list of nodes and column data.
Dim objView
Set objView = objDoc.ActiveView

' Get the first child node of the Event Viewer node.
On Error Resume Next
Dim objNode
Set objNode = Nothing
Set objNode = objSN.GetChild(objEvtVwrNode)
if (objNode Is Nothing) then
    ' Unexpected condition.
    objTextFile.WriteLine("Unable to get Event Viewer child node.")
    'Wscript.echo "Unable to get Event Viewer child node."
    'Wscript.quit
end if

Dim objSib  ' Used when moving to the next child (sibling) node.
' Loop through each Event Viewer's child nodes.
Do Until (objNode is Nothing)
    ' Expand the Event Viewer's child node.
    objSN.Expand(objNode)

    ' Display text stating which node is being examined.
    objTextFile.WriteLine("Error events in the " + objNode.Name + " log")
    'Wscript.echo "Error events in the " + objNode.Name + " log"
    objTextFile.WriteLine("=====================================")
        Dim objList
    Set objList = objView.ListItems

    ' Iterate through the list of nodes.
    Dim objItem
    For Each objItem In objList
        Dim str
        ' Retrieve the data in the first column. In the Event Viewer
        ' snap-in, the first column is for the Event type.
        str = objView.CellContents(objItem, 1)
        ' Determine if the event type is for an Error event.
        If (str = "Error") Then
            ' The node is for an Error event.
            ' Output the details of this Error event, with
            ' a comma separating each data field.
            
  dim myVariable   
  myVariable = objView.CellContents(objItem, 1) & "," & _
                         objView.CellContents(objItem, 2) & "," & _
                         objView.CellContents(objItem, 3) & "," & _
                         objView.CellContents(objItem, 4) & "," & _
                         objView.CellContents(objItem, 5) & "," & _
                         objView.CellContents(objItem, 6) & "," & _
                         objView.CellContents(objItem, 7) & "," & _
                         objView.CellContents(objItem, 8)  
                         
                            
objTextFile.WriteLine(myVariable)
        End If
    Next

    ' Print a blank line before the next child node is processed.
    'Wscript.echo ""
    objTextFile.WriteLine("")

    ' Move to the next node under the Event Viewer node.
    Set objSib = Nothing
    Set objSib = objSN.GetNext(objNode)
    Set objNode = objSib

Loop

objTextFile.Close

 
tsuji (TechnicalUser)
10 Nov 10 11:34
[Q.0] Can you clarify whether vgiwpw03-sql3 is the remote m/c? And the path to eventvwr.msc on the remote m/c you may need? And the path to MMC EVent Viewer Remote Server.vbs? etc... The path is fairly important as you don't have current directory set and the search may go to windows\system32 where the cmd to run the bat file is located.

[Q.1] In the meantime, what is the errReturn being returned?

[Q.2] Also why does it need to make a pass through .bat? You may well directly execute the cscript?

[Q.3] And then, what is the "central" location? which executable is hosted there? Is it different from the local m/c where the (wmi) script is executed?

[Q.4] The user running the wmi script and got impersonated, does he belong to the local admin group of the remote?...

The picture is not very clear.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close