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 Chris 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 when Permission denied

Status
Not open for further replies.

tbscmgi

MIS
Sep 17, 2003
66
US
To All-
I get permission denied when I'm trying to get the server name.
Thanks for any help.
tbscmgi


********************************************************
Sub ShowSVRIPAddress

strComputer = "."

Set objIPaWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colIPaItems = objIPaWMIService.ExecQuery("Select * from Win32_NTDomain",,48)
For Each IPAobjItem in colIPaItems
tmpsvripaddr = IPAobjItem.DomainControllerAddress
if Right(tmpsvripaddr,3) > 0 then
svripaddr = Left(tmpsvripaddr,(Len(tmpsvripaddr)-3)) & 195
svripaddr1 = Right(svripaddr,(Len(svripaddr)-2))
end if
next
set objIPaWMIService = Nothing
End Sub
'============================================================================
'
' S h o w S V R N a m e
' =======================
'
'
Sub ShowSVRName
Set objSVRnWMIService = GetObject( _
"winmgmts:{impersonationLevel=impersonate," _
& "authenticationLevel=pktPrivacy}!\\" & svripaddr1 & "\root/cimv2")
Set colSVRnItems = objSVRnWMIService.ExecQuery("Select * from Win32_NTDomain",,48)
For Each SVRNobjItem in colSVRnItems
tmpsvrname = SVRNobjItem.DomainControllerName
next
set objSVRnWMIService = Nothing
End Sub
 
Are are making a proclamation or do you want someone to tell you what's wrong with your script?

If it's the latter, you are posting 2 stand-alone subroutines but you're not calling them anywhere in the script. This isn't a complete script. Try posting the entire script and telling us what you've tried so far. Also include where you're running it from and include the operating system. List your credentials as well since I assume you are an administrator or have appropriate rights on the device you're running the script on.
 
Brycspain-
Sorry about that, I'm calling the subroutines, but the problem I'm having is when I pass the primary server IP Address I keep getting permission denied.

Thanks
Tony
 
Are you a domain administrator ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If you just need a domain controller name then just use something like this.

Code:
Dim objADSysInfo : Set objADSysInfo = CreateObject("ADSystemInfo")
WScript.Echo objADSysInfo.GetAnyDCName

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top