Jump to content

Question: User Environment is there a command?


Recommended Posts

Hello,

I´ve a question regarding making an environment entry.

I thought EnvSet would be for what I need but in the helpfile I read:

Remarks

A environment variable set in this way will only be accessible to programs that AutoIt spawns (Run, RunWait). Once AutoIt closes, the variables will cease to exist.

I need to set some user enviroment variables, eg. pathes and so on in a login script. These should be avaible to all programms the user starts, not only for one programm that I start from within autoit.

Is there a function in autoit that does this? I searched the helpfile + the forum and did not find an answer to that.

If there really is no function for that, I´ll have to modify directly the registry key entrys in HKEY_CURRENT_USER\Environment

commenti

Link to comment
Share on other sites

Hi ezzetabi,

thank you for suggesting me:

But I don´t wanna use ist, reason: I have to install it on every computer or at least copying it itsself to the logonshare. I don´t wanna do that. My question was not how to set enviroment variables for the user, my question was if there is a function in AutoIt that is for this task. But thanks anyway.

Ok, seems there ist no internal function in AutoIt so I´ll do it this way:

example how to use the function:

setuserenv ("autoitisgreatpath=c:\autoitforever\")

And here is the short function I made to do this in autoit. (I just asked, because I wanted to know if I accidently did not find a intern autoit function to do that, I don´t wanted to invent the wheel two times :ph34r: )

Func setuserenv ($nameandvalue)
   $name=stringmid($nameandvalue,1,StringInStr ( $nameandvalue, "=",1)-1)
   $value=stringmid($nameandvalue,StringInStr ( $nameandvalue, "=",1)+1,256)
   RegWrite("HKEY_CURRENT_USER\Environment", $name, "REG_EXPAND_SZ", $value)
   EnvUpdate ( )
EndFunc

commenti

Link to comment
Share on other sites

Which OS are you using? You need to put the environment variables into the AutoExec.bat of the computer.

Set PATH=%PATH%;C:\Utilities

I do not know if this works on anything past Windows ME.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

But I don´t wanna use ist, reason: I have to install it on every computer or at least copying it itsself to the logonshare. I don´t wanna do that.

I am afraid that the mother microsoft confused you.

There is no need for installing for SETX. Just install it once. Save the setx.exe file somewhere and uninstall the rubbish MS want you install and keep the only file needed setx.exe .

Done this, Fileinstall setx... use it and delete it. Any computer that can execute the autoit compiled file will also can use setx.

Link to comment
Share on other sites

Hello,

@Nutster thanks for the suggestion but this does not work under Win2000 and XP. (I am using these and I need it for a loginscript).

@ezzetabi Hm, I think you are right that MS confused me with the setup for setx. But I don´t need it anymore anyway. My short function works well, I allready tried it out. Why fileinstalling a third party program if you can do it not that difficult in AutoIt itsself with a short udf? My short udf only takes 6 lines and works with Win 2K and WinXP. (Thats what I need for my login script). As I allready wrote the reason I posted the question in the first time was, I wanted to know if there was allready a build in function for this that I did not find. But perhaps I find a use for setx for something else. So thank you anyway.

commenti

Link to comment
Share on other sites

I set system environment variables in the registry... hmmm.. .. where did I last do that? Don't know, but I do it by added to both CurrentControlSet and ControlSet001:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment

As that is where a variable shows when you manually add them. To have it be in effect durring the current script, use envset.

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment

Usually CurrentControlSet should be enough.

As far as I remember ControlSetNNN is for the different hardware profiles that can be created. CurrentControlSet only exists while Windows is running, so there are two possibilities: CurrentControlSet is only a link to the active ControlSetNNN (like HKEY_CURRENT_USER) or it's a copy.

So as long as you don't need to care about different hardware profiles just use CurrentControlSet.

Link to comment
Share on other sites

Hello,

I wanted to set the enviroment for the current user not for the whole maschine. If I use

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

then I am setting the enviroment for the whole maschine. The bigger problem would be that a normal user has no right to write to this part of the registry. (admin rights needed, not usefull in normal loginscripts if you want avoid runas if possible for security reasons)

So I think:

HKEY_CURRENT_USER\Environment

as I use it in my small setuserenv function (see my posts bevor) is fine.

commenti

Link to comment
Share on other sites

  • 2 years later...

Howdy commenti,

I have to say, I have tried many ways to set the environment variables for the users log on and yours is the best solution to date. When I finish the script I will post it so that everyone say what they think use it whatever. Thanks so much!!!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...