C 實現程式開機啟動

2021-05-23 08:52:25 字數 1181 閱讀 9697

如何用c#實現開機啟動?其實用c#實現程式的開機啟動大致有兩種方法,就是寫入登錄檔或者採用服務程式,最近一直研究著用c#來操作登錄檔,下面介紹的方法便是用登錄檔來實現程式隨開機啟動(高手就不用看了,嘿嘿...)。

1)引入命名空間 using microsoft.win32;

//開啟登錄檔子項

registrykey key = registry.localmachine.opensubke("software//microsoft//windows//currentversion//run",true);

key.setvalue(程式的名稱, 程式的路徑);//設定為開機啟動

為了安全性,還應該判斷設定的檔案是否存在以及該子項是否存在,所有完整**如下:

private void btnshowopen_click(object sender, eventargs e)}

private bool runwhenstart(bool started,string exename, string path)

if (started == true)

catch

}else

catch

}return true;}

private void btnset_click(object sender, eventargs e)

string path = txtpath.text.trim();

string exename = path.substring(path.lastindexof("//") + 1);

if (!file.exists(path))//檢查該檔案是否存在

if (runwhenstart(true,exename, path))

else}

private void btncancel_click(object sender, eventargs e)

string path = txtpath.text.trim();

string exename = path.substring(path.lastindexof("//") + 1);

if (!file.exists(path))//檢查該檔案是否存在

if (runwhenstart(false, exename, path))

else

}

C 實現程式開機自啟動

可以採用以下方式實現自啟動 拷貝到系統目錄 tchar temppath max path cstring temp getsystemdirectory temppath max path temp temppath temp temp t intranet.exe int len temp.ge...

C 實現程式開機自啟動

最近在做乙個自動備份檔案的小工具,需要用到開機自啟動 下面是 private void checkbox8 checkedchanged object sender,eventargs e 取消開機自啟動 else catch exception ex 第一種方法原理是直接把可執行檔案的快捷方式複製...

C 程式開機啟動

設定程式開機啟動,可以通過修改登錄檔將啟動資訊寫入登錄檔來實現。在 執行 中輸入 regedit 就可以開啟登錄檔。登錄檔左側的都是項,右邊列出值 一項可以對應 多個值 每個值對應 值名稱 和 值資料。c 為操作登錄檔提供了兩個類,registry和registrykey。registry提供提供靜...