Index: src/branch.c
==================================================================
--- src/branch.c
+++ src/branch.c
@@ -165,11 +165,11 @@
       "\n"
       "Note: the local check-out has not been updated to the new\n"
       "      branch.  To begin working on the new branch, do this:\n"
       "\n"
       "      %s update %s\n",
-      fossil_nameofexe(), zBranch
+      g.argv[0], zBranch
     );
   }
 
 
   /* Commit */

Index: src/cgi.c
==================================================================
--- src/cgi.c
+++ src/cgi.c
@@ -1298,11 +1298,11 @@
     fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
     fflush(stdout);
   }
   if( zBrowser ){
     zBrowser = mprintf(zBrowser, iPort);
-    if( system(zBrowser)<0 ){
+    if( fossil_system(zBrowser)<0 ){
       fossil_warning("cannot start browser: %s\n", zBrowser);
     }
   }
   while( 1 ){
     if( nchildren>MAX_PARALLEL ){

Index: src/configure.c
==================================================================
--- src/configure.c
+++ src/configure.c
@@ -913,12 +913,12 @@
       }
     }
     db_end_transaction(0);
     fossil_print("Configuration reset to factory defaults.\n");
     fossil_print("To recover, use:  %s %s import %s\n", 
-            fossil_nameofexe(), g.argv[1], zBackup);
+            g.argv[0], g.argv[1], zBackup);
   }else
   {
     fossil_fatal("METHOD should be one of:"
                  " export import merge pull push reset");
   }
 }

Index: src/db.c
==================================================================
--- src/db.c
+++ src/db.c
@@ -92,11 +92,13 @@
     g.cgiOutput = 0;
     cgi_printf("<h1>Database Error</h1>\n"
                "<pre>%h</pre><p>%s</p>", z, zRebuildMsg);
     cgi_reply();
   }else{
-    fprintf(stderr, "%s: %s\n\n%s", fossil_nameofexe(), z, zRebuildMsg);
+    char *zOut = mprintf("%s: %s\n\n%s", g.argv[0], z, zRebuildMsg);
+    fossil_puts(zOut, 1);
+    free(zOut);
   }
   free(z);
   db_force_rollback();
   fossil_exit(rc);
 }

Index: src/json.c
==================================================================
--- src/json.c
+++ src/json.c
@@ -348,11 +348,11 @@
   if( 0 != rc ){
     cson_value_free( v );
   }
   assert( (0==rc) && "Adding item to GC failed." );
   if(0!=rc){
-    fprintf(stderr,"%s: FATAL: alloc error.\n", fossil_nameofexe())
+    fprintf(stderr,"%s: FATAL: alloc error.\n", g.argv[0])
         /* reminder: allocation error is the only reasonable cause of
            error here, provided g.json.gc.a and v are not NULL.
         */
         ;
     fossil_exit(1)/*not fossil_panic() b/c it might land us somewhere
@@ -1628,11 +1628,11 @@
   if(!resp){
     /* about the only error case here is out-of-memory. DO NOT
        call fossil_panic() here because that calls this function.
     */
     fprintf(stderr, "%s: Fatal error: could not allocate "
-            "response object.\n", fossil_nameofexe());
+            "response object.\n", g.argv[0]);
     fossil_exit(1);
   }
   if( g.isHTTP ){
     if(alsoOutput){
       json_send_response(resp);

Index: src/main.c
==================================================================
--- src/main.c
+++ src/main.c
@@ -352,21 +352,14 @@
   char *z;            /* General use string pointer */
   char **newArgv;     /* New expanded g.argv under construction */
   char const * zFileName;   /* input file name */
   FILE * zInFile;           /* input FILE */
   int foundBom = -1;        /* -1= not searched yet, 0 = no; 1=yes */
-#ifdef _WIN32
-  wchar_t buf[MAX_PATH];
-#endif
 
   g.argc = argc;
   g.argv = argv;
-#ifdef _WIN32
-  GetModuleFileNameW(NULL, buf, MAX_PATH);
-  g.argv[0] = fossil_unicode_to_utf8(buf);
-  for(i=1; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
-#endif
+  for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
   for(i=1; i<g.argc-1; i++){
     z = g.argv[i];
     if( z[0]!='-' ) continue;
     z++;
     if( z[0]=='-' ) z++;
@@ -535,11 +528,21 @@
 
 /*
 ** Return the name of the current executable.
 */
 const char *fossil_nameofexe(void){
+#ifdef _WIN32
+  static const char *z = 0;
+  if (!z) {
+    wchar_t buf[MAX_PATH];
+    GetModuleFileNameW(NULL, buf, MAX_PATH);
+    z = fossil_unicode_to_utf8(buf);
+  }
+  return z;
+#else
   return g.argv[0];
+#endif
 }
 
 /*
 ** Exit.  Take care to close the database first.
 */
@@ -574,12 +577,13 @@
     if( g.cgiOutput && once ){
       once = 0;
       cgi_printf("<p class=\"generalError\">%h</p>", z);
       cgi_reply();
     }else if( !g.fQuiet ){
-      char *zOut = mprintf("%s: %s\n", fossil_nameofexe(), z);
+      char *zOut = mprintf("%s: %s\n", g.argv[0], z);
       fossil_puts(zOut, 1);
+      free(zOut);
     }
   }
   free(z);
   db_force_rollback();
   fossil_exit(rc);
@@ -606,12 +610,13 @@
     if( g.cgiOutput ){
       g.cgiOutput = 0;
       cgi_printf("<p class=\"generalError\">%h</p>", z);
       cgi_reply();
     }else if( !g.fQuiet ){
-      char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z);
+      char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
       fossil_puts(zOut, 1);
+      free(zOut);
     }
   }
   free(z);
   db_force_rollback();
   fossil_exit(rc);
@@ -647,11 +652,11 @@
     if( g.cgiOutput ){
       g.cgiOutput = 0;
       cgi_printf("<p class=\"generalError\">%h</p>", z);
       cgi_reply();
     }else{
-      char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z);
+      char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
       fossil_puts(zOut, 1);
       free(zOut);
     }
   }
   db_force_rollback();
@@ -673,11 +678,11 @@
 #endif
   {
     if( g.cgiOutput ){
       cgi_printf("<p class=\"generalError\">%h</p>", z);
     }else{
-      char *zOut = mprintf("\r%s: %s\n", fossil_nameofexe(), z);
+      char *zOut = mprintf("\r%s: %s\n", g.argv[0], z);
       fossil_puts(zOut, 1);
       free(zOut);
     }
   }
   free(z);
@@ -708,14 +713,18 @@
 #if defined(_WIN32)
   /* On windows, we have to put double-quotes around the entire command.
   ** Who knows why - this is just the way windows works.
   */
   char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
-  char *zMbcs = fossil_utf8_to_mbcs(zNewCmd);
-  if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zMbcs);
-  rc = system(zMbcs);
-  fossil_mbcs_free(zMbcs);
+  wchar_t *zUnicode = fossil_utf8_to_unicode(zNewCmd);
+  if( g.fSystemTrace ) {
+    char *zOut = mprintf("SYSTEM: %s\n", zNewCmd);
+    fossil_puts(zOut, 1);
+    free(zOut);
+  }
+  rc = _wsystem(zUnicode);
+  fossil_mbcs_free(zUnicode);
   free(zNewCmd);
 #else
   /* On unix, evaluate the command directly.
   */
   if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zOrigCmd);
@@ -781,11 +790,11 @@
 
 /*
 ** Print a usage comment and quit
 */
 void usage(const char *zFormat){
-  fossil_fatal("Usage: %s %s %s\n", fossil_nameofexe(), g.argv[1], zFormat);
+  fossil_fatal("Usage: %s %s %s\n", g.argv[0], g.argv[1], zFormat);
 }
 
 /*
 ** Remove n elements from g.argv beginning with the i-th element.
 */
@@ -942,11 +951,11 @@
 */
 void help_cmd(void){
   int rc, idx;
   const char *z;
   if( g.argc<3 ){
-    z = fossil_nameofexe();
+    z = g.argv[0];
     fossil_print(
       "Usage: %s help COMMAND\n"
       "Common COMMANDs:  (use \"%s help --all\" for a complete list)\n",
       z, z);
     command_list(0, CMDFLAG_1ST_TIER);
@@ -981,11 +990,11 @@
     fossil_fatal("no help available for the %s command",
        aCommand[idx].zName);
   }
   while( *z ){
     if( *z=='%' && strncmp(z, "%fossil", 7)==0 ){
-      fossil_print("%s", fossil_nameofexe());
+      fossil_print("%s", g.argv[0]);
       z += 7;
     }else{
       putchar(*z);
       z++;
     }