]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Windows: Update Control Panel to use ShellExecuteEx instead of WinExec
authorJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 22 Oct 2009 12:57:04 +0000 (08:57 -0400)
committerJeffrey Altman <jaltman|account-1000011@unknown>
Thu, 22 Oct 2009 13:18:40 +0000 (06:18 -0700)
WinExec is for 16-bit application compatibility.  Starting with
Windows 7 it cannot be used to execute a process that requires
elevated privileges.  ShellExecute[Ex] must be used instead.

LICENSE MIT

Reviewed-on: http://gerrit.openafs.org/711
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
src/WINNT/client_cpa/NTMakefile
src/WINNT/client_cpa/cpl_interface.cpp

index 0c1bbe74bf9caee9acb34ea812b30fbe8e44b385..b724da792f6181c98b48b81bcb5e56ea1aa43aa8 100644 (file)
@@ -22,7 +22,7 @@ DLLOBJS =\
 DLLLIBS =\
        $(DESTDIR)\lib\afs\TaLocale.lib \
        $(DESTDIR)\lib\libosi.lib \
-       comctl32.lib
+       comctl32.lib shell32.lib ole32.lib
 
 DEFFILE = afs_cpa.def
 
index 37d8d09458dd0604a76d665271631d2cc012613d..4d03eec2c2d851c291d9527b2480df4cb51625a8 100644 (file)
@@ -8,6 +8,8 @@
  */
 
 #include <windows.h>
+#include <objbase.h>
+#include <shellapi.h>
 #include <cpl.h>
 #include <WINNT/TaLocale.h>
 #include <WINNT/afsreg.h>
@@ -72,24 +74,25 @@ extern "C" LONG APIENTRY CPlApplet(HWND hwndCPl, UINT uMsg, LONG lParam1, LONG l
 {
     LPNEWCPLINFO lpNewCPlInfo;
     LPCPLINFO lpCPlInfo;
+    SHELLEXECUTEINFO shellExecInfo;
 
     switch (uMsg) {
         case CPL_INIT:      /* first message, sent once  */
             hinst = GetModuleHandle("afs_cpa.cpl");
             hinstResources = TaLocale_LoadCorrespondingModule (hinst);
+            CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
             return (hinst != 0);
 
         case CPL_GETCOUNT:  /* second message, sent once */
             return 1;
-            break;
 
         case CPL_INQUIRE:  /* in case we receive this we should indicate that we like NEWINQUIRE better. */
-                       lpCPlInfo = (CPLINFO *) lParam2;
-                       lpCPlInfo->idIcon = ((IsClientInstalled() || !IsWindowsNT())? IDI_AFSD : IDI_CCENTER);
-                       lpCPlInfo->idName = CPL_DYNAMIC_RES;
-                       lpCPlInfo->idInfo = CPL_DYNAMIC_RES;
-                       lpCPlInfo->lData = 0;
-                       break;
+            lpCPlInfo = (CPLINFO *) lParam2;
+            lpCPlInfo->idIcon = ((IsClientInstalled() || !IsWindowsNT())? IDI_AFSD : IDI_CCENTER);
+            lpCPlInfo->idName = CPL_DYNAMIC_RES;
+            lpCPlInfo->idInfo = CPL_DYNAMIC_RES;
+            lpCPlInfo->lData = 0;
+            break;
 
         case CPL_NEWINQUIRE: /* third message, sent once per app */
             lpNewCPlInfo = (LPNEWCPLINFO) lParam2;
@@ -108,14 +111,20 @@ extern "C" LONG APIENTRY CPlApplet(HWND hwndCPl, UINT uMsg, LONG lParam1, LONG l
             GetString (lpNewCPlInfo->szInfo, (!IsWindowsNT()) ? IDS_CPL_DESC_95 : (!IsClientInstalled()) ? IDS_CPL_DESC_CCENTER : IDS_CPL_DESC_NT);
             break;
 
-        case CPL_DBLCLK:               /* applet icon double-clicked */
-           if (IsClientInstalled() || !IsWindowsNT())
-               WinExec("afs_config.exe", SW_SHOW);
-           else
-               WinExec("afs_config.exe /c", SW_SHOW);
+    case CPL_DBLCLK:           /* applet icon double-clicked */
+            memset(&shellExecInfo, 0, sizeof(shellExecInfo));
+            shellExecInfo.cbSize = sizeof(shellExecInfo);
+            shellExecInfo.nShow = SW_SHOWNORMAL;
+            shellExecInfo.hwnd = hwndCPl;
+            shellExecInfo.lpFile = "afs_config.exe";
+           if (!IsClientInstalled() && IsWindowsNT())
+                shellExecInfo.lpParameters = "/c";
+
+            ShellExecuteEx(&shellExecInfo);
             break;
 
-        case CPL_EXIT:
+    case CPL_EXIT:
+            CoUninitialize();
             if (hinstResources)
                 FreeLibrary (hinstResources);
             break;