4 gcc -o create-links -D_WIN32_IE=0x400 create-links.c -lole32 -luuid -lshell32 -lshlwapi
6 Martin Fuchs, 27.12.2003
10 #define WIN32_LEAN_AND_MEAN
19 HRESULT
CreateShellLink(LPCSTR linkPath
, LPCSTR cmd
, LPCSTR arg
, LPCSTR dir
, LPCSTR iconPath
, int icon_nr
, LPCSTR comment
)
23 WCHAR buffer
[MAX_PATH
];
25 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
27 printf("creating shortcut file '%s' to %s...\n", linkPath
, cmd
);
30 hr
= psl
->lpVtbl
->SetPath(psl
, cmd
);
33 hr
= psl
->lpVtbl
->SetArguments(psl
, arg
);
36 hr
= psl
->lpVtbl
->SetWorkingDirectory(psl
, dir
);
39 hr
= psl
->lpVtbl
->SetIconLocation(psl
, iconPath
, icon_nr
);
42 hr
= psl
->lpVtbl
->SetDescription(psl
, comment
);
44 hr
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
47 MultiByteToWideChar(CP_ACP
, 0, linkPath
, -1, buffer
, MAX_PATH
);
49 hr
= ppf
->lpVtbl
->Save(ppf
, buffer
, TRUE
);
51 ppf
->lpVtbl
->Release(ppf
);
54 psl
->lpVtbl
->Release(psl
);
60 printf("error %08x\n\n", (int) hr
);
73 /* create some shortcuts in the start menu "programs" folder */
74 SHGetSpecialFolderPathA(0, path
, CSIDL_PROGRAMS
, TRUE
);
75 p
= PathAddBackslash(path
);
77 strcpy(p
, "start-cmd.lnk");
78 CreateShellLink(path
, "cmd.exe", "", NULL
, NULL
, 0, "open console window");
80 strcpy(p
, "start-winhello.lnk");
81 CreateShellLink(path
, "winhello.exe", "", NULL
, NULL
, 0, "launch winhello");
84 /* create some shortcuts on the desktop */
85 SHGetSpecialFolderPathA(0, path
, CSIDL_DESKTOP
, TRUE
);
86 p
= PathAddBackslash(path
);
88 strcpy(p
, "start-wcmd.lnk");
89 CreateShellLink(path
, "cmd.exe", "", NULL
, NULL
, 0, "open console window");
91 strcpy(p
, "start-winemine.lnk");
92 CreateShellLink(path
, "winemine.exe", "", NULL
, NULL
, 0, "launch winemine");