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>
29 * ROUTINES ___________________________________________________________________
33 void Shortcut_Init (void)
39 void Shortcut_Exit (void)
44 BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc, LPTSTR pszArgs)
47 HRESULT rc = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
51 rc = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
54 rc = psl->SetPath (pszSource);
57 rc = psl->SetDescription (pszDesc ? pszDesc : pszSource);
61 rc = psl->SetArguments (pszArgs);
65 rc = ppf->Save (pszTarget, TRUE);
68 MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, wsz, MAX_PATH);
69 rc = ppf->Save (wsz, TRUE);
78 return SUCCEEDED(rc) ? TRUE : FALSE;
82 void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
84 TCHAR szShortcut[ MAX_PATH + 10 ] = TEXT("");
87 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0)
89 DWORD dwSize = sizeof(szShortcut);
90 DWORD dwType = REG_SZ;
91 RegQueryValueEx (hk, TEXT("Common Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
92 if (szShortcut[0] == TEXT('\0'))
94 dwSize = sizeof(szShortcut);
96 RegQueryValueEx (hk, TEXT("Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
100 if (szShortcut[0] == TEXT('\0'))
102 GetWindowsDirectory (szShortcut, MAX_PATH);
103 lstrcat (szShortcut, TEXT("\\Start Menu\\Programs\\Startup"));
105 lstrcat (szShortcut, TEXT("\\"));
106 lstrcat (szShortcut, pszLinkName);
108 TCHAR szSource[ MAX_PATH ];
109 GetModuleFileName (GetModuleHandle(NULL), szSource, MAX_PATH);
113 DWORD code, len, type;
114 TCHAR szParams[ 64 ] = TEXT(AFSCREDS_SHORTCUT_OPTIONS);
116 code = RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_OPENAFS_CLIENT,
117 0, KEY_QUERY_VALUE, &hk);
118 if (code != ERROR_SUCCESS)
119 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_OPENAFS_CLIENT,
120 0, KEY_QUERY_VALUE, &hk);
121 if (code == ERROR_SUCCESS) {
122 len = sizeof(szParams);
124 code = RegQueryValueEx(hk, "AfscredsShortcutParams", NULL, &type,
125 (BYTE *) &szParams, &len);
128 Shortcut_Create (szShortcut, szSource, "Autostart Authentication Agent", szParams);
130 else // (!g.fAutoStart)
132 DeleteFile (szShortcut);