Problem with Win32_NetworkLoginProfile and C#

  • Thread starter Thread starter Stefan Pilgrim
  • Start date Start date
S

Stefan Pilgrim

Hi,
I try to query the Logins on a remote computer with a little c#-program.
Everything works fine, but some Logins are not returned from the remote
computer. Microsoft confirms that there's a problem with the
Win32_NetworkLoginProfile class.
http://support.microsoft.com/default.aspx?scid=kb;DE;816485

To solve the problem Microsoft recommends to use the following line in
VBScript:
Set objWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate,
(Restore)}!root/cimv2")

That works fine. But I don't know how to bring the "(Restore)" to my
c#-program:

ManagementObjectSearcher searcher = new ManagementObjectSearcher(new
SelectQuery("SELECT * FROM Win32_NetworkLoginProfile"));
ConnectionOptions con= new ConnectionOptions();
con.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mScope = new ManagementScope("\\\\BS457\\root\\cimv2", con);
searcher.Scope = mScope;
searcher.Get(results);

Thanks
Stefan
 
Add this to your code:
mScope.Options.EnablePrivileges = true;

this should enable the required privilege(s) (SeRestorePrivilege) for this
sesion.

Willy.
 
Back
Top