File Copy in ASp.net

G

Guest

Hi ,
I am sharing a network drive, by using the following code (C# Code using ASP.net)
/**********************************************************************************/
public void ShareMap(string machineName, string username, string password, string ShareName)

{

System.Management.ManagementScope sc = null;

ConnectionOptions co = null;

try

{

co = new ConnectionOptions();

co.Impersonation = ImpersonationLevel.Impersonate;

//co.Impersonation = ImpersonationLevel.Delegate;

co.EnablePrivileges = true;

if (machineName.ToUpper() == Environment.MachineName.ToUpper() )

sc = new ManagementScope(@"\ROOT\CIMV2", co);

else

{

co.Username = username;

co.Password = password;

sc = new ManagementScope(@"\\" + machineName + @"\ROOT\CIMV2", co);

}

sc.Connect();

ManagementBaseObject inParams = null;
ManagementClass classObj = new ManagementClass(sc, new ManagementPath("Win32_Share"), null);
inParams = classObj.GetMethodParameters("Create");
inParams["Access"] = null; // default Security descriptor used
inParams["Description"] = "Shared for Admin Purposes";
inParams["MaximumAllowed"] = 10;
inParams["Name"] = ShareName;
inParams["Password"] = password;
inParams["Path"] = @"c:\";
inParams["Type"] = 0; // Disk drive 0, print queue 1
ManagementBaseObject outParams = classObj.InvokeMethod("Create", inParams, null);
}

catch (Exception ex)

{

throw ex;

}

finally

{

}

}

/**************************************************************************/

and then trying to copy using

string sSource = @"c:\temp\test.exe";
string sExepath = @"\\"+sRemoteMachineName+@"\C$\test.exe";
// Copy the file.
File.Copy(sSource, sExepath,true);


This is when I get the
System.Io.Exception: Logon Failure: unknown user name or bad password, Error. I dont get this error when I am running thee application as a C# Console application. But when I run the same code in an ASp.net web page. I have these problems.

Any feedback would be appreciated.

I need to be able to dynamically share drives on different machines and copy files

Regards,
PRM




Print | Copy URL of this post



... .


Manage Your Profile |Legal |Contact Us |MSDN Flash Newsletter
©2004 Microsoft Corporation. All rights reserved. Terms of Use |Privacy Statement
 

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

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top