我在比较两个列表时遇到了麻烦。该程序的目的是执行脱机补丁安装

时间:2014-02-27 13:19:27

标签: c#

问题出现在循环中。它似乎执行wmi qfe列表和KB列表之间的比较。我遇到的问题是获取并搜索KB的.msu文件名列表的内容,然后安装它。我在python中创建了一个类似的程序,并在C#代码中模仿了一个类似的构造。任何有关如何正确使用此功能的指导将不胜感激。代码如下:

static void Server08r2Patches()
    {
    var IE9 = from a in IAVA.Worksheet<IE9>("IE9") select a;
    var Server08r2 = from a in IAVA.Worksheet<Server08r2>("Server08r2") select a;
    var KBlist = Server08r2.Select(s=>new {KB = s.KB}).ToList();
    var ExeList = Server08r2.Select(s=>new {Executable = s.Executable}).ToList();
    string path = (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)+@"\x64\");
    foreach (var item in KBlist)
    {
    if (OsPatches.Contains(item.KB))
    {
                Console.WriteLine(item.KB+" is already installed.");
            }
            else
            {
                Console.WriteLine(item.KB+" will now be installed.");
                foreach (var inst in ExeList)
                {
                    do
                        {
                            var kb_inst = new ProcessStartInfo()
                            {
                                CreateNoWindow = true,
                                UseShellExecute = true,
                                FileName =path+inst.Executable,
                                WindowStyle = ProcessWindowStyle.Hidden,
                                Arguments = (@" /quiet /norestart"),
                            };
                            try
                            {
                                Process update = new Process();
                                update.StartInfo = kb_inst;
                                update.Start();
                                update.WaitForExit();
                                Console.WriteLine(inst.Executable+" was successfully installed");
                            }
                            catch (Exception Ex)
                            {
                                Console.WriteLine(Ex.Message+" "+inst.Executable);
                            }
                        }
                    while (inst.Executable.Contains(item.KB) == true);
                }
            }
        }
    }

0 个答案:

没有答案