ainner Posted March 26, 2013 Share Posted March 26, 2013 (edited) I'd like to be able to read an env var created in a .vbs with EnvGet without having to reboot. Anyone know why I can read it right away in a .vbs and not with EnvGet Thx! $oShell = ObjCreate("WScript.Shell") $wshSystemEnv = $oShell.Environment("SYSTEM") $wshSystemEnv( "David" ) = "Bowie" $var = EnvGet("David") MsgBox(4096, "Path variable is:", $var) MsgBox(4096, "Test", $wshSystemEnv("David"), 10) Edited March 26, 2013 by ainner Link to comment Share on other sites More sharing options...
water Posted March 26, 2013 Share Posted March 26, 2013 The example you provided crashes with "The requested action with this object has failed.: $wshSystemEnv( "David" ) = "Bowie"^ ERROR"Does the Env variable still exist after the VB script has ended? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
ainner Posted March 26, 2013 Author Share Posted March 26, 2013 Strange my example work just fine except that the first msgbox is empty. Link to comment Share on other sites More sharing options...
FireFox Posted March 26, 2013 Share Posted March 26, 2013 (edited) It crashes for me too. I can't get the right syntax to assign the value. Edit: Not possible as it's a string and not an object. Edited March 26, 2013 by FireFox Link to comment Share on other sites More sharing options...
water Posted March 26, 2013 Share Posted March 26, 2013 I'm running WIndows 7 64 bit. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 26, 2013 Moderators Share Posted March 26, 2013 ainner, Does this work for you? #include <Constants.au3> $sOutput = "" $sEnvVar = "David" $sEnvValue = "Not Found" ; Read the system emnvironment Local $iPID = Run(@ComSpec & " /C SET", "", @SW_HIDE, $STDOUT_CHILD) While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd ; Find the env var $aEnv = StringSplit($sOutput, @CRLF, 1) For $i = 1 To $aEnv[0] $aSplit = StringSplit($aEnv[$i], "=") If $aSplit[1] = $sEnvVar Then $sEnvValue = $aSplit[2] ExitLoop EndIf Next MsgBox(0, "Env Var", $sEnvVar & " = " & $sEnvValue) Any use? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
FireFox Posted March 26, 2013 Share Posted March 26, 2013 @Melba23 Play the game and try it with the WScript Shell Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 26, 2013 Moderators Share Posted March 26, 2013 FireFox, Remind me who sets the rules around here? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
FireFox Posted March 26, 2013 Share Posted March 26, 2013 D'oh ! Too easy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 26, 2013 Moderators Share Posted March 26, 2013 ainner, Please ignore us - we like to have a bit of fun now and again. Does the script I posted allow you to read the environment variable you need? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now