Xichael

Unable to EnvGet("SESSIONNAME")

10 posts in this topic

In CMD, echo %SESSIONNAME% works fine, but AutoIt's EnvGet("SESSIONNAME") produces nothing. Anyone know how to get this working?

Share this post


Link to post
Share on other sites

Works fine here. Have you checked to see what the result is for "echo %SESSIONNAME% " when running the 32 cmd version? ( %windir%\SysWoW64\cmd.exe )

Jos

 

 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

it works here (win7 x64 AutoIt v 3.3.14.2)

Local $sValue = EnvGet("SESSIONNAME")
MsgBox(0, "EnvGet", $sValue)

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

On 3/17/2017 at 10:53 AM, Jos said:

Works fine here. Have you checked to see what the result is for "echo %SESSIONNAME% " when running the 32 cmd version? ( %windir%\SysWoW64\cmd.exe )

Yes, that's working.

Edited by Xichael

Share this post


Link to post
Share on other sites

What is the output of this script when ran in SciTE: ?

#include <AutoItConstants.au3>
Local $iPID = Run(@ComSpec & ' /C set ',"", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
Local $sOutput = StdoutRead($iPID)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sOutput = ' & $sOutput & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

...

Edited by Xichael

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It's actually working if I launch the script  from Cmd or the Run window, but if I launch with a double-click from Explorer, EnvGet("SESSIONNAME") is empty.

On 3/17/2017 at 11:05 AM, Jos said:

What is the output of this script when ran in SciTE: ?

#include <AutoItConstants.au3>
Local $iPID = Run(@ComSpec & ' /C set ',"", @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
Local $sOutput = StdoutRead($iPID)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sOutput = ' & $sOutput & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

 

Similar situation here; if I launch SciTE from the Explorer context menu and F5 to run your script, no SESSIONNAME in the console, but if I launch SciTE from the start menu and run it, it's there.

 

 

Edited by Xichael

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Still struggling with this one, if anyone can help.

Quick recap:

Works fine if I Win+R > C:\Path\To\Script.au3, but fails if I double-click from Explorer (both 32 and 64 bit).

MsgBox('','',EnvGet('sessionname'))

 

Edited by Xichael

Share this post


Link to post
Share on other sites

It appears to be using System Session rather than the User Session, you probably could use:

ExpandEnvironmentStringsForUser
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762275(v=vs.85).aspx

However for me its easier just to get the info from registry for example:

Func _RegSessionName()
    Local $i = 1, $sRegRoot = "HKCU\Volatile Environment", $sRegKey, $sRegVal = ""
    While 1
        $sRegKey = RegEnumKey($sRegRoot, $i)
            If @error Then ExitLoop
        $sRegVal = RegRead($sRegRoot & "\" & $sRegKey, "SessionName")
        If $sRegVal <> "" Then Return $sRegVal
        $i += 1
    WEnd
    Return ""
EndFunc

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thanks, that works great. Wondering though, when would SessionName ever not be at key 1? It'd be nice if I could just use this: 

RegRead('HKCU\Volatile Environment\1', 'SessionName')

Also, is this System Session vs User Session situation with EnvGet a bug?

Edited by Xichael

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