應業務需求,程序須要與系統啓動而自動運行,故加入如下代碼,保存成 .bat文件 ,雙擊執行便可app
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v HuazhuPushRecord /t reg_sz /d "your app path/app.exe" /f echo "成功添加開機啓動 you app.exe" your app.exe
有些時候,窗口程序須要隱藏,防止誤關閉致使程序不運行,故添加如下代碼,可避免這種狀況ide
[DllImport("User32.dll", EntryPoint = "FindWindow")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint = "FindWindowEx")] //找子窗體 private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("User32.dll", EntryPoint = "SendMessage")] //用於發送信息給窗體 private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); [DllImport("User32.dll", EntryPoint = "ShowWindow")] // private static extern bool ShowWindow(IntPtr hWnd, int type); public static void WindowHide() { Console.Title = "youappname"; IntPtr ParenthWnd = new IntPtr(0); IntPtr et = new IntPtr(0); ParenthWnd = FindWindow(null, "youappname"); ShowWindow(ParenthWnd, 0);//隱藏本dos窗體, 0: 後臺執行;1:正常啓動;2:最小化到任務欄;3:最大化 }