i have problem with sharing a folder through programming using c#?

Posted by moon on Stack Overflow See other posts from Stack Overflow or by moon
Published on 2010-03-29T06:23:58Z Indexed on 2010/03/29 6:33 UTC
Read the original article Hit count: 268

Filed under:

here is my code it shares the folder but that does not work correctly when i want to access it , it shows access denied help required,

private static void ShareFolder(string FolderPath, string ShareName, string Description) { try { // Create a ManagementClass object ManagementClass managementClass = new ManagementClass("Win32_Share"); // Create ManagementBaseObjects for in and out parameters ManagementBaseObject inParams = managementClass.GetMethodParameters("Create"); ManagementBaseObject outParams; // Set the input parameters inParams["Description"] = Description; inParams["Name"] = ShareName; inParams["Path"] = FolderPath; inParams["Type"] = 0x0; // Disk Drive //Another Type: //DISK_DRIVE = 0x0; //PRINT_QUEUE = 0x1; //DEVICE = 0x2; //IPC = 0x3; //DISK_DRIVE_ADMIN = 0x80000000; //PRINT_QUEUE_ADMIN = 0x80000001; //DEVICE_ADMIN = 0x80000002; //IPC_ADMIN = 0x8000003; //inParams["MaximumAllowed"] = int maxConnectionsNum; // Invoke the method on the ManagementClass object outParams = managementClass.InvokeMethod("Create", inParams, null); // Check to see if the method invocation was successful

            if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
            {
                throw new Exception("Unable to share directory. Because Directory is already shared or directory not exist");
            }//end if

        }//end try
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "error!");
        }//end catch
    }//End Method

© Stack Overflow or respective owner

Related posts about c#