Problem with Win32_NetworkLoginProfile and C#

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
 
W

Willy Denoyette [MVP]

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

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

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top