Beispiel #1
0
        static void Main()
        {
            IntPtr handle = CreateToolhelp32Snapshot((uint)SnapShotFlags.TH32CS_SNAPPROCESS, 0);

            if ((int)handle != -1)
            {
                PROCESSENTRY32 pe32 = new PROCESSENTRY32();
                pe32.dwSize = (uint)Marshal.SizeOf(typeof(PROCESSENTRY32));
                int            bMore = Process32First(handle, ref pe32);
                PROCESSENTRY32 pe;
                string         servername = "";
                while (bMore == 1)
                {
                    IntPtr temp = Marshal.AllocHGlobal((int)pe32.dwSize);
                    Marshal.StructureToPtr(pe32, temp, true);
                    pe = (PROCESSENTRY32)Marshal.PtrToStructure(temp, typeof(PROCESSENTRY32));
                    Marshal.FreeHGlobal(temp);
                    //MessageBox.Show(pe32.szExeFile);
                    if (pe32.szExeFile == "PDA.exe")
                    {
                        if (servername == "")
                        {
                            servername = pe32.szExeFile;
                        }
                        else if (servername == "PDA.exe")
                        {
                            return;
                        }
                    }
                    bMore = Process32Next(handle, ref pe32);
                }
            }
            CloseHandle(handle);

            if (Directory.Exists(FunPublic.CurrentPath + "/temp") == false)
            {
                Directory.CreateDirectory(FunPublic.CurrentPath + "/temp");
            }
            if (System.IO.File.Exists(FunPublic.CurrentPath + "\\Update.exe"))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(FunPublic.CurrentPath + "\\SysConfig.xml");
                string strFtpAddress = doc.SelectSingleNode(@"SystemConfig/Server/Url").InnerText.Trim(); //更新的网站的服务器地址
                strFtpAddress = strFtpAddress.Remove(strFtpAddress.LastIndexOf("/") + 1, 15) + "PDA";
                string version = doc.SelectSingleNode(@"SystemConfig/Version").InnerText.Trim();          //版本号
                //下载xml配置文件
                HttpWebRequest         Request  = (HttpWebRequest)System.Net.WebRequest.Create(strFtpAddress + "/SysConfig.xml");
                HttpWebResponse        Response = (HttpWebResponse)(WebResponse)Request.GetResponse();
                System.IO.BinaryReader sr       = new BinaryReader(Response.GetResponseStream());
                long         fileLenth          = Response.ContentLength;
                byte[]       content            = sr.ReadBytes((Int32)fileLenth);
                FileStream   so         = new FileStream(FunPublic.CurrentPath + "/temp/" + "SysConfig.xml", FileMode.Create);
                BinaryWriter fileWriter = new BinaryWriter(so);
                fileWriter.Write(content, 0, (Int32)fileLenth);
                fileWriter.Close();
                //下载xml文件结束
                doc.Load(FunPublic.CurrentPath + "/temp/" + "SysConfig.xml");
                if (doc.SelectSingleNode(@"SystemConfig/Version").InnerText.Trim() != version)
                {
                    if (MessageBox.Show("检测到有新版本,是否更新程序?", "消息框", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                    {
                        System.Diagnostics.Process.Start(FunPublic.CurrentPath + "/Update.exe", null);
                        System.Diagnostics.Process.GetCurrentProcess().Kill();
                    }
                }
            }
            FrmPDALogin FrmPDALogin = new FrmPDALogin();

            FrmPDALogin.ShowDialog();
            if (FrmPDALogin.DialogResult == DialogResult.OK)
            {
                Application.Run(new FrmMenu());
            }
            else
            {
                return;
            }
        }
Beispiel #2
0
 public static extern int Process32Next(IntPtr handle, ref PROCESSENTRY32 pe);