Hi There,
I was wondering if anyone can help me with the following problem:
I have written an app to easily create a share on a remote computer utilizing WMI, however I cannot seem to get it working, I end up with a "Provider is not capable of the attempted operation" error. I have full admin access to the remote server so permissions should not be an issue. Any help or suggestions would be greatly appreciated. Below is the code in question:
try { ManagementPath winSharePath = new ManagementPath("Win32_Share"); ManagementScope winShareScope = new ManagementScope(@"\\server01\root\cimv2"); ManagementClass winShareClass = new ManagementClass(winShareScope,winSharePath,null); ManagementObject shareObject = winShareClass.CreateInstance(); shareObject["Path"] = @"E:\Test"; shareObject["Name"] = "TestShare$"; shareObject["Type"] = 0; shareObject["Description"] = "Test Share Description"; PutOptions shareOptions = new PutOptions(); shareOptions.Type = PutType.UpdateOrCreate; shareOptions.Timeout = TimeSpan.MaxValue; shareObject.Put(shareOptions); } catch (Exception err) { MessageBox.Show(err.Message); }
|
Cheers
Ben
Mayur VadherPosted Oct 7, 2010, 2:08 AM
here is my code.
Dim moSearch As Management.ManagementObjectSearcher = New Management.ManagementObjectSearcher("Select * from Win32_POTSModem")
'' get serach data
Dim oc As Management.ManagementObjectCollection = moSearch.Get()
'' list of every modems install in computer
For Each m As Management.ManagementObject In oc
'' check modem status
'' status "OK" means ready to use
If m("Status").ToString() = "OK" Then
''' properties list
''' http://msdn.microsoft.com/en-us/library/aa394360%28VS.85%29.aspx
If m("Name").ToString & "[" & m("AttachedTo").ToString() & "]" = oldNm Then
Dim p As String = m.Item("Name")
m.SetPropertyValue("Name", newNm)
Dim moo As New Management.ManagementOperationObserver()
Dim shareOptions As New Management.PutOptions()
shareOptions.Type = Management.PutType.UpdateOrCreate
shareOptions.Timeout = TimeSpan.MaxValue
m.Put(shareOptions)
'm.SetQualifierValue("Name", newNm)
Exit For
End If
End If
Next
for above code i got error like "Provider is not capable of the attempted operation", when i call put function.
any solution.
Ben TaylorPosted Dec 30, 2009, 10:38 PM
ManagementPath winSharePath = new ManagementPath("Win32_Share");
ManagementScope winShareScope = new ManagementScope(@"\\server01\root\cimv2");
ManagementClass winShareClass = new ManagementClass(winShareScope, winSharePath, null);
ManagementBaseObject shareParams = winShareClass.GetMethodParameters("Create");
shareParams["Path"] = @"E:\Test";
shareParams["Name"] = "TestShare$";
shareParams["Type"] = 0;
shareParams["Description"] = "Test Share Description";
ManagementBaseObject winShareResult = winShareClass.InvokeMethod("Create", shareParams, null);
Cheers
Ben
Lalit MPosted Dec 29, 2009, 12:42 AM