 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Mar 14, 2006 4:49 pm Post subject: Setting system enviroment variable with run %comspec% |
|
|
I have trying to set a variable in the enviroment with no success, I have also looked aorund the forum for an example but with no help. | Code: | RegRead, IncludeDir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, IncludeDir
Run %COMSPEC% Set "A_IncludeDir=%IncludeDir%"
ExitApp | May someone please correct my code, thank you _________________ my lame sig  |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Tue Mar 14, 2006 5:01 pm Post subject: |
|
|
I guess it has to be
A_IncludeDir="%IncludeDir%"
But I'm not so sure if it is even possible to set a variable through Run. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Peter
Joined: 30 Dec 2005 Posts: 279
|
Posted: Tue Mar 14, 2006 5:04 pm Post subject: |
|
|
It should work, but the variable is only valid for that DOS session, as it is when you do it manually. So this will work: | Code: | IncludeDir= C:\test
Run %COMSPEC% /k Set "A_IncludeDir=%IncludeDir%"
ExitApp |
If you want it make for every DOS session, I think you can only make it permanent in e.g. Autoexec.bat. But that's no solution for you if I understand your goal. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Mar 14, 2006 5:15 pm Post subject: |
|
|
Do you mean doing a permanent change of the environment?
In this case, set doesn't do it: open a cmd box, set a variable, close the cmd, open a new one: the value isn't there.
You have the EnvSet command, but it has the same problem: only subtasks (like those ran with Run or RunWait) will see it.
The problem can be solved, but it depends on your system.
On old Dos-based systems (Win9x), you have to alter autoexec.bat and reboot... Actually, Microsoft provided an exe (WinSet?) doing a permanent change to the current system, probably using some voodoo.
On NT-based system (Win2k, WinXP), I believe these values are saved in the registry. I changed user and system environment with the System Properties dialog, monitoring with Regmon. Found:
HKCU\Environment\MyUserEnvironmentVariable
HKLM\System\CurrentControlSet\Control\Session Manager\Environment\MySystemEnvironmentVariable
Use with care... _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Mar 14, 2006 5:43 pm Post subject: |
|
|
oh yes, that works very well, thank you. _________________ my lame sig  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5890
|
Posted: Tue Mar 14, 2006 6:01 pm Post subject: Re: Setting system enviroment variable with run %comspec% |
|
|
Dear Invalid User,
| Code: | RegRead, IncludeDir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, IncludeDir
Run %COMSPEC% Set "A_IncludeDir=%IncludeDir%"
ExitApp |
| Quote: | RegRead, IncludeDir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, IncludeDir
Should`nt it be Installdir ?
|
An alternative way :
| Code: | | SplitPath, A_Ahkpath,, IncludeDir,,, |
Thank you. _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5890
|
Posted: Tue Mar 14, 2006 6:05 pm Post subject: |
|
|
| PhiLho wrote: | | On old Dos-based systems (Win9x), you have to alter autoexec.bat and reboot... Actually, Microsoft provided an exe (WinSet?) doing a permanent change to the current system, probably using some voodoo. |
I use winset.exe in WIN 98 SE - but it crashes in Win XP !!!
Regards,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Mar 14, 2006 6:49 pm Post subject: |
|
|
| Goyyah wrote: | | I use winset.exe in WIN 98 SE - but it crashes in Win XP !!! |
That's logical: they have a very different way to storing/managing the environment variables, and if, like I think, WinSet use some voodoo to do its trick (like manipulating directly the memory of Windows...), it has to crash on WinNT...
Last notes: in WinNT, I had to logout and relogin to have the values taken in account. It seems no longer needed in XP. The running consoles will not take in account the change. Perhaps a broadcast of the change should be done to be consistent, if changing a value that may affect a running application. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Invalid User
Joined: 14 Feb 2005 Posts: 442 Location: Texas, Usa
|
Posted: Tue Mar 14, 2006 6:50 pm Post subject: |
|
|
| Quote: | RegRead, IncludeDir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, IncludeDir
Should`nt it be Installdir ?
|
Actully, no. A_IncludeDir is a new variable that will be accessible in ahk: %A_IncludeDir%. This will allow dynamic inclusion of files when and if #include is ever improved to handle user or env variable.
Functions from my download here: http://www.autohotkey.com/forum/viewtopic.php?t=5016 could be included like this someday: | Code: |
#Include %A_IncludeDir%\Fucntions\Misc\MemGetStats.ahk |
_________________ my lame sig  |
|
| Back to top |
|
 |
Peter
Joined: 30 Dec 2005 Posts: 279
|
Posted: Wed Mar 29, 2006 10:34 pm Post subject: |
|
|
| Peter wrote: | | If you want it to make for every DOS session, I think you can only make it permanent in e.g. Autoexec.bat. | Correction, it is possible to make the variable permanent, with Setx tool from resource kit Win2000! But it's the opposite of the normal behaviour namely, the environment variable is valid for all next DOS sessions, and not the current one.
More information here. And by searching the forum on Setx, I found Bobo's post . | Quote: | SETX Command Line Examples:
--------------------------
SETX MACHINE COMPAQ
Sets value of MACHINE to be COMPAQ in the users environment.
SETX MACHINE "COMPAQ COMPUTER" -m
Sets value of MACHINE to be "COMPAQ COMPUTER" in the machine environment.
SETX MYPATH %PATH%
Sets the value of MYPATH to the CURRENT value of the PATH environment variable.
SETX MYPATH ~PATH~
Sets the value of MYPATH to ALWAYS be equal to the value of the PATH environment
variable even in the event that the PATH variable changes. |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|