How to set windows system path using Qt api
-
wrote on 14 Oct 2011, 09:34 last edited by
Hi,
I want to add a the bin path of installed JDK to window's system variable's path from qt application.
May i know if there are any apis to edit window systme variable's path. If anybody knows plz share code example.regards,
Pradeep -
wrote on 14 Oct 2011, 09:45 last edited by
no, there are not
you can change the path of your app by using putenv.
The system environment isv stored in the registry and from there given to each top most process. From there on, you have no chance from outside to change it, only from inside of the process. -
wrote on 14 Oct 2011, 10:08 last edited by
Thanks for the reply.
Just tried the below code to set jre path from my qt app.
putenv("PATH=C:\Apps\Java\jre6\bin");
then i saw in the system variable, it did not add to the path variable. Any idea how to do it?
regards,
Pradeep -
wrote on 14 Oct 2011, 10:27 last edited by
could be:
@putenv(“PATH=%PATH%;C:\Apps\Java\jre6\bin”); @ -
wrote on 14 Oct 2011, 10:46 last edited by
i tried the below code
putenv("PATH=%PATH%;C:\Apps\Java\jre6\bin");
QString path = getenv("PATH");This code did not append to the system var path :(
but while debugging i could see getenv returns the string %PATH%;C:\Apps\Java\jre6\bin. -
wrote on 14 Oct 2011, 10:49 last edited by
Well, this is not how environments work.
There is one inital system environment (stored in the registry on Windows) which is passed to each created process by the kernel. If a process now spawns another process (which is true for the majority of the processes, userland processes are not spawn by the kernel, but for example by Explorer.exe instead) the environment is passed to the spawned process. This means that a process can always alter its own environment (which gets passed to processes it spawns).
If you want to change the environment for other processes you will have to change the system environment and restart all processes (log off and log on on Windows).
In fact Windows provides another method by broadcasting WM_SETTINGCHANGE which enables applications aware of that message to re-initialize their environment (which should be true for at least the Windows Explorer, Program Manager and Task Manager).
1/6