private void BackgroundDoWork(string FileName, string Arguments) { TaskProgressBar.ProgressState = TaskbarItemProgressState.Indeterminate; Tab4Process.IsIndeterminate = true; try { Process p = new Process(); p.StartInfo.FileName = FileName; if (Arguments != null) { if (FileName == string.Empty) { OTP.OfficeConfiguration office = new OTP.OfficeConfiguration(); if (office.HasOffice) { p.StartInfo.FileName = "cscript"; p.StartInfo.Arguments = "//Nologo \"" + office.InstallPath + "\\Office16\\ospp.vbs\" /" + Arguments; } else { TaskProgressBar.ProgressState = TaskbarItemProgressState.None; Tab4Process.IsIndeterminate = false; CMessageBox.Show(Find("ToastLoadOSPPError"), Find("MsgError"), CMessageBoxImage.Error); return; } } else { p.StartInfo.Arguments = Arguments; } } p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = true; p.EnableRaisingEvents = true; p.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived); p.Exited += Process_Exited; p.Start(); p.BeginOutputReadLine(); } catch (Exception ex) { TaskProgressBar.ProgressState = TaskbarItemProgressState.None; Tab4Process.IsIndeterminate = false; CMessageBox.Show(ex.Message, CMessageBoxImage.Error); } }
private void ResetLicensingStatus_Click(object sender, RoutedEventArgs e) { if (CMessageBox.Show(Find("MsgResetLicensingStatus"), Find("MsgWarning"), CMessageBoxButton.YesNO, CMessageBoxImage.Question) == CMessageBoxResult.Yes) { OTP.OfficeConfiguration office = new OTP.OfficeConfiguration(); if (office.HasOffice) { BackgroundDoWork(office.InstallPath + "\\Office16\\OSPPREARM.EXE", string.Empty); } else { CMessageBox.Show(Find("ToastLoadOSPPError"), Find("MsgError"), CMessageBoxImage.Error); return; } } }
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(); } } }