Jump to content

System variables


Recommended Posts

Hey Guys,

Here is my problem. I am writing software to configure laptops for customers so that they don't have to manually do it. I have a GUI that is kicking off these individual scripts, one might install java while another is installing tomcat etc. Anyways my question is why is it so hard for me to set an ENV_VAR in my install_java.exe and get that variable from my install_tomcat.exe. I get that this is probably a parent-child shell problem, with an emphasis on inheriting sys variables. I have found that doing setEnv() and getEnv() don't work from one script to another if both scripts are kicked off from one "parent" script. Any ideas, it seems like this is a very unintuitive function.

Link to comment
Share on other sites

If the environment variables aren't working between scripts, then don't use individual scripts, put them all into one script and run them as functions in that script. Seems like it would be much more efficient to have only one script instead of several.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If the environment variables aren't working between scripts, then don't use individual scripts, put them all into one script and run them as functions in that script. Seems like it would be much more efficient to have only one script instead of several.

Can't happen. I need them to be individual scripts. It's not about efficiency I don't care how long this takes to run, I need to able to update individual scripts and not release a whole new version of my product.

Link to comment
Share on other sites

If you're using the scripts to install the programs, have you investigated whether or not there are silent install options for each program? I know that Java and Tomcat both have ways of installing them without user intervention.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I do, I install java and tomcat with cmd line statements. However my company has created software that does not have a silent install mode. I just think that the people who maintain the autoIT documentation need to rewrite the description for EnvUpdate(). It states

Remarks

Similar effect as logging off and then on again. For example, changes to the %path% environment might not take effect until you call EnvUpdate (or you logoff/reboot).

However this is not correct at all. When a script returns an exit code to my GUI I call this function, which claims to do the same thing as a logoof/reboot. This is not the case as when I call another script it does not see that I have set an environment variable.

Link to comment
Share on other sites

From EnvSet's description

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.

Which means that once your first script closes, the variable isn't accessible any longer. It also means that it's only available to that script and anything that script runs, if you set an environment variable from the main script instead of the child processes, it should be accessible to any other programs that you start from the main script.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

No idea, I've never used it myself. I suppose it would matter for things like the Path statement, but I'd just use the full path to a file/program and stick it in a variable instead of changing the path variable in Windows.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I wrote a small utility that simply calls EnvUpdate() 3 times with Sleep() calls between. Sometimes I can avoid things like using UnLocker or logging off to get Explorer to let go of a file or folder. That's about it. My suggestion would be if using the call, run it at least 3 times with Sleep() calls maybe 1/5 of a second duration between. If it doesn't do the trick run 3 times in succession then it probably isn't going to work for you.

I remember there was some utility to set the global environment that was distributed in the Resource Kit. But my memory is fuzzy. I don't remember if it's a Win9x or NT based utility. If you ran it from command prompt, you could close the prompt, then open a new one, and the settings were still in effect. I forget the name of it. Something like WinSetEnv or GlobalEnv or something like that.

I found this link. Don't know if it's Vista or W7 compatible:

http://forums.techguy.org/all-other-software/581746-xp-setx-utility-path-environment.html

Link to comment
Share on other sites

Why not use an INI file or use something like this >>

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I second the ini file suggestion. Unless you have to pass a lot of data. Even so you could use the ini file to store a temp filename so that all the scripts know what the current temp file is to open to get settings/data etc..

Just about everything that can be programmed on Windows has a mechanism to access ini files or the means to call the WinAPI functions to do so.

Link to comment
Share on other sites

OR you could use AutoIt's 'Hidden Window' to store the data, have a look for more details. You will need to play around with the code to suit your needs.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

BEWARE - If you use these functions EnvVarCreate(), _EnvVarSet(), and/or _EnvVarDelete(), on an existing environmental variable,, take care, the variable will be overwritten.

Local $sEnvVarName = "TestValue" ; "Path" ;

If FileExists("BkUpEnvVars_" & $sEnvVarName & ".txt") = 0 Then FileWrite("BkUpEnvVars_" & $sEnvVarName & ".txt", EnvGet($sEnvVarName))

_EnvVarCreate($sEnvVarName, "This is a test")
ConsoleWrite( _EnvGetVar($sEnvVarName) & @LF & @LF)
MsgBox(0, "Check", 'Check if "' & $sEnvVarName & '" exists using' & @LF & 'Windows Explorer>MyComputer>right click button>"Properties">"Advanced" tab>"Environmental Variables" button')

_EnvVarSet($sEnvVarName, "This is a testBB")
ConsoleWrite( _EnvGetVar($sEnvVarName) & @LF & @LF)

_EnvVarDelete($sEnvVarName)
ConsoleWrite("Get Var Deleted: " & _EnvGetVar($sEnvVarName) & @LF & @LF)

If FileRead("BkUpEnvVars_" & $sEnvVarName & ".txt") = "" Then FileDelete("BkUpEnvVars_" & $sEnvVarName & ".txt")


; http://blogs.technet.com/b/heyscriptingguy/archive/2005/03/18/how-can-i-create-an-environment-variable-using-a-script.aspx
Func _EnvVarCreate($sNewName, $sValue, $UserName = "")
    Local $strComputer = "."
    Local $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")
    Local $objVariable = $objWMIService.Get("Win32_Environment").SpawnInstance_
    $objVariable.Name = $sNewName
    $objVariable.UserName = $UserName
    $objVariable.VariableValue = $sValue
    $objVariable.Put_
    Return
EndFunc   ;==>_EnvVarCreate

Func _EnvVarSet($sName, $sNewValue)
    Local $strComputer = "."
    Local $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")
    Local $colItems = $objWMIService.ExecQuery _
            ("Select * from Win32_Environment Where Name = '" & $sName & "'")
    For $objItem In $colItems
        $objItem.VariableValue = $sNewValue
        $objItem.Put_
    Next
    Return
EndFunc   ;==>_EnvVarSet

Func _EnvGetVar($sName, $Display = "d")
    Local $aProperties[108], $iNum = 0, $strComputer = "."
    Local $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")
    Local $colItems = $objWMIService.ExecQuery _
            ("Select * from Win32_Environment Where Name = '" & $sName & "'")
    For $objItem In $colItems
        $aProperties[$iNum] = $objItem.Name
        $aProperties[$iNum + 1] = $objItem.UserName
        $aProperties[$iNum + 2] = $objItem.VariableValue
        If $Display = "d" Then
            ConsoleWrite("Name: " & $aProperties[$iNum] & @LF)
            ConsoleWrite("User Name: " & $aProperties[$iNum + 1] & @LF)
            ConsoleWrite("Variable Value: " & $aProperties[$iNum + 2] & @LF)
        EndIf
        $iNum += 3
    Next
    If $iNum > 0 Then ReDim $aProperties[$iNum - 2]
    Return $aProperties
EndFunc   ;==>_EnvGetVar

Func _EnvVarDelete($sName)
    Local $strComputer = "."
    Local $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")
    Local $colItems = $objWMIService.ExecQuery _
            ("Select * from Win32_Environment Where Name = '" & $sName & "'")
    For $objItem In $colItems
        $objItem.Delete_
    Next
    Return
EndFunc   ;==>_EnvVarDelete

This works on my xp.

Edit: This link address to the original scripts was automatically abbreviated in my example, rendering the address unreadable.

Edited by Malkey
Link to comment
Share on other sites

So apart from what has already been suggested, there are many more ways to have your scripts

interact. One little gem I just remembered, which If I recall was very easy to understand and use

is called "containers" which allows you to share data between scripts really easily, and caters

for arrays and objects too.

Search the example scripts for it, written by MrCreator.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I missed that you had mentioned INI JohnOne sorry about that.

Malkey,

It doesn't work on Windows 7 x64. Will have a look as to why,

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

For a set of installers i use an .ini file with encrypted data and when the installer needs it it just grabs the data and if i need to update i just change the .ini

Keeps it simple.

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...