views:

116

answers:

1

Hi,

I'm using WMI in .NET to connect to remote machines in a web app. When I initialize the connection, the Management ConnectionOptions always require a username and password in text. I was wondering if there was a way for it to use the context of the current Windows user, eg via page.user.identity. If I leave the connectionoptions blank then it doesn't appear to default to anything - remains null. The reason is because I don't want the user to have to enter a logon/password - that's the whole point of Windows integrated security, right?

Any info is appreciated! Thanks

+2  A: 

Take a look at this description of the constructor for ConnectionOptions. It says that when username and password are null then the credentials of the currently logged-on user are used.

ConnectionOptions options = new ConnectionOptions(...);

// Make a connection to a remote computer.
// Replace the "FullComputerName" section of the
// string "\\\\FullComputerName\\root\\cimv2" with
// the full computer name or IP address of the
// remote computer.
ManagementScope scope = 
            new ManagementScope(
            "\\\\FullComputerName\\root\\cimv2", options);
scope.Connect();
Seventh Element
Thanks, this is useful.
tuseau