1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
string appPath = w2s(getAppPath()) + "videoHelper.exe"; CreatLink2startupFolder(appPath,"videoHelper");
deleteLinkFromStarupFolder("videoHelper.lnk");
BOOL (string linkName) { CHAR szStartPath[MAX_PATH] = { 0 }; SHGetSpecialFolderPathA(NULL, szStartPath, CSIDL_STARTUP, 0); string path = &szStartPath[0]; path += "\" + linkName; return DeleteFileA(path.c_str()); }
bool CreatLink2startupFolder(string appPath, string linkName) { string appName = "\" + linkName + ".lnk"; HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { IShellLink *pisl; hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pisl); if (SUCCEEDED(hr)) { IPersistFile* pIPF;
pisl->SetPath(s2w(appPath).c_str()); hr = pisl->QueryInterface(IID_IPersistFile, (void**)&pIPF); if (SUCCEEDED(hr)) { CHAR szStartPath[MAX_PATH] = { 0 }; SHGetSpecialFolderPathA(NULL, szStartPath, CSIDL_STARTUP, 0); strcat_s(szStartPath,MAX_PATH, appName.c_str());
USES_CONVERSION; LPCOLESTR lpOleStr = A2COLE(szStartPath); pIPF->Save(lpOleStr, FALSE); pIPF->Release(); } pisl->Release(); } CoUninitialize(); }
return true; }
|
近期评论