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
14 #include <afsconfig.h>
15 #include <afs/param.h>
34 * ROUTINES ___________________________________________________________________
38 void Shortcut_Init (void)
40 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
44 void Shortcut_Exit (void)
49 BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc, LPTSTR pszArgs)
52 HRESULT rc = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
56 rc = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
59 rc = psl->SetPath (pszSource);
62 rc = psl->SetDescription (pszDesc ? pszDesc : pszSource);
66 rc = psl->SetArguments (pszArgs);
70 rc = ppf->Save (pszTarget, TRUE);
73 MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, (LPWSTR)wsz, MAX_PATH);
74 rc = ppf->Save ((LPCOLESTR)wsz, TRUE);
83 return SUCCEEDED(rc) ? TRUE : FALSE;
87 BOOL Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
89 TCHAR szShortcut[ MAX_PATH + 10 ] = TEXT("");
93 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0)
95 DWORD dwSize = sizeof(szShortcut);
96 DWORD dwType = REG_SZ;
97 RegQueryValueEx (hk, TEXT("Common Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
98 if (szShortcut[0] == TEXT('\0'))
100 dwSize = sizeof(szShortcut);
102 RegQueryValueEx (hk, TEXT("Startup"), NULL, &dwType, (LPBYTE)szShortcut, &dwSize);
106 if (szShortcut[0] == TEXT('\0'))
108 GetWindowsDirectory (szShortcut, MAX_PATH);
109 lstrcat (szShortcut, TEXT("\\Start Menu\\Programs\\Startup"));
111 lstrcat (szShortcut, TEXT("\\"));
112 lstrcat (szShortcut, pszLinkName);
114 TCHAR szSource[ MAX_PATH ];
115 GetModuleFileName (GetModuleHandle(NULL), szSource, MAX_PATH);
119 DWORD code, len, type;
120 TCHAR szParams[ 64 ] = TEXT(AFSCREDS_SHORTCUT_OPTIONS);
122 code = RegOpenKeyEx(HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY,
123 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk);
124 if (code == ERROR_SUCCESS) {
125 len = sizeof(szParams);
127 code = RegQueryValueEx(hk, "AfscredsShortcutParams", NULL, &type,
128 (BYTE *) &szParams, &len);
131 if (code != ERROR_SUCCESS) {
132 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
133 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk);
134 if (code == ERROR_SUCCESS) {
135 len = sizeof(szParams);
137 code = RegQueryValueEx(hk, "AfscredsShortcutParams", NULL, &type,
138 (BYTE *) &szParams, &len);
142 bSuccess = Shortcut_Create (szShortcut, szSource, "Autostart Authentication Agent", szParams);
144 else // (!g.fAutoStart)
146 bSuccess = DeleteFile (szShortcut);