We help IT Professionals succeed at work.

Access denied! Get info from terminal server using wmi.

Using WMI I can access other servers and pc's execpt our Windows 2003 terminal server. Basic code is as follows. Any help is appreciated. C# code is welcome.

 
Public Sub getInfo(byval Server as string)
        Dim options As New ConnectionOptions
        options.Impersonation = ImpersonationLevel.Impersonate
        options.Username = "Administrator"
        options.Password = "AdminPassword"
        options.EnablePrivileges = True
        options.Authentication = AuthenticationLevel.Packet
        options.Authentication = AuthenticationLevel.Connect
 
        Dim path As New ManagementPath("\\" & Server & "\root\CIMV2:Win32_Process")
        Dim ms As New ManagementScope(path, options)
        Dim op As New System.Management.ObjectGetOptions
 
        Dim wmi As New ManagementClass(ms, path, New ObjectGetOptions())
        Dim objs As ManagementObjectCollection
        Dim obj As ManagementObject
 
        objs = wmi.GetInstances()
 
        For Each obj In objs
'Retrieves process names on remote server
            Console.WriteLine(obj("Name"))
        Next
 
    End Sub

Open in new window

Comment
Watch Question

CERTIFIED EXPERT

Commented:
do you get an error? where is the problem?

Author

Commented:

Public Sub getInfo(byval Server as string)
        Dim options As New ConnectionOptions
        options.Impersonation = ImpersonationLevel.Impersonate
        options.Username = "Administrator"
        options.Password = "AdminPassword"
        options.EnablePrivileges = True
        options.Authentication = AuthenticationLevel.Packet
        options.Authentication = AuthenticationLevel.Connect
 
        Dim path As New ManagementPath("\\" & Server & "\root\CIMV2:Win32_Process")
        Dim ms As New ManagementScope(path, options)
        Dim op As New System.Management.ObjectGetOptions
 
        Dim wmi As New ManagementClass(ms, path, New ObjectGetOptions())
        Dim objs As ManagementObjectCollection
        Dim obj As ManagementObject
 
        objs = wmi.GetInstances()   <----------ERROR OCCURS ------Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
 
        For Each obj In objs
'Retrieves process names on remote server
            Console.WriteLine(obj("Name"))
        Next
 
    End Sub

Open in new window

CERTIFIED EXPERT

Commented:
are you able to modify permissions on that server?

Author

Commented:
Yes, I have full admin permissions. I have modified and added permissions to the wmi control.
CERTIFIED EXPERT

Commented:
CERTIFIED EXPERT

Commented:
sorry, about that last post
CERTIFIED EXPERT

Commented:
in the dcomcnfg did you enable distributed COM on this computer and reboot?

Author

Commented:
No, Where do I go to do that
1st can you remotly control that server with the Computer Management MSC from your PC?  If no then the 2003 firewall / restrictions are to tight.  (2003 by default is locked down tight)...

You should be able to utilize WMI within the MSC remotely if it is not being blocked.
CERTIFIED EXPERT

Commented:
run dcomcnfg from the run line

click on the my computer icon in the toolbar--> i believe it is under default properties

Author

Commented:
OK. tried to connect. Error Win32: Access is denied. Would you please walk me through loosening the restrictions?
Commented:
running dcomcnfg and configuring the default properties does not work. I set it just like the other servers.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.