2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
27 * ROUTINES ___________________________________________________________________
31 void Shortcut_Init (void)
37 void Shortcut_Exit (void)
43 BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc)
46 HRESULT rc = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
50 rc = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
53 rc = psl->SetPath (pszSource);
56 rc = psl->SetDescription (pszDesc ? pszDesc : pszSource);
60 rc = ppf->Save (pszTarget, TRUE);
63 MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, wsz, MAX_PATH);
64 rc = ppf->Save (wsz, TRUE);
72 return SUCCEEDED(rc) ? TRUE : FALSE;
76 void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
78 TCHAR szShortcut[ MAX_PATH ] = TEXT("");
81 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0)
83 DWORD dwSize = sizeof(szShortcut);
84 DWORD dwType = REG_SZ;
85 RegQueryValueEx (hk, TEXT("Common Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
86 if (szShortcut[0] == TEXT('\0'))
88 dwSize = sizeof(szShortcut);
90 RegQueryValueEx (hk, TEXT("Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
94 if (szShortcut[0] == TEXT('\0'))
96 GetWindowsDirectory (szShortcut, MAX_PATH);
97 lstrcat (szShortcut, TEXT("\\Start Menu\\Programs\\Startup"));
99 lstrcat (szShortcut, TEXT("\\"));
100 lstrcat (szShortcut, pszLinkName);
102 TCHAR szSource[ MAX_PATH ];
103 GetModuleFileName (GetModuleHandle(NULL), szSource, MAX_PATH);
107 Shortcut_Create (szShortcut, szSource);
109 else // (!g.fAutoStart)
111 DeleteFile (szShortcut);