QT installer framework to set user PATH environment variable
-
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 ?
-
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. -
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?
-
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.
-
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.
-
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.
@Renjith-R hello,Have you found a solution later on,to get only the USER environment or only the system environment variable