Jump to content
Sign in to follow this  

Reading Recently Set Env Vars

Recommended Posts


I have created a VBScript to set an environment variable and launch it from an AutoIt Script with ExpandEnvVars = 1 - for some reason the Variable is not read unless I either create the environment variable outside the Autoit script or re-run the autoit script after the env var. has been created it won't be read and I only get back the %Trigram% ... any ideas?

This is the VBScript

Option Explicit

Dim ObjShell, strComputerName, strExpCompName, strTriGram

Set ObjShell = CreateObject("WScript.Shell")

strComputerName = "%COMPUTERNAME%"

strExpCompName = ObjShell.ExpandEnvironmentStrings(strComputerName)

strTriGram = Left(strExpCompName, 3)

ObjShell.Environment.Item("TRIGRAM") = strTriGram

and this is the Autoit Script ( the part that I need anyway ) I have highlited where the Entries are failing -

Opt("ExpandEnvStrings", 1)

Run('D:\Packeteer\ReportCenter\bin\launch.exe -w "D:\Packeteer\ReportCenter" console')

Run('C:\Windows\System32\cscript.exe C:\Windows\logs\ca.vbs')


WinWaitActive("Create New Collection Agent","")


WinWait("Modify %TRIGRAM%PKC001","")

If Not WinActive("Modify %TRIGRAM%PKC001","") Then WinActivate("Modify %TRIGRAM%PKC001","")

WinWaitActive("Modify %TRIGRAM%PKC001","")


Share this post

Link to post
Share on other sites

I believe that when the Au3 is launched it creates something akin to a sandbox of the environment variables. It copies in the pointers where the existing ones reside.

Why not use the Shell("programname.exe") method to launch your script instead of watching for an Environ()?

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post

Link to post
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
Sign in to follow this