1

I am working on a small project, in asp.net mvc3, that would copy the deployment files from a local drive to a share drive on a window server 2008 R2 server. I am connected using WMI, and the connection is successful. However, I tried to create a folder, and I receive the message "Logon failure: unknown user name or bad password." Here is a sample code:

bool isConnected = false;
            options.Username = user.Name.Trim();
            options.Password = user.password.Trim();
            mScope = new ManagementScope("\\\\xxx.xxx.xxx.xxx\\root\\cimv2", options);
            mScope.Connect();
            if (mScope.IsConnected == true)
            {
               //I've gotten to this point. Then, the code below throw the exception
                Directory.CreateDirectory(@"\\\\xxx.xxx.xxx.xxx\Tester\shareFile.txt");
                isConnected = true;
            }

I'd like to know what am I doing? Is that the right way of doing it?

Josiane Ferice
  • 921
  • 5
  • 15
  • 31

1 Answers1

3

it is the correct way however it will be the current user you are trying to access that gets passed to the remote computer to create the directory. The management scope at this point has nothing to do with Directory.CreateDirectory. These are 2 different "worlds". you do give the creds to ManagementScope but this has no affect on Directory.CreateDirectory. you could use impersonation to do what you are wanting to:

How do you do Impersonation in .NET?

it is unclear though if you are doing this in ASP.NET/MVC or a different platform. your tags indicate ASP.NET MVC but not your main question.

remember, if you are using ASP.NET/MVC, the credentials of the app pool are being used to perform such actions.

Community
  • 1
  • 1
Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72