void __fastcall TFMain::CreateDesktopShortCut(const AnsiString sMyFileName,const AnsiString ShortCutName)<br>{<br> char sShortCutLink[1024];<br> AnsiString sFileName;<br> char szBuffer[1024];<br> char szShortCutDesc[80];<br> char *pPos;<br> GetSystemDirectory(szBuffer, 1023);<br> strupr(szBuffer);<br> pPos = strstr(szBuffer, "SYSTEM");<br> if (pPos != NULL)<br> *pPos = '/0';<br><br> strcat(szBuffer, "Desktop");<br> sFileName="//"+ShortCutName;<br><br> //pPos = strrchr(sFileName.c_str(), '//');<br> //if (pPos != NULL)<br> //StrPCopy(sFileName.c_str(), pPos);<br> // sFileName=pPos;<br> strcpy(szShortCutDesc, "&Iacute;&otilde;&Oacute;&brvbar;&Auml;&Iuml;±à&ETH;&acute;");<br> strcat(szBuffer, "//");<br> strcpy(sShortCutLink, szBuffer);<br> strcat(sShortCutLink, sFileName.c_str());<br><br> //pPos = strchr(sShortCutLink, '.');<br> //if (pPos != NULL)<br> // *pPos = '/0';<br> strcat(sShortCutLink, ".LNK");<br> CreateShortCut(sMyFileName.c_str(), sShortCutLink, szShortCutDesc);<br>}<br>void __fastcall TFMain::CreateShortCut(char *pFileName, char *pLink, char*pDesc)<br>{<br> IShellLink *psl;<br> IPersistFile *ppf;<br> wchar_t szWChar[1024];<br><br> try<br> {<br> OleCheck(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,<br> IID_IShellLink, (void **) &psl) );<br> try<br> {<br> OleCheck(psl->QueryInterface(IID_IPersistFile, (void **) &ppf) );<br> OleCheck(psl->SetDescription(pDesc));<br> OleCheck(psl->SetPath(pFileName));<br> MultiByteToWideChar(CP_ACP, 0, pLink, -1, szWChar, 1023);<br> OleCheck(ppf->Save(szWChar, TRUE));<br> }<br> catch (...)<br> {<br> ppf->Release();<br> }<br> ppf->Release();<br> }<br> catch(...)<br> {<br> psl->Release();<br> }<br> psl->Release();<br>}<br><br><br><br><br><br><br> CreateDesktopShortCut(Application->ExeName,"test");<br> CreateDesktopShortCut(ExtractFilePath(Application->ExeName)+"MainDelprj.exe","test");<br>