Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get server name using vbscript 1

Status
Not open for further replies.

tbscmgi

MIS
Sep 17, 2003
66
US
I'm trying to get a server name by passing the ip address.
I have a primary server and backup server i only want the primary server name, that why I'm passing the IP address.
Below is my script and error message.
-----------------------------------------------------------
Sub ShowSVRIPAddress

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTDomain",,48)
For Each objItem in colItems
tmpsvripaddr = objItem.DomainControllerAddress
if Right(tmpsvripaddr,3) > 0 then
svripaddr = Left(tmpsvripaddr,(Len(tmpsvripaddr)-3)) & 195
svripaddr1 = Right(svripaddr,(Len(svripaddr)-2))
if Right(svripaddr,3) = 195 then
strComputer = svripaddr
ShowSVRName strComputer
end if
end if
next
set objWMIService = Nothing
End Sub
---------------------------------------------------------
Sub ShowSVRName(strComputer)

error on this line Set objWMIService = GetObject("winmgmts:\\" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTDomain",,48)
For Each objItem in colItems
tmpsvrname = objItem.DomainControllerName
msgbox " name = " & tmpsvrname
next
set objWMIService = Nothing
End Sub

error message is
error: 0x80041021
code: 80041021
source: (null)

Thank for any help
Tony
 
[1]
>error on this line Set objWMIService = GetObject("winmgmts:\\" _
[tt]Set objWMIService = GetObject("winmgmts[highlight]:"[/highlight] _[/tt]
[2]
You _must_ either rename the above objWMIService to something else, or put a dim in the sub ShowSVRName to limit its scope and to avoid variable name collision with the caller.
[tt]
Sub ShowSVRName(strComputer)
dim objWMIService
'etc...
End Sub
[/tt]
[3] The way you change the meaning of strComputer is worrisome, though should not have the same gravity as that of objWMIService mentioned in [2]. Those names are arbitrary, and you have no need to call it the same every time you invoke wmi's service.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top