Using WMI win32_share in asp.net page not working on IIS6?
-
hi, I'm trying to create a folder sharing using WMI win32_share on an ASP.NET c# page. while running it using the visual studio 2008 it works great. But after I publish it to the IIS and run the WebPage nothing happends?! it's seems like the page was loaded fine but checking the folder I see no share was created. Any ideas? I'm using .NET 3.5, visual studio 2008, c# webapplication. IIS 6 server. here is the code
string shareName = "Test";
string CUDir = @"D:\Test";
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"\] = ""; inParams\["Name"\] = shareName; inParams\["Path"\] = CUDir; inParams\["Type"\] = 0x0; // Disk Drive // Invoke the method on the ManagementClass object outParams = managementClass.InvokeMethod("Create", inParams, null);
tnx
modified on Tuesday, January 27, 2009 4:33 AM
-
hi, I'm trying to create a folder sharing using WMI win32_share on an ASP.NET c# page. while running it using the visual studio 2008 it works great. But after I publish it to the IIS and run the WebPage nothing happends?! it's seems like the page was loaded fine but checking the folder I see no share was created. Any ideas? I'm using .NET 3.5, visual studio 2008, c# webapplication. IIS 6 server. here is the code
string shareName = "Test";
string CUDir = @"D:\Test";
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"\] = ""; inParams\["Name"\] = shareName; inParams\["Path"\] = CUDir; inParams\["Type"\] = 0x0; // Disk Drive // Invoke the method on the ManagementClass object outParams = managementClass.InvokeMethod("Create", inParams, null);
tnx
modified on Tuesday, January 27, 2009 4:33 AM
The problem was on the IIS application pool. in order for me to use Win32_share I need to setup the predefined Identity of the Application Pool to Local System. otherwise I have no premissions to use WMI. I can also set the Configurable to a user with the right premissions to do the same. To access the Identity you need to open the IIS Manager. Colpase the Apllication pools and either create a new pool to be used or edit the deafult by right click and Properties. Go to the Identity tab and choose your wish. Also do not forget to go to under Web Sites and on your selected website/virtual directory properties to set under the Application settings the Apllication pool to the one with the new premissions.