ObjectGetOptions options = new ObjectGetOptions();
ManagementPath p = new ManagementPath("\\\\server01\\root" + "\\cimv2:Win32_Share");
// Make a connection to a remote computer.
ManagementScope scope = new ManagementScope("\\\\server01\\root\\cimv2");
scope.Connect();
// Create a ManagementClass object
ManagementClass managementClass = new ManagementClass(scope, p, options);
// Create ManagementBaseObjects for in and out parameters
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
ManagementBaseObject outParams;
// Set the input parameters
//inParams["Description"] = String.Empty;
inParams["Name"] = "test";
inParams["Path"] = @folderPath;
inParams["Type"] = 0x0; // Disk Drive
// 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. Error code: " + outParams.Properties["ReturnValue"].Value);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
}
}
Sto utilizzando il seguente codice per impostare una condivisione, ma ottengo sempre un valore di ritorno di 9 che significa un nome non valido. Sto passando una stringa e ho provato a utilizzare una stringa esplicita e ottengo ancora l'errore 9.Errore di programmazione con errore 9
Sto creando la condivisione in remoto anziché su una macchina locale. Ho cercato di assicurarmi che mi stia connettendo al provider WMI remoto, ma non sono sicuro di aver avuto successo.
Qualsiasi suggerimento da parte di guru WMI e altri è molto apprezzato.
Grazie per la condivisione – MichaelS
A meno che il percorso è per la radice di un disco, per esempio C: \. Quindi è necessario il backslash. –