views:

621

answers:

0

Hi.

I have a really simple piece of code that creates a DirectoryEntry object which is attached to a w3svc object on a remote server. The C# code I have is as follows (NOTE: The code runs inside a windows WPF form)

    public static W3SvcWrapper CreateW3Svc(string machineName,
                                           string username,
                                           string password)
    {
        string path = "IIS://<computername>/w3svc";

        DirectoryEntry w3SvcDir =
            new DirectoryEntry(path, username, password,
                               AuthenticationTypes.Secure | AuthenticationTypes.Encryption);

        // Dump Child Objects
        foreach (DirectoryEntry child in w3SvcDir.Children)
            System.Diagnostics.Debug.WriteLine(String.Format("   Child Name: {0}, Path: {1}, Schema: {2}, Username: {3}"
                                                            , child.Name
                                                            , child.Path
                                                            , child.SchemaClassName
                                                            , child.Username));

}

My problem is that no matter what username and password I pass in I always seem to be connecting with the interactive users credentials. If I pass in completely bogus login details no authentication failure occurs and my user credentials are still be used.

The diagnostic message shows that the username has been set correctly but all the logging on the remote machine (i.e. the Security Audit in the EventViewer) only shows activity from my interactive user.

Have I really misunderstood how this is supposed to work? How can I achieve controlling a website remotely with different user credentials? NOTE: I don't want to run the process as a different user or impersonate a different user within the process.

Thanks for any help