Beispiel #1
0
        public static bool GetDeviceSetting(ref DeviceSettingConfig config)
        {
            RegistryKey myRKCN = Registry.LocalMachine.OpenSubKey("SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters");

            foreach (string myCpName in myRKCN.GetValueNames())
            {
                if (myCpName == "NV Hostname")
                {
                    config.PCName = myRKCN.GetValue(myCpName).ToString();
                    break;
                }
            }
            ManagementClass            mc   = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection nics = mc.GetInstances();

            foreach (ManagementObject nic in nics)
            {
                if (!(bool)nic["IPEnabled"])
                {
                    continue;
                }
                if (nic["IPAddress"] != null)
                {
                    config.IP = (nic["IPAddress"] as String[])[0];
                }
                if (nic["IPSubnet"] != null)
                {
                    config.Mask = (nic["IPSubnet"] as String[])[0];
                }
                if (nic["DefaultIPGateway"] != null)
                {
                    config.Gateway = (nic["DefaultIPGateway"] as String[])[0];
                }
                if (nic["DNSServerSearchOrder"] != null)
                {
                    config.DNS = (nic["DNSServerSearchOrder"] as String[])[0];
                }
                break;
            }
            if (config.IP == "" || config.IP == "0.0.0.0")
            {
                config.IsStaticIP = false;
            }
            return(true);
        }
Beispiel #2
0
 private void button22_Click(object sender, EventArgs e)
 {
     Code.DeviceSettingConfig config = new Code.DeviceSettingConfig();
     config.IP         = txt_d_IP.Text;
     config.DNS        = txt_d_dns.Text;
     config.Gateway    = txt_d_getway.Text;
     config.Mask       = txt_d_mask.Text;
     config.PCName     = txt_pc_name.Text;
     config.IsStaticIP = cb_staticIP.Checked;
     if (Code.DeviceSetting.SaveDeviceSetting(config))
     {
         MessageBox.Show("设置成功!");
     }
     else
     {
         MessageBox.Show("设置失败!");
     }
 }
Beispiel #3
0
        public static bool SaveDeviceSetting(DeviceSettingConfig config)
        {
            try
            {
                string        fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;
                StringBuilder shutdownbat       = new StringBuilder();
                string        path = fileDircetoryPath + "DeviceSetting.bat";
                shutdownbat.AppendLine("rem 修改用户密码");
                shutdownbat.AppendLine("net user Administrator jsddgx");
                shutdownbat.AppendLine("rem 设置自动登录");
                shutdownbat.AppendLine("reg add \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\" /v DefaultUserName /t reg_sz /d Administrator /f");
                shutdownbat.AppendLine("reg add  \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\" /v DefaultPassword /t reg_sz /d jsddgx /f");
                shutdownbat.AppendLine("reg add  \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\" /v AutoAdminLogon /t reg_sz /d 1 /f");
                shutdownbat.AppendLine("rem 结束未响应程序");
                shutdownbat.AppendLine("reg add \"HKEY_USERS\\.DEFAULT\\Control Panel\\Desktop\\\" /v AutoEndTasks /t reg_sz /d 1 /f ");
                shutdownbat.AppendLine("reg add \"HKEY_CURRENT_USER\\Control Panel\\Desktop\" /v AutoEndTasks /t reg_sz /d 1 /f");
                shutdownbat.AppendLine("rem 清空屏幕信息......");
                shutdownbat.AppendLine("cls");
                shutdownbat.AppendLine("rem 思路是:直接删除气球键,最后添加该键值");
                shutdownbat.AppendLine("echo 删除气球注册键......");
                shutdownbat.AppendLine("reg delete \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\" /v \"EnableBalloonTips\" /f");
                shutdownbat.AppendLine("echo 删除气球注册键成功......");
                shutdownbat.AppendLine("echo 添加气球注册键及键值......");
                shutdownbat.AppendLine("reg add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\" /v \"EnableBalloonTips\" /t REG_DWORD /d 00000000 /f");
                shutdownbat.AppendLine("echo 添加气球注册键成功......");
                shutdownbat.AppendLine("echo 去除气球提示成功......");
                shutdownbat.AppendLine("echo 开启远程桌面");
                shutdownbat.AppendLine("reg add \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\"  /v fDenyTSConnections /t REG_DWORD /d 0  /f");
                if (!File.Exists(path))
                {
                    FileStream fs = File.Create(path);
                    fs.Close();
                }
                StreamWriter sw = new StreamWriter(path, false, Encoding.GetEncoding("GB2312"));
                sw.Write(shutdownbat);
                sw.Flush();
                sw.Close();
                System.Diagnostics.Process.Start(fileDircetoryPath + "DeviceSetting.bat");

                IWshRuntimeLibrary.WshShell     shell    = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup) + "\\" + "终端启动程序.lnk");
                shortcut.TargetPath  = fileDircetoryPath + "终端启动程序.exe";
                shortcut.WindowStyle = 1;
                shortcut.Save();

                RegistryKey myRKCN = Registry.LocalMachine.OpenSubKey("SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters", true);
                foreach (string site in myRKCN.GetValueNames())
                {
                    if (site == "NV Hostname")
                    {
                        myRKCN.DeleteValue(site, false);
                        myRKCN.SetValue("NV Hostname", config.PCName);
                        break;
                    }
                }
                ManagementBaseObject       inPar  = null;
                ManagementBaseObject       outPar = null;
                ManagementClass            mc     = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc    = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    if (!(bool)mo["IPEnabled"])
                    {
                        continue;
                    }
                    if (config.IsStaticIP)
                    {
                        //设置ip地址和子网掩码
                        inPar = mo.GetMethodParameters("EnableStatic");
                        inPar["IPAddress"]  = new string[] { config.IP };
                        inPar["SubnetMask"] = new string[] { config.Mask };
                        outPar = mo.InvokeMethod("EnableStatic", inPar, null);

                        //设置网关地址
                        inPar = mo.GetMethodParameters("SetGateways");
                        inPar["DefaultIPGateway"] = new string[] { config.Gateway };
                        outPar = mo.InvokeMethod("SetGateways", inPar, null);

                        //设置DNS
                        inPar = mo.GetMethodParameters("SetDNSServerSearchOrder");
                        inPar["DNSServerSearchOrder"] = new string[] { config.DNS };
                        outPar = mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null);
                        break;
                    }
                    else
                    {
                        inPar  = mo.GetMethodParameters("EnableDHCP");
                        outPar = mo.InvokeMethod("EnableDHCP", inPar, null);
                        inPar  = mo.GetMethodParameters("SetDNSServerSearchOrder");
                        inPar["DNSServerSearchOrder"] = null;
                        outPar = mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null);
                        break;
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                SeatManageComm.WriteLog.Write("保存终端设置失败!" + ex.Message);
                return(false);
            }
        }
Beispiel #4
0
        private void SeatManageConfigTool_Load(object sender, EventArgs e)
        {
            Code.HostConfig             hostconfig          = new Code.HostConfig();
            Code.ClientBasicConfig      clientconfig        = new Code.ClientBasicConfig();
            Code.CardReaderBasicConfig  cardReaderConfig    = new Code.CardReaderBasicConfig();
            Code.WebConfigSetting       webConfigSeeting    = new Code.WebConfigSetting();
            Code.LeaveClientBesicConfig leaveConfigSetting  = new Code.LeaveClientBesicConfig();
            Code.DeviceSettingConfig    deviceSettingConfig = new Code.DeviceSettingConfig();
            Code.ShutDownConfig         shutDownConfig      = new Code.ShutDownConfig();
            if (Code.ReadSeatHostConfigV3.ReadConfig(ref hostconfig))
            {
                foreach (string server in hostconfig.HostServer)
                {
                    if (server == "WcfHost")
                    {
                        cb_WCF.Checked = true;
                    }
                    else if (server == "MonitorService")
                    {
                        cb_Watch.Checked = true;
                    }
                    else if (server == "DataTransferService")
                    {
                        cb_DT.Checked = true;
                    }
                }
                txt_DBIP.Text               = hostconfig.DBIP;
                txt_DBName.Text             = hostconfig.DBName;
                txt_DBpw.Text               = hostconfig.DBPW;
                txt_DBUser.Text             = hostconfig.DBUser;
                txt_SeverWCFConnString.Text = hostconfig.WCFString;
                txt_weixinendportwcf.Text   = hostconfig.WeChatWCFString;
                txt_FilePath.Text           = hostconfig.MediaFilePath;
                txt_ServerSchoolNo.Text     = hostconfig.SchoolNo;
                txt_ServerLoopTime.Text     = hostconfig.LoopTime;
                txt_Uploadtime.Text         = hostconfig.UploadTime;
                if (Code.WebConfig.ReadConfig(ref webConfigSeeting))
                {
                    cb_web_pw_change.Checked = webConfigSeeting.IsChangePW;
                }
                else
                {
                    MessageBox.Show("无法自动获取管理网站配置文件,请确保和Host服务文件夹放置在同一目录,并且文件夹为“SeatManageWebV5”");
                    gb_web.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[3].Controls)
                {
                    c.Enabled = false;
                }
            }
            else if (Code.ReadSeatClientConfig.GetSeatClientBaseConfig(ref clientconfig) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Select"))
            {
                clientmode = "Select";
                txt_clientwcfstring.Text = clientconfig.WCFConnString;
                txt_schoolno.Text        = clientconfig.SchoolNo;
                txt_campusno.Text        = clientconfig.CampusNo;
                txt_deviceno.Text        = clientconfig.TerminalNum;
                txt_defualtmedia.Text    = clientconfig.DefaultMedia;
                txt_adloop.Text          = clientconfig.SCLoopTime;
                txt_sentloop.Text        = clientconfig.SentStatusTime;
                txt_update.Text          = clientconfig.UpdateTime;
                txt_mac.Text             = GetMacAddress.GetLocalAddress()[0];
                gb_xzx.Enabled           = false;
                gb_mh.Enabled            = false;
                gb_fk.Enabled            = false;
                gb_gz.Enabled            = false;
                gb_cut.Enabled           = false;
                gb_dz.Enabled            = false;

                switch (cardReaderConfig.CardReaderTye)
                {
                case 0: rb_mh.Checked = true; break;

                case 1: rb_xzx.Checked = true; break;

                case 2: rb_fk.Checked = true; break;

                case 3: rb_gz.Checked = true; break;

                case 4: rb_cut.Checked = true; break;

                case 5: rb_dz.Checked = true; break;
                }
                if (cardReaderConfig.CardID10Or16 == 10)
                {
                    fk_10.Checked = true;
                    rb_10.Checked = true;
                }
                else
                {
                    fk_16.Checked = true;
                    rb_16.Checked = true;
                }
                cb_Isbeep.Checked     = cardReaderConfig.IsBeep;
                fk_port.Text          = cardReaderConfig.FKport;
                txt_xzx_ip.Text       = cardReaderConfig.XZX_ServerEndPort;
                txt_xzx_sys.Text      = cardReaderConfig.XZX_SysCode;
                txt_xzx_tre.Text      = cardReaderConfig.XZX_TerminalNo;
                xzx_addreader.Checked = cardReaderConfig.XZX_AddReader;
                xzx_off.Checked       = cardReaderConfig.XZX_Offline;
                if (cardReaderConfig.Hook_isCardNo)
                {
                    rb_gz_cardno.Checked = true;
                }
                else
                {
                    rb_gz_cardid.Checked = true;
                }
                if (cardReaderConfig.XZX_IsOnelyReaderCardId)
                {
                    rb_xzx_readcardid.Checked = true;
                }
                else
                {
                    rb_xzx_readcardno.Checked = true;
                }
                cb_change.Checked = cardReaderConfig.CardIDIsChange;
                fk_change.Checked = cardReaderConfig.CardIDIsChange;
                cb_add0.Checked   = cardReaderConfig.IsAdd0;
                fk_add0.Checked   = cardReaderConfig.IsAdd0;

                if (Code.DeviceSetting.GetDeviceSetting(ref deviceSettingConfig))
                {
                    txt_d_IP.Text       = deviceSettingConfig.IP;
                    txt_d_dns.Text      = deviceSettingConfig.DNS;
                    txt_d_getway.Text   = deviceSettingConfig.Gateway;
                    txt_d_mask.Text     = deviceSettingConfig.Mask;
                    txt_pc_name.Text    = deviceSettingConfig.PCName;
                    cb_staticIP.Checked = deviceSettingConfig.IsStaticIP;
                }
                if (Code.DeviceSetting.GetShotDownSetting(ref shutDownConfig))
                {
                    cb_sd.Checked = shutDownConfig.IsUsed;
                    txt_sd_h.Text = shutDownConfig.ShutDownHour;
                    txt_sd_m.Text = shutDownConfig.ShutDownMin;
                    txt_sd_s.Text = shutDownConfig.ShutDownWaitSec;
                }
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                tabControl1.SelectedIndex = 1;
            }
            else if (Code.LeaveClientConfig.GetLeaveClientConfig(ref leaveConfigSetting) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Leave"))
            {
                clientmode             = "Leave";
                txt_leave_wcfconn.Text = leaveConfigSetting.WCFConnString;
                switch (leaveConfigSetting.LeaveMode)
                {
                case "0": rb_leave_s.Checked = true; break;

                case "1": rb_leave_sl.Checked = true; break;

                case "2": rb_leave_l.Checked = true; break;

                case "3": rb_leave_s.Checked = true; break;
                }
                if (leaveConfigSetting.SetUpMode == "1")
                {
                    rb_win_max.Checked = true;
                }
                else
                {
                    rb_win_min.Checked = true;
                }
                gb_xzx.Enabled = false;
                gb_mh.Enabled  = false;
                gb_fk.Enabled  = false;
                gb_gz.Enabled  = false;
                gb_cut.Enabled = false;
                gb_dz.Enabled  = false;

                switch (cardReaderConfig.CardReaderTye)
                {
                case 0: rb_mh.Checked = true; break;

                case 1: rb_xzx.Checked = true; break;

                case 2: rb_fk.Checked = true; break;

                case 3: rb_gz.Checked = true; break;

                case 4: rb_cut.Checked = true; break;

                case 5: rb_dz.Checked = true; break;
                }
                if (cardReaderConfig.CardID10Or16 == 10)
                {
                    fk_10.Checked = true;
                    rb_10.Checked = true;
                }
                else
                {
                    fk_16.Checked = true;
                    rb_16.Checked = true;
                }
                cb_Isbeep.Checked     = cardReaderConfig.IsBeep;
                fk_port.Text          = cardReaderConfig.FKport;
                txt_xzx_ip.Text       = cardReaderConfig.XZX_ServerEndPort;
                txt_xzx_sys.Text      = cardReaderConfig.XZX_SysCode;
                txt_xzx_tre.Text      = cardReaderConfig.XZX_TerminalNo;
                xzx_addreader.Checked = cardReaderConfig.XZX_AddReader;
                xzx_off.Checked       = cardReaderConfig.XZX_Offline;
                if (cardReaderConfig.Hook_isCardNo)
                {
                    rb_gz_cardno.Checked = true;
                }
                else
                {
                    rb_gz_cardid.Checked = true;
                }
                if (cardReaderConfig.XZX_IsOnelyReaderCardId)
                {
                    rb_xzx_readcardid.Checked = true;
                }
                else
                {
                    rb_xzx_readcardno.Checked = true;
                }
                cb_change.Checked = cardReaderConfig.CardIDIsChange;
                fk_change.Checked = cardReaderConfig.CardIDIsChange;
                cb_add0.Checked   = cardReaderConfig.IsAdd0;
                fk_add0.Checked   = cardReaderConfig.IsAdd0;
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                tabControl1.SelectedIndex = 2;
            }
            else
            {
                MessageBox.Show("获取配置文件失败,请把配置工具拷贝到宿主服务或者终端的根目录下,再次尝试!");
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[3].Controls)
                {
                    c.Enabled = false;
                }
                btnBackupProgram.Enabled  = false;
                tabControl1.SelectedIndex = 4;
            }
        }