Example #1
0
 private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     Dispatcher.BeginInvoke(new Action(delegate
     {
         ResultBox.AppendText(e.Data);
         ResultBox.AppendText(Environment.NewLine);
         ResultBox.ScrollToEnd();
     }));
 }
Example #2
0
        private void InstallLicenses_DoWork(object sender, DoWorkEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(delegate
            {
                Tab4Process.IsIndeterminate   = true;
                TaskProgressBar.ProgressState = TaskbarItemProgressState.Indeterminate;
            })).Wait();
            OTP.OfficeConfiguration office = new OTP.OfficeConfiguration();
            Process p = new Process();

            p.StartInfo.FileName               = "cscript";
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow         = true;
            string[] ar = (string[])e.Argument;
            if (ar[0] == "2")
            {
                XElement loadxml = XElement.Load(office.InstallPath + "\\root\\Licenses16\\c2rpridslicensefiles_auto.xml");
                IEnumerable <XElement> MatchElements = from el in loadxml.Elements("ProductReleaseId")
                                                       select el;

                char[]   separator = { ',' };
                string[] Licenses  = ar[1].Split(separator);
                foreach (string id in Licenses)
                {
                    foreach (XElement ele in MatchElements)
                    {
                        if (ele.Attribute("id").Value == id)
                        {
                            foreach (XElement elements in ele.Elements())
                            {
                                foreach (XElement element in elements.Element("Files").Elements())
                                {
                                    p.StartInfo.Arguments = "//Nologo \"" + office.InstallPath + "\\Office16\\ospp.vbs\" /inslic:\"" + office.InstallPath + "\\root\\Licenses16\\" + element.Attribute("name").Value + "\"";
                                    p.Start();
                                    string sOutput = p.StandardOutput.ReadToEnd();
                                    Dispatcher.BeginInvoke(new Action(delegate
                                    {
                                        ResultBox.AppendText(sOutput);
                                        ResultBox.ScrollToEnd();
                                    }));
                                }
                            }
                        }
                    }
                }
                return;
            }
            string[] files = Directory.GetFiles(ar[1], "*.xrm-ms");//获取指定路径的证书文件
            if (files.Length == 0)
            {
                e.Result = Find("ToastLicensesInstallError");
                return;
            }
            if (ar[0] == "0")//是否指定 common 证书
            {
                string[] commonfiles = Directory.GetFiles(ar[3], "*.xrm-ms");
                foreach (string s in commonfiles)
                {
                    FileInfo fi = new FileInfo(s);
                    p.StartInfo.Arguments = "//Nologo \"" + office.InstallPath + "\\Office16\\ospp.vbs\" /inslic:\"" + ar[3] + "\\" + fi.Name + "\"";
                    p.Start();
                    string sOutput = p.StandardOutput.ReadToEnd();
                    Dispatcher.BeginInvoke(new Action(delegate
                    {
                        ResultBox.AppendText(sOutput);
                        ResultBox.ScrollToEnd();
                    }));
                }
            }
            foreach (string s in files)//安装指定路径的证书文件
            {
                FileInfo fi = new FileInfo(s);
                p.StartInfo.Arguments = "//Nologo \"" + office.InstallPath + "\\Office16\\ospp.vbs\" /inslic:\"" + ar[1] + "\\" + fi.Name + "\"";
                p.Start();
                string sOutput = p.StandardOutput.ReadToEnd();
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ResultBox.AppendText(sOutput);
                    ResultBox.ScrollToEnd();
                }));
            }
            if (ar[0] == "0")//安装 Key
            {
                if (ar[2] != string.Empty)
                {
                    p.StartInfo.Arguments = "//Nologo \"" + office.InstallPath + "\\Office16\\ospp.vbs\" /inpkey:" + ar[2];
                    p.Start();
                    string Output = p.StandardOutput.ReadToEnd();
                    Dispatcher.BeginInvoke(new Action(delegate
                    {
                        ResultBox.AppendText(Output);
                        ResultBox.AppendText(Environment.NewLine);
                        ResultBox.ScrollToEnd();
                    })).Wait();
                }
            }
        }
Example #3
0
        private void InstallLicenses_DoWork(object sender, DoWorkEventArgs e)
        {
            Process p = new Process();

            p.StartInfo.FileName               = "cscript";
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow         = true;
            string[] ar = (string[])e.Argument;
            if (ar[0] == "2")
            {
                XElement loadxml = XElement.Load(OfficeInstallPath + "\\root\\Licenses16\\c2rpridslicensefiles_auto.xml");
                IEnumerable <XElement> MatchElements = from el in loadxml.Elements("ProductReleaseId")
                                                       select el;

                char[]   separator = { ',' };
                string[] Licenses  = ar[1].Split(separator);
                foreach (string id in Licenses)
                {
                    foreach (XElement ele in MatchElements)
                    {
                        if (ele.Attribute("id").Value == id)
                        {
                            foreach (XElement elements in ele.Elements())
                            {
                                foreach (XElement element in elements.Element("Files").Elements())
                                {
                                    if (File.Exists("files\\activate\\ospp_" + Find("Culture") + ".vbs"))
                                    {
                                        p.StartInfo.Arguments = "//Nologo files\\activate\\ospp_" + Find("Culture") + ".vbs /inslic:\"" + OfficeInstallPath + "\\root\\Licenses16\\" + element.Attribute("name").Value + "\"";
                                    }
                                    else
                                    {
                                        p.StartInfo.Arguments = "//Nologo files\\activate\\ospp.vbs /inslic:\"" + OfficeInstallPath + "\\root\\Licenses16\\" + element.Attribute("name").Value + "\"";
                                    }
                                    p.Start();
                                    string sOutput = p.StandardOutput.ReadToEnd();
                                    Dispatcher.BeginInvoke(new Action(delegate
                                    {
                                        ResultBox.AppendText(sOutput);
                                        ResultBox.ScrollToEnd();
                                    }));
                                }
                            }
                        }
                    }
                }
                return;
            }
            else if (ar[0] == "0")
            {
                try //删除多余文件,避免出错
                {
                    DirectoryInfo di = new DirectoryInfo(a + "licenses\\");
                    di.Delete(true);
                }
                catch
                { }
                ZipFile.ExtractToDirectory("files\\activate\\licenses.data", a);
            }
            string[] files = Directory.GetFiles(ar[1], "*.xrm-ms");//获取指定路径的证书文件
            if (files.Length == 0)
            {
                e.Result = Find("ToastLicensesInstallError");
                return;
            }
            if (ar[0] == "0")//是否指定 common 证书
            {
                string[] commonfiles = Directory.GetFiles(ar[3], "*.xrm-ms");
                foreach (string s in commonfiles)
                {
                    FileInfo fi = new FileInfo(s);

                    if (File.Exists("files\\activate\\ospp_" + Find("Culture") + ".vbs"))
                    {
                        p.StartInfo.Arguments = "//Nologo files\\activate\\ospp_" + Find("Culture") + ".vbs /inslic:\"" + ar[3] + "\\" + fi.Name + "\"";
                    }
                    else
                    {
                        p.StartInfo.Arguments = "//Nologo files\\activate\\ospp.vbs /inslic:\"" + ar[3] + "\\" + fi.Name + "\"";
                    }
                    p.Start();
                    string sOutput = p.StandardOutput.ReadToEnd();
                    Dispatcher.BeginInvoke(new Action(delegate
                    {
                        ResultBox.AppendText(sOutput);
                        ResultBox.ScrollToEnd();
                    }));
                }
            }
            foreach (string s in files)//安装指定路径的证书文件
            {
                FileInfo fi = new FileInfo(s);

                if (File.Exists("files\\activate\\ospp_" + Find("Culture") + ".vbs"))
                {
                    p.StartInfo.Arguments = "//Nologo files\\activate\\ospp_" + Find("Culture") + ".vbs /inslic:\"" + ar[1] + "\\" + fi.Name + "\"";
                }
                else
                {
                    p.StartInfo.Arguments = "//Nologo files\\activate\\ospp.vbs /inslic:\"" + ar[1] + "\\" + fi.Name + "\"";
                }
                p.Start();
                string sOutput = p.StandardOutput.ReadToEnd();
                Dispatcher.BeginInvoke(new Action(delegate
                {
                    ResultBox.AppendText(sOutput);
                    ResultBox.ScrollToEnd();
                }));
            }
            if (ar[0] == "0")//安装 Key
            {
                if (ar[2] != string.Empty)
                {
                    if (File.Exists("files\\activate\\ospp_" + Find("Culture") + ".vbs"))
                    {
                        p.StartInfo.Arguments = "//Nologo files\\activate\\ospp_" + Find("Culture") + ".vbs /inpkey:" + ar[2];
                    }
                    else
                    {
                        p.StartInfo.Arguments = "//Nologo files\\activate\\ospp.vbs /inpkey:" + ar[2];
                    }
                    p.Start();
                    string Output = p.StandardOutput.ReadToEnd();
                    Dispatcher.BeginInvoke(new Action(delegate
                    {
                        ResultBox.AppendText(Output);
                        ResultBox.AppendText(Environment.NewLine);
                        ResultBox.ScrollToEnd();
                    })).Wait();
                }
            }
        }