Winform 建立桌面快捷方式並開機啟動

2022-03-04 14:59:18 字數 1677 閱讀 3963

快捷方式實質上是乙個擴充套件名為 .lnk 的檔案

方法如下:

首先要新增引用 (如圖)

就是那個windows script host object model的類庫....

然後在程式中引入命名空間

using  iwshruntimelibrary;

有一些檔案操作,所有要引入

using  system.io;

關鍵方法如下:

///   

///  建立桌面快捷方式並開機啟動的方法

///   

注意:1.建立桌面快捷方式需要引用iwshruntimelibrary類庫

2.設定開機啟動需要使用microsoft.win32的registry類

using

system;

using

system.collections.generic;

using

system.componentmodel;

using

system.data;

using

system.drawing;

using

system.text;

using

system.windows.forms;

//-----------------------

using

system.io;

using

microsoft.win32;

using

iwshruntimelibrary;

namespace

private

void formoption_load(object

sender, eventargs e)

checkbox1.checked = (key.getvalue("

發貨審核

") != null

); key.close();

//檢查是否建立桌面快捷方式

bool b = system.io.file.exists(environment.getfolderpath(environment.specialfolder.desktopdirectory) +

"//" + "

發貨審核.lnk");

checkbox2.checked =b;

}private

void buttonoption_click(object

sender, eventargs e)

private

void runwhenstart(bool started, string name, string

path)

if (started == true)//

設定開機啟動

catch

(exception err)

}else

//取消開機啟動

}catch

(exception ex)}}

private

void createdesktoplink(bool

created)

}else}}

}}

建立桌面快捷方式

bool createdesktopshotcut cstring strname,在桌面顯示的名稱 cstring strsourcepath 檔案絕對路徑名稱 pshell release strdestdir.format s path strdestdir strdestdir strnam...

DELPHI建立桌面快捷方式

由於我們是通過ole inte ce實現此功能的,因此在程式單元的uses語句中要加入comobj activex和shlobj這三個單元。在單元的宣告部分加入以下 procedure createlink programpath,programarg,linkpath,descr string 其...

VC MFC 建立桌面快捷方式

bool createdesktopshotcut cstring strname,cstring strsourcepath int i char path max path 1 cstring strdestdir i csidl desktopdirectory lpitemidlist pi...