afscreds-shortcut-params-20040227
[openafs.git] / src / WINNT / client_creds / shortcut.cpp
index cb0123d..9508dd2 100644 (file)
@@ -16,10 +16,12 @@ extern "C" {
 #include <initguid.h>
 #include <windows.h>
 #include <windowsx.h>
+#undef INITGUID
 #include <shlobj.h>
 #include <shellapi.h>
 #include <shobjidl.h>
 #include <shlguid.h>
+#include "afscreds.h"
 #include "shortcut.h"
 
 
@@ -39,8 +41,9 @@ void Shortcut_Exit (void)
    CoUninitialize();
 }
 
+static char OpenAFSConfigKeyName[] = "SOFTWARE\\OpenAFS\\Client";
 
-BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc)
+BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc, LPTSTR pszArgs)
 {
    IShellLink *psl;
    HRESULT rc = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
@@ -56,13 +59,18 @@ BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc)
             rc = psl->SetDescription (pszDesc ? pszDesc : pszSource);
             if (SUCCEEDED (rc))
                {
+               if ( pszArgs )
+                   rc = psl->SetArguments (pszArgs);
+                   if (SUCCEEDED (rc))
+                   {
 #ifdef UNICODE
-               rc = ppf->Save (pszTarget, TRUE);
+                   rc = ppf->Save (pszTarget, TRUE);
 #else
-               WORD wsz[ MAX_PATH ];
-               MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, wsz, MAX_PATH);
-               rc = ppf->Save (wsz, TRUE);
+                   WORD wsz[ MAX_PATH ];
+                   MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, wsz, MAX_PATH);
+                   rc = ppf->Save (wsz, TRUE);
 #endif
+                   }
                }
             }
          ppf->Release ();
@@ -75,7 +83,7 @@ BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc)
 
 void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
 {
-   TCHAR szShortcut[ MAX_PATH ] = TEXT("");
+   TCHAR szShortcut[ MAX_PATH + 10 ] = TEXT("");
 
    HKEY hk;
    if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), &hk) == 0)
@@ -103,12 +111,27 @@ void Shortcut_FixStartup (LPCTSTR pszLinkName, BOOL fAutoStart)
    GetModuleFileName (GetModuleHandle(NULL), szSource, MAX_PATH);
 
    if (fAutoStart)
-      {
-      Shortcut_Create (szShortcut, szSource);
-      }
+   {
+       DWORD code, len, type; 
+       TCHAR szParams[ 64 ] = TEXT(AFSCREDS_SHORTCUT_OPTIONS);
+
+       code = RegOpenKeyEx(HKEY_CURRENT_USER, OpenAFSConfigKeyName,
+                            0, KEY_QUERY_VALUE, &hk);
+       if (code != ERROR_SUCCESS)
+           code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, OpenAFSConfigKeyName,
+                                0, KEY_QUERY_VALUE, &hk);
+       if (code == ERROR_SUCCESS) {
+           len = sizeof(szParams);
+           type = REG_SZ;
+           code = RegQueryValueEx(hk, "AfscredsShortcutParams", NULL, &type,
+                                   (BYTE *) &szParams, &len);
+           RegCloseKey (hk);
+       }
+       Shortcut_Create (szShortcut, szSource, "Autostart Authentication Agent", szParams);
+   }
    else // (!g.fAutoStart)
-      {
+   {
       DeleteFile (szShortcut);
-      }
+   }
 }