+ Post New Thread
Results 1 to 2 of 2
Windows Server 2008 Thread, Connecting to a remote computer using VBScript in Technical; Hey all, I am trying to create a script that connects to a remote computer to get the OS that ...
  1. #1

    Join Date
    Sep 2011
    Posts
    16
    Thank Post
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Connecting to a remote computer using VBScript

    Hey all,

    I am trying to create a script that connects to a remote computer to get the OS that is running on it. It is a fairly simple code that I have written, and though it works for the local computer, as soon as I change the strComputer to a remote computer name it does nothing. I am querying this info out of Windows Server 2008 database. Think you can help?

    Here is my code:

    Option Explicit
    Dim objWMIService, objItem, colItems, counter
    Dim strComputer, strList, objOS, stringArray

    On Error Resume Next
    strComputer = "."
    strOS = "XP"
    str7 = "7"


    ' WMI Connection to the object in the CIM namespace
    Set objWMIService = GetObject("winmgmts:\\" _
    & strComputer & "\root\cimv2")

    ' WMI Query to the Win32_OperatingSystem
    Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

    ' For Each... In Loop (Next at the very end)
    For Each objItem in colItems
    objOS=objItem.Caption & VbCr
    Next

    stringArray = Split(objOS)
    for counter=0 to UBound(stringArray)
    if (stringArray(counter)=strOS) then
    Wscript.Echo "Windows XP"
    Exit for
    End if
    if (stringArray(counter)=str7) then
    Wscript.Echo "Windows 7"
    Exit for
    End if
    next
    WSCript.Quit

    ' End of WMI Win32_OperatingSystem VBScript

  2. #2

    Join Date
    Mar 2011
    Location
    Coventry
    Posts
    61
    Thank Post
    12
    Thanked 6 Times in 6 Posts
    Rep Power
    8
    The two things I can think of are....

    Is there a firewall running on the remote server? and if so is it set to allow WMI queries through?

    And also try setting the impersonation level for authentication on the remote server.

    I have a script that gets the current user of the remote machine that works using WMI. Dont know if it will help so I will paste the appropriate piece of code below.

    Code:
    Function GetLocallyLoggedOnUser(strComputer)
    	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
    	
    	Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
    	 
    	For Each objComputer in colComputer
    		'WScript.Echo " " & objComputer.UserName
    	    GetLocallyLoggedOnUser = objComputer.UserName
    	Next
    End Function

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 1
    Last Post: 23rd November 2010, 03:44 PM
  2. Replies: 9
    Last Post: 25th June 2010, 08:00 PM
  3. Replies: 3
    Last Post: 16th February 2009, 09:36 PM
  4. vbs to write to mySQL on remote computer
    By ChrisP in forum Coding
    Replies: 4
    Last Post: 19th December 2007, 11:18 AM
  5. Remote software - using it to monitor students
    By Halfmad in forum General Chat
    Replies: 12
    Last Post: 10th April 2007, 09:54 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •