void DoWork(object sender, DoWorkEventArgs e) { CB_STATE cb_state = (CB_STATE)e.Argument; if (cb_state.vnc) { VNC vnc = new VNC(fileutils); Console.WriteLine("VNC安装中..."); vnc.install(); Console.WriteLine("VNC安装完成."); } if (cb_state.klite) { KLITE klite = new KLITE(fileutils); Console.WriteLine("K-Lite安装中..."); klite.install(); Console.WriteLine("K-Lite安装完成."); } if (cb_state.office) { OFFICE office = new OFFICE(fileutils); Console.WriteLine("MS Office安装中..."); office.install(); Console.WriteLine("MS Office安装完成."); } if (cb_state.uninstall != null) { foreach (INSTALLED item in lv_uninstalled.Items) { Console.WriteLine(item.name + "卸载中..."); progMgr.uninstall(item); //lv_uninstalled.Items.Remove(item); Console.WriteLine(item.name + "卸载完成."); } } }
private void Button_Click_1(object sender, RoutedEventArgs e) { Console.WriteLine("开始配置..."); CB_STATE cb_state = new CB_STATE(); if ((bool)cb_ip.IsChecked) { string mask = "255.255.255.0"; adapter.setIP(tb_ip.Text, mask); cfg.tb_ip = tb_ip.Text; Console.WriteLine("IP设置完成."); string path; if (flashdisk == null) { path = Regex.Match(tb_save.Text, @"\w").Groups[0].Value; } else { path = flashdisk.Name; } string origin = File.ReadAllText(tb_ipfile.Text, System.Text.Encoding.Default); //string origin = File.ReadAllText(tb_ipfile.Text, Encoding.UTF8); Regex rgx = new Regex(tb_ip.Text); string result = rgx.Replace(origin, tb_ip.Text + "," + adapter.mac); using (StreamWriter sw = new StreamWriter( new FileStream(tb_ipfile.Text, FileMode.Open, FileAccess.ReadWrite), Encoding.UTF8 )) //using (StreamWriter sw = File.CreateText(tb_ipfile.Text)) { sw.WriteLine(result); } //fileutils.append(tb_ip.Text + "----" + adapter.mac, path + @"部署工具\IP分配文件.txt"); if (flashdisk != null) { REMOVEDRIVE rmdrive = new REMOVEDRIVE(fileutils); //rmdrive.eject(flashdisk.Name); Console.WriteLine("IP和MAC已记录在文件: " + path + ". 可拔出U盘,部署将继续运行."); } } if ((bool)cb_gateway.IsChecked) { adapter.setGateway(tb_gateway.Text); Console.WriteLine("网关设置完成."); } if ((bool)cb_waken.IsChecked) { //Console.WriteLine(adapter.index.PadLeft(4, '0')); adapter.allowAwaken(); Console.WriteLine("\"运行网卡唤醒\"启用."); } if ((bool)cb_firewall.IsChecked) { firewall.disable(); Console.WriteLine("防火墙关闭."); } if ((bool)cb_zoom.IsChecked) { textZoom.DEFAULT(); Console.WriteLine("桌面缩放关闭."); } if ((bool)cb_swsoft_startup.IsChecked) { string drive = System.IO.Path.GetPathRoot(fileutils.path); switchSoft sw = new switchSoft(fileutils); string[] array = System.IO.Path.GetDirectoryName(sw.version).Split(new[] { @"\" }, StringSplitOptions.None); sw.version = drive + array.Last() + @"\" + sw.softName; sw.addStartup(); Console.WriteLine("\"开关机软件\"自启设置完成."); sw.runAsAdmin(); Console.WriteLine("\"开关机软件\"管理员权限设置完成."); //winupdate.enable(); } if ((bool)cb_fusion.IsChecked) { string source = @""; string target = @""; //fileutils.copyFolder(); } if ((bool)cb_vnc.IsChecked) { cb_state.vnc = true; } if ((bool)cb_klite.IsChecked) { cb_state.klite = true; } if ((bool)cb_power.IsChecked) { power.alwaysOn(); Console.WriteLine("电源常开设置完成."); } if (lv_uninstalled.Items != null) { cb_state.uninstall = lv_uninstalled.Items; } if ((bool)cb_office.IsChecked) { cb_state.office = true; } if (lv_dellnk.Items != null) { foreach (SHORTCUT item in lv_dellnk.Items) { File.Delete(item.path); lv_dellnk.Items.Remove(item); } } if (lv_delstartmenu.Items != null) { foreach (SHORTCUT item in lv_delstartmenu.Items) { File.Delete(item.path); lv_delstartmenu.Items.Remove(item); } } m_BackgroundWorker.RunWorkerAsync(cb_state); //cmd.ExecuteCommand("shutdown /r"); }