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 ...
-
4th October 2011, 03:19 PM #1
- 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
-
-
IDG Tech News
-
5th October 2011, 09:14 AM #2
- Rep Power
- 6
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: 
Similar Threads
-
By thesk8rjesus in forum Coding
Replies: 1
Last Post: 23rd November 2010, 03:44 PM
-
Replies: 9
Last Post: 25th June 2010, 08:00 PM
-
By Pauldg in forum Scripts
Replies: 3
Last Post: 16th February 2009, 09:36 PM
-
By ChrisP in forum Coding
Replies: 4
Last Post: 19th December 2007, 11:18 AM
-
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
-
Forum Rules