RE: windows installer - vbs vs bat startup script
"JohnD" <[email protected]>
| Newsgroups | gmane.comp.gnu.octave.maintainers |
|---|---|
| Message-ID | <[email protected]> |
> -----Original Message----- > From: John W. Eaton [mailto:[email protected]] > Sent: Thursday, August 27, 2020 11:49 AM > To: Nicholas Jankowski; JohnD > Cc: octave-maintainers > Subject: Re: windows installer - vbs vs bat startup script > > On 8/27/20 11:44 AM, Nicholas Jankowski wrote: > > I wonder if the issue is trying to run the .vbs script, or trying to > > run a program as hidden from another program ?____ > > > > __ __ > > > > If it just the general act of running a .vbs script , we could just > > a small program using activex and call almost the same commands > > from within it. > > > > > > if the issue with vbs files is the various, potentially conflicting, > > non-standard security protocols, is activex any better? I wasn't aware > > it was supported outside of a browser environment. > > Does it need to be a script or could the same job be done with a > separate .exe program file that sets up the environment appropriately > and then execs the real Octave binary? > > jwe Heres a launcher exe code that looks like will work. See comments in file for compiling. It probally needs a little more work to ensure things don’t buffer run, and doesn’t do much error checking It assumes its in the same directory as the octave executable and works out the paths from that. Its pretty close to what is being done in the.vbs scrip, but in a different order for parts
octave-launch.c
(text/plain, 6.3 KB)
/* * Wrapper application to set octave env variables and then run octave * compile with gcc -o octave-launch octave-launch.c -Wl,--subsystem,windows -lshlwapi * * Copyright (C) 2020 John Donoghue <[email protected]> * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, see <http: *www.gnu.org/licenses/>. */ #include <windows.h> #include <shlwapi.h> int ParentDir(char *dir) { int len = strlen(dir); while(len > 0 && dir[len] != '\\') len --; dir[len] = 0; return len; } char * FilePart(char *dir) { int len = strlen(dir); while(len > 0 && dir[len-1] != '\\') len --; return &dir[len]; } int main(int argc, char **argv) { PROCESS_INFORMATION pi; char msyspath[1024]; char path[1024]; char binpath[1024]; int gui_mode = -1; int i; /* get path of us as we assume octave will be in same dir */ DWORD nSize = GetModuleFileName(NULL, path, sizeof(path)-1); if (nSize) { while(nSize > 0 && path[nSize] != '\\') nSize --; path[nSize] = '\0'; } nSize = GetShortPathName(path, binpath, sizeof(binpath)-1); if (nSize == 0) { StrCpy(binpath, path); } /* binpath is to the bin dir so get the parent */ StrCpy(path, binpath); ParentDir(path); /* now at the octave home */ SetEnvironmentVariable("OCTAVE_HOME", path); /* qt paths * either %OCT_HOME%\qt5\plugins * or %OCT_HOME\plugins */ nSize = strlen(path); StrCat(path, "\\qt5\\plugins"); if (! PathFileExists(path)) { path[nSize] = '\0'; StrCat(path, "\\plugins"); } SetEnvironmentVariable("QT_PLUGIN_PATH", path); path[nSize] = '\0'; /* get msys path and set env */ StrCpy(msyspath, path); char * msys = FilePart(msyspath); /* * should be mingw64 for msys2 ming64 * should be mingw32 for msys2 ming32 * else msys */ if (StrCmpI(msys, "mingw64") == 0) { SetEnvironmentVariable("MSYSTEM", "MINGW64"); ParentDir(msyspath); StrCat(msyspath, "\\bin"); SetEnvironmentVariable("MSYSPATH", msyspath); } else if (StrCmpI(msys, "mingw32") == 0) { SetEnvironmentVariable("MSYSTEM", "MINGW32"); ParentDir(msyspath); StrCat(msyspath, "\\bin"); SetEnvironmentVariable("MSYSPATH", msyspath); } else { SetEnvironmentVariable("MSYSTEM", "MSYS"); SetEnvironmentVariable("MSYSPATH", msyspath); } /* exe paths */ { char pathbuffer[8096]; char newpathbuffer[8096]; nSize = GetEnvironmentVariable("PATH", pathbuffer, sizeof(pathbuffer)-1); pathbuffer[nSize] = '\0'; /* set our paths first */ StrCpy(newpathbuffer, binpath); StrCat(newpathbuffer, ";"); StrCat(newpathbuffer, msyspath); StrCat(newpathbuffer, ";"); StrCat(newpathbuffer, pathbuffer); SetEnvironmentVariable("PATH", newpathbuffer); } /* other env */ SetEnvironmentVariable("TERM", "cygwin"); SetEnvironmentVariable("GNUTERM", "wxt"); SetEnvironmentVariable("GS", "gs.exe"); /* home set */ nSize = GetEnvironmentVariable("HOME", path, sizeof(path)-1); if (nSize == 0 || path[0] == 0) { char newhome[1024]; nSize = GetEnvironmentVariable("USERPROFILE", path, sizeof(path)-1); if (nSize == 0 || path[0] == 0) { /* build dir from drive and path */ char tmpbuff[1024]; nSize = GetEnvironmentVariable("HOMEDRIVE", tmpbuff, sizeof(tmpbuff)-1); if (nSize) StrCpy (path, tmpbuff); else path[0] = '\0'; nSize = GetEnvironmentVariable("HOMEPATH", tmpbuff, sizeof(tmpbuff)-1); if(nSize) StrCat(path, tmpbuff); } nSize = GetShortPathName(path, newhome, sizeof(newhome)-1); if (nSize == 0) { StrCpy(newhome, path); } SetEnvironmentVariable("HOME", newhome); } /* check for gui mode */ for (i=1; i<argc; i++) { if (StrCmp(argv[i], "--no-gui") == 0) gui_mode = 0; else if (StrCmp(argv[i], "--gui") == 0) gui_mode = 1; else if (StrCmp(argv[i], "--force-gui") == 0) gui_mode = 1; } /* set up process args and start it */ { STARTUPINFO si; char argbuffer[4096]; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); StrCpy(path, binpath); if(gui_mode == -1) { /* no mode specified, so set gui */ StrCpy(argbuffer, "octave-gui.exe --gui "); StrCat(path, "\\octave-gui.exe"); si.dwFlags = STARTF_USESHOWWINDOW; } else if (gui_mode == 1) { StrCpy(argbuffer, "octave-gui.exe "); StrCat(path, "\\octave-gui.exe"); si.dwFlags = STARTF_USESHOWWINDOW; } else { StrCpy(argbuffer, "octave-cli.exe "); StrCat(path, "\\octave-cli.exe"); } /* quote and append each arg */ for (i=1; i<argc; i++) { StrCat(argbuffer, "\""); StrCat(argbuffer, argv[i]); StrCat(argbuffer, "\" "); } /* Start the child process */ if (! CreateProcess(path,// module name argbuffer, // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) //Pointer to PROCESS_INFORMATION structure ) return 1; } /* Wait until child process exits. */ WaitForSingleObject( pi.hProcess, INFINITE ); /* Close process and thread handles */ CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); return 0; }