Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

*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.

Students Click Here


Connect to remote servers

Connect to remote servers

Connect to remote servers

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.

RE: Connect to remote servers

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
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

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.
' 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.

' 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."
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.

    ' 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"
        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)  
        End If

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

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




RE: Connect to remote servers

[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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

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