AutoHotkey Community

It is currently May 27th, 2012, 7:07 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: March 14th, 2006, 4:49 pm 
Offline

Joined: February 14th, 2005, 10:54 am
Posts: 447
Location: Texas, Usa
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2006, 5:01 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2006, 5:04 pm 
Offline

Joined: December 30th, 2005, 5:01 pm
Posts: 448
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2006, 5:15 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2006, 5:43 pm 
Offline

Joined: February 14th, 2005, 10:54 am
Posts: 447
Location: Texas, Usa
oh yes, that works very well, thank you.

_________________
my lame sig :)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 14th, 2006, 6:01 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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.

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2006, 6:05 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2006, 6:49 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2006, 6:50 pm 
Offline

Joined: February 14th, 2005, 10:54 am
Posts: 447
Location: Texas, Usa
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2006, 10:34 pm 
Offline

Joined: December 30th, 2005, 5:01 pm
Posts: 448
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], sjc1000, Yahoo [Bot] and 74 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group