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
tr
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)
els
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 use
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
ManagementBaseObject outParams = classObj.InvokeMethod("Create", inParams, null)
catch (Exception ex
throw ex
finall
/************************************************** ************************
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 th
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 file
Regards
PR