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()); } } I am using the following code to set up a share, but I am always getting a return value of 9 which means invalid name. I am passing a string and have tried to use an explicit string and I still get error 9.I am creating the share remotely rather than on local machine however. I have tried to make sure I am connecting to the remote WMI provider, but I am not sure if I have been successful.Any suggestions from WMI gurus and others is greatly appreciated.
3 Réponses :
a trouvé la réponse sur un autre site. Le chemin du dossier doit être le chemin local de la machine que l'action est créée, pas un chemin UNC comme j'utilisais. P>
J'ai eu la même erreur. Dans mon cas, bien que le problème soit une barre oblique inverse. Do DistoirePath.trimend ('\') a résolu le problème. P>
Sauf si le chemin est pour la racine d'un lecteur, par exemple C: \. Ensuite, la barre oblique inverse est requise.
Valeurs de retour p>
retourne l'une des valeurs dans le tableau suivant ou toute autre valeur pour indiquer une erreur. 0 - Succès P>
2 - accès refusé p>
8 - échec inconnu p>
9 - Nom non valide P>
10 - Niveau non valide P>
21 - Paramètre non valide P>
22 - Dupliquer Partager P>
23 - Chemin redirigé P>
24 - Dispositif inconnu ou répertoire P>
25 - Nom net non trouvé p>
Où est la source de cette liste?
Je ne me souviens pas maintenant que c'était il y a longtemps mais voici un lien msdn.microsoft.com/en-us/library/aa393598 (v = vs.85) .aspx