J'utilise le morceau de code suivant pour modifier la propriété "port" de l'imprimante. Le problème est qu'il s'exécute plus d'une minute. Y a-t-il un moyen de l'accélérer? Puis-je instancier l'objet de gestion non avec toutes les propriétés de l'objet wmi? Et plus important encore, comment puis-je mettre à jour seulement 1 propriété? Peut-être que je devrais instancier managementobject withouth searcher?La mise à jour de l'objet de gestion win32_printer prend tellement de temps
ManagementPath mPath = new ManagementPath();
mPath.Server = Server.TrimStart(new char[] {'\\'});
mPath.NamespacePath = "root\\cimv2";
ManagementScope mScope = new ManagementScope();
mScope.Options.Impersonation = ImpersonationLevel.Impersonate;
mScope.Path = mPath;
SelectQuery sQ = new SelectQuery();
sQ.ClassName = "Win32_Printer";
//sQ.SelectedProperties.Add("PortName");
//sQ.SelectedProperties.Add("DeviceID");
sQ.Condition = string.Format("Name=\"{0}\"", Name);
ManagementObjectSearcher s = new ManagementObjectSearcher(mScope, sQ);
foreach (ManagementObject service in s.Get())
{
string oldname = service.Properties["PortName"].Value.ToString();
service.Properties["PortName"].Value = PortName;
service.Put();
this.Port = PortName;
return true;
}