QT installer framework to set user PATH environment variable
-
wrote on 25 Apr 2019, 17:52 last edited by
I'd like to set user PATH environment variable for my Qt application and in my installscript.qs I do this:
Component.prototype.createOperations = function() { // call default implementation component.createOperations(); // ... add custom operations var winpath = installer.environmentVariable("PATH") + ";" + installer.value("TargetDir"); component.addElevatedOperation("EnvironmentVariable","PATH",winpath,true); }
However this will add system PATH environment variable to user PATH environment variable, and it will keep repeat everything if I run the installer again. That messes up the variable. What can I do? What is the right way of just adding my variable to the user PATH environment variable (and maybe remove it upon uninstallation)?
Thanks a lot.
-
Hi,
Out of curiosity, why do you want to modify the user PATH environment variable ?
-
wrote on 25 Apr 2019, 18:58 last edited by
My application needs external dll (lets call it a.dll), and I think that a.dll calls other dll relative to its location. I tested it that I can't just move a.dll to same directory of my exe, but if I set the environment variable everything will work fine...
-
My application needs external dll (lets call it a.dll), and I think that a.dll calls other dll relative to its location. I tested it that I can't just move a.dll to same directory of my exe, but if I set the environment variable everything will work fine...
tested it that I can't just move a.dll to same directory of my exe, but if I set the environment variable everything will work fine...
That sounds strange. On Windows, both should work the same.
I'd very upset if your app would modify my
PATH
. There are already enough strange entries that causes problems for other apps, e.g. -
wrote on 25 Apr 2019, 19:14 last edited by
I think the a.dll is expecting some fix relative directory structure of dll (and other things). I think Windows program add environment variable all the time? Or can I create my own variable?
-
Then you should check what exactly is expected for these .dlls.
As @aha_1980, there are indeed lots of application that modify the
PATH
environment variable for usually no really good reasons and that can be mighty annoying. -
I think the a.dll is expecting some fix relative directory structure of dll (and other things). I think Windows program add environment variable all the time? Or can I create my own variable?
@Pauly I just hunted a bug where an app didn't work.
It turned out, the app was using the wrong Qt DLLs from QtCreator, because that one was added to
PATH
So just think, fixing your case might break others.
-
wrote on 25 Apr 2019, 19:53 last edited by
Understood... So is there a way to specify relative path to a particular dll in Qt project, just as if that is added to the environment variable? That may solve my need without messing with the environment variable.
-
wrote on 28 May 2019, 13:15 last edited by
I have same problem, but on uninstall process, also, i get errors with "Error during uninstallation: " with empty description.
I think, it happens because "addElevatedOperation" must have both DO and UNDO steps(but i dont know how to add UNDO step for uninstall)
DO on installation step, UNDO on uninstall. Does anyone know how to solve this problem?Component.prototype.createOperations = function() { component.createOperations(); if(installer.isInstaller()) { component.addElevatedOperation("EnvironmentVariable","GST_PLUGIN_PATH", gstPluginPath, persistently, false); component.addElevatedOperation("EnvironmentVariable","GST_PLUGIN_SYSTEM_PATH", gstPluginSystemPath, persistently, false); component.addElevatedOperation("EnvironmentVariable","GSTREAMER_1_0_ROOT_X86", gstreamerRootPath, persistently, false); }
-
Understood... So is there a way to specify relative path to a particular dll in Qt project, just as if that is added to the environment variable? That may solve my need without messing with the environment variable.
-
wrote on 23 Nov 2020, 06:19 last edited by MikePooh
Try this
var winpath = installer.environmentVariable("PATH"); component.addOperation( "Execute", "setx", ["PATH", "\"" + @TargetDir@ + winpath + "\""] );
to add to user PATH or
component.addOperation( "Execute", "setx", ["/M", "PATH", "\"" + @TargetDir@ + winpath + "\""] );
to add to system PATH (admin rights might be provided)
Be noted that setx command truncate PATH to 1024 symbols. That mean, it might break the system in case the PATH variable was longer.
-
wrote on 28 Jul 2022, 05:38 last edited by
In the above-mentioned code by @MikePooh, installer.environmentVariable("PATH") returns both user and system environment variables.
So Is there any way to get only the USER environment or only the system environment variable? Otherwise, it will write system variables to user path or vise versa.
-
In the above-mentioned code by @MikePooh, installer.environmentVariable("PATH") returns both user and system environment variables.
So Is there any way to get only the USER environment or only the system environment variable? Otherwise, it will write system variables to user path or vise versa.
wrote on 13 Sept 2023, 07:46 last edited by@Renjith-R hello,Have you found a solution later on,to get only the USER environment or only the system environment variable