Hello,
I am writing a VB.NET tool that at one part tries to retrieve the Terminal Services permissions on a remote computer. It works great on the local computer but refuses to work on a remote one. I used this as my reference
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383773(v=vs.85).aspx and the WMI creator tool.
Heres what I got:
This works on a local Win7 PC.
Dim searcher As New ManagementObjectSearcher("\\" & strComputer & "\root\CIMV2\TerminalServices", "SELECT * FROM Win32_TSAccount")
For Each objItem 'As ManagementObject In searcher.Get()
msgbox (objItem("AccountName") & " - " & objItem("PermissionsAllowed"))
next
Again, the above works if I put the local computer name in as strComputer but does not work for remote computers. I tried a few things, including adding the winmgmts:{authenticationLevel=pktPrivacy}! and impersonate but nothing seems to work. When I add
the winmgmts to the line above I get invalid parameters errors so I broke it out like the below:
Dim objWMIService As Object = GetObject("winmgmts:{authenticationLevel=pktPrivacy}!\\" & strComputer & "\root\CIMV2\TerminalServices")
Dim colItems As Object = objWMIService.ExecQuery("SELECT * FROM Win32_TSAccount")
For Each objItem In colItems
msgbox (objItem("AccountName") & " - " & objItem("PermissionsAllowed"))
next
This gives does not even work on the local machine and gives a Member not found found.
I'm a little stuck if anyone could shoot over some ideas I would be greatly appreciative.
Thanks
Life moves pretty fast. If you don't stop and look around once in a while, you could miss it.