العثور على منتج خاص موجودة في النظام البعيد أم لا
-
08-07-2019 - |
سؤال
وتحاول أن تجد يتم تثبيت المنتج في أجهزة الكمبيوتر عن بعد أو لم يكن، فإنه يستغرق وقتا طويلا لتنفيذ، هل هناك أي طرق يمكننا تحقيق ذلك أسرع.
و// الاستعمال: // uninstall4 ( "المضيف"، "PRODUCTNAME"، "{AC9C1263-2BA8-4863-BE18-01232375CE42}"، "10.0.0.69")؛
public void uninstall4(string targetServer, string product,string guid , string version)
{
//Connect to Server
System.Management.ConnectionOptions connoptions = new System.Management.ConnectionOptions();
connoptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;
connoptions.Timeout = new TimeSpan(0, 0, 10); // 10 seconds
System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" + targetServer + @"\root\cimv2", connoptions);
scope.Connect();
string q = "select * from Win32_Product where name = '" + product + "' and IdentifyingNumber='"+guid+"' and version = '"+version+"'";
System.Management.SelectQuery query = new System.Management.SelectQuery(q);
System.Management.EnumerationOptions options = new System.Management.EnumerationOptions();
options.EnumerateDeep = false;
options.ReturnImmediately = false;
options.DirectRead = true;
using (System.Management.ManagementObjectSearcher searcher
= new System.Management.ManagementObjectSearcher(scope, query, options))
{
using (System.Management.ManagementObjectCollection moc = searcher.Get())
{
if(moc == null || moc.Count == 0)
{
throw new Exception("product Not Found");
}
}
}
}
المحلول
وكلا. مقدم لفئة Win32_Product أن بناء المعلومات حيوي عند الاستعلام ذلك، وأنها دائما، دائما بطيئة.
لا تنتمي إلى StackOverflow