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>
25 * ROUTINES ___________________________________________________________________
29 void Shortcut_Init (void)
35 void Shortcut_Exit (void)
41 BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc)
44 HRESULT rc = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
48 rc = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
51 rc = psl->SetPath (pszSource);
54 rc = psl->SetDescription (pszDesc ? pszDesc : pszSource);
58 rc = ppf->Save (pszTarget, TRUE);
61 MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, wsz, MAX_PATH);
62 rc = ppf->Save (wsz, TRUE);
70 return SUCCEEDED(rc) ? TRUE : FALSE;
74 void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
76 TCHAR szShortcut[ MAX_PATH ] = TEXT("");
79 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0)
81 DWORD dwSize = sizeof(szShortcut);
82 DWORD dwType = REG_SZ;
83 RegQueryValueEx (hk, TEXT("Common Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
84 if (szShortcut[0] == TEXT('\0'))
86 dwSize = sizeof(szShortcut);
88 RegQueryValueEx (hk, TEXT("Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
92 if (szShortcut[0] == TEXT('\0'))
94 GetWindowsDirectory (szShortcut, MAX_PATH);
95 lstrcat (szShortcut, TEXT("\\Start Menu\\Programs\\Startup"));
97 lstrcat (szShortcut, TEXT("\\"));
98 lstrcat (szShortcut, pszLinkName);
100 TCHAR szSource[ MAX_PATH ];
101 GetModuleFileName (GetModuleHandle(NULL), szSource, MAX_PATH);
105 Shortcut_Create (szShortcut, szSource);
107 else // (!g.fAutoStart)
109 DeleteFile (szShortcut);