PDA

View Full Version : Setting Environment Variable in login script doesn't show up in AutoCAD 2014!!! ARGH!!!



bowlingbrad
2013-10-25, 05:17 PM
I have this line in my login script:



Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WshSysEnv = WshShell.Environment("USER")
WshSysEnv.item("GP_OFFICE") = "CHICAGO"


I open a command prompt and type set.... I see this variable.

I open autocad and type (getenv "GP_OFFICE") and get nil.

hmmmmmmmmm.....

help?

bowlingbrad
2013-10-25, 05:35 PM
I've even modified this line



Set WshSysEnv = WshShell.Environment("USER")


to read



Set WshSysEnv = WshShell.Environment("SYSTEM")

Tom Beauford
2013-10-25, 06:21 PM
On my PC (getenv "OS") returns "Windows_NT", but (getenv "PROMPT") returns nil. Probably has to do with where the values are stored in the registry.
When you enter SET at the DOS command prompt does the variable display correctly? What is it you're trying to do?

bowlingbrad
2013-10-25, 06:28 PM
typing SET gives me the value.
I'm trying to set a variable to locate the computer. We have 3 offices and I want a simple (getenv) that reveals what office the user logged into. I have other portions of the login script doing office specific stuff too (not environment variables)

dgorsman
2013-10-25, 06:51 PM
In order to get generic Windows ENV variables inside AutoCAD, you'll need to take another route. Might need to dig through the registry through a (vl-registry-read ...) call, or change your method of setting variables (e.g. dedicated registry keys and values, or a common network data file with location information).

Opie
2013-10-25, 07:54 PM
Here is a quick routine to get environment values through AutoLISP and the Shell environment.

(defun GetEnvVar (EnvVarName / objShell EnvVarValue )
(setq objShell (vlax-get-or-create-object "Wscript.Shell")
EnvVarValue (vlax-invoke-method objShell 'ExpandEnvironmentStrings (strcat "%"EnvVarName"%")))
(vlax-release-object objShell)
EnvVarValue
)

This may not retrieve all environment variables.

bowlingbrad
2013-10-25, 08:09 PM
I think I'm getting close with (vl-registry-read).... I'll post my findings.

bowlingbrad
2013-10-25, 08:27 PM
my original vbs code was fine.

I changed the way I access the environment variable using:


(vl-registry-read "HKEY_CURRENT_USER\\Environment" "GP_OFFICE")