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
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