1、新建一個(gè)類,設(shè)置一個(gè)操作注冊(cè)表的方法;
成都創(chuàng)新互聯(lián)公司是工信部頒發(fā)資質(zhì)IDC服務(wù)器商,為用戶提供優(yōu)質(zhì)的綿陽(yáng)機(jī)房托管服務(wù)
2、在程序中調(diào)用這個(gè)方法。true就自動(dòng)啟動(dòng),false就刪除自動(dòng)啟動(dòng)。
- public static bool RunWhenStart(bool started, string exeName, string path)
- { //started是否開(kāi)機(jī)啟動(dòng),exeName應(yīng)用程序名稱,path應(yīng)用程序路徑
- RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//打開(kāi)注冊(cè)表子項(xiàng)
- if (key == null) //如果該項(xiàng)不存在的話,則創(chuàng)建該子項(xiàng)
- {
- key = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
- }
- if (started == true)
- {
- try
- {
- key.SetValue(exeName, path);//設(shè)置為開(kāi)機(jī)啟動(dòng)
- key.Close();
- }
- catch
- {
- return false;
- }
- }
- else
- {
- try
- {
- key.DeleteValue(exeName);//取消開(kāi)機(jī)啟動(dòng)
- key.Close();
- }
- catch
- {
- return false;
- }
- }
- return true;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- if (Autorun == "true")
- {
- function.RunWhenStart(true, "51cto.iego.net", Application.ExecutablePath);
- }
- else
- {
- function.RunWhenStart(false, "51cto.iego.net", Application.ExecutablePath);
- }
- }
文章標(biāo)題:C#制作開(kāi)機(jī)自動(dòng)啟動(dòng)程序
本文鏈接:http://jinyejixie.com/article12/ppsedc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、云服務(wù)器、虛擬主機(jī)、軟件開(kāi)發(fā)、網(wǎng)頁(yè)設(shè)計(jì)公司、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)