Qian Hong : kernel32: Fallback to default comspec when %COMSPEC% is not set.

Alexandre Julliard julliard at winehq.org
Mon Sep 3 16:26:10 CDT 2018


Module: wine
Branch: master
Commit: 279ac253e5aa7132ec4960af175115befcdfefd0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=279ac253e5aa7132ec4960af175115befcdfefd0

Author: Qian Hong <qhong at codeweavers.com>
Date:   Fri Aug 31 01:09:32 2018 +0000

kernel32: Fallback to default comspec when %COMSPEC% is not set.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=19801
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/process.c |  6 +++++-
 programs/cmd/wcmdmain.c | 10 ++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 7ac7477..85e0042 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -2206,6 +2206,7 @@ static BOOL create_cmd_process( LPCWSTR filename, LPWSTR cmd_line, LPVOID env, L
 
 {
     static const WCHAR comspecW[] = {'C','O','M','S','P','E','C',0};
+    static const WCHAR cmdW[] = {'\\','c','m','d','.','e','x','e',0};
     static const WCHAR slashscW[] = {' ','/','s','/','c',' ',0};
     static const WCHAR quotW[] = {'"',0};
     WCHAR comspec[MAX_PATH];
@@ -2213,7 +2214,10 @@ static BOOL create_cmd_process( LPCWSTR filename, LPWSTR cmd_line, LPVOID env, L
     BOOL ret;
 
     if (!GetEnvironmentVariableW( comspecW, comspec, ARRAY_SIZE( comspec )))
-        return FALSE;
+    {
+        GetSystemDirectoryW( comspec, (sizeof(comspec) - sizeof(cmdW))/sizeof(WCHAR) );
+        strcatW( comspec, cmdW );
+    }
     if (!(newcmdline = HeapAlloc( GetProcessHeap(), 0,
                                   (strlenW(comspec) + 7 + strlenW(cmd_line) + 2) * sizeof(WCHAR))))
         return FALSE;
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index cceb588..c8a41d3 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -2403,10 +2403,20 @@ int wmain (int argc, WCHAR *argvW[])
   static const WCHAR offW[] = {'O','F','F','\0'};
   static const WCHAR promptW[] = {'P','R','O','M','P','T','\0'};
   static const WCHAR defaultpromptW[] = {'$','P','$','G','\0'};
+  static const WCHAR comspecW[] = {'C','O','M','S','P','E','C',0};
+  static const WCHAR cmdW[] = {'\\','c','m','d','.','e','x','e',0};
+  WCHAR comspec[MAX_PATH];
   CMD_LIST *toExecute = NULL;         /* Commands left to be executed */
   OSVERSIONINFOW osv;
   char osver[50];
 
+  if (!GetEnvironmentVariableW(comspecW, comspec, sizeof(comspec)/sizeof(WCHAR)))
+  {
+      GetSystemDirectoryW(comspec, (sizeof(comspec) - sizeof(cmdW))/sizeof(WCHAR));
+      strcatW(comspec, cmdW);
+      SetEnvironmentVariableW(comspecW, comspec);
+  }
+
   srand(time(NULL));
 
   /* Get the windows version being emulated */




More information about the wine-cvs mailing list