搞C++的改玩VBS了哦- /*
- * Author: Demon
- * Date: 2012/6/25
- * Website: http://demon.tw
- * Description: create shorcut using C++, no error handling for simplicity
- */
- #include <Windows.h>
- #include <shlobj.h>
- #include <Shlwapi.h>
- #pragma comment(lib, "Shlwapi.lib")
-
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
- {
- IShellLink *pShellLink;
- IPersistFile *pPersistFile;
- WCHAR TargetPath[MAX_PATH], WorkingDirectory[MAX_PATH], Desktop[MAX_PATH];
- LPITEMIDLIST p;
-
- CoInitialize(NULL);
- CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&pShellLink);
-
- GetModuleFileName(NULL, TargetPath, MAX_PATH);
- PathRemoveFileSpec(TargetPath);
- lstrcpyn(WorkingDirectory, TargetPath, MAX_PATH);
- PathAppend(TargetPath, L"gf.exe");
-
- pShellLink->SetPath(TargetPath);
- pShellLink->SetShowCmd(SW_SHOWNORMAL);
- pShellLink->SetHotkey(MAKEWORD(0x45, HOTKEYF_CONTROL | HOTKEYF_ALT));
- pShellLink->SetIconLocation(TargetPath, 0);
- pShellLink->SetDescription(L"快捷方式");
- pShellLink->SetWorkingDirectory(WorkingDirectory);
-
- pShellLink->QueryInterface(IID_IPersistFile, (void **)&pPersistFile);
- SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &p);
- SHGetPathFromIDList(p, Desktop);
- PathAppend(Desktop, L"lingdong.lnk");
- pPersistFile->Save(Desktop, TRUE);
-
- pShellLink->Release();
- pPersistFile->Release();
- CoUninitialize();
- return 0;
- }
复制代码
|