Win32_Environment %SessionName% not found. RRS feed

  • Question

  • Hi Guys,

    I'm trying to write a simple WMI query using the Environment class for a GPO to check whether user is using a RDP session or on a Console session. The variable works fine and displays the correct data (Console or RDP-tcpxx) on command prompt but when i try to execute it over WMI tester the %SessionName% variable cannot be found! Any ideas?

    Pretty sure i don't any have any syntax error for the WMI query as i tried looking for the variable using Select * from Win32_Environment. It's just not there.

    Your help is much appreciated!

    With Regards,

    Monday, September 21, 2015 8:16 AM


All replies

  • Batch file?  What?

    %SessionName% is only valid in batch files.

    In WMI % is a wildcard.

    Get-WmiObject Win32_Environment -Filter Name="'SessionName'"


    Monday, September 21, 2015 11:56 AM
  • Hi Jrv,

    I'm using WQL (WMI Query Language) for filters to setup a GPO. Can't use powershell command though.

    It has to be like Select * from Win32_Environment where Name like '%sessionname%'.

    I understand % is wildcard. It's just my habit of putting it into all like conditions. Still the above query doesn't return with any result as if the environment variable "sessionname" doesn't exist. And neither does the powershell command return anything. But from DOS set sessionname it does appear though. Not sure why.

    Tuesday, September 22, 2015 6:29 AM
  • The variable only exists in an RDP session.


    Tuesday, September 22, 2015 9:31 AM
  • A little research shows that WMI cannot see that variable for many reasons. You will need to use another method to get the environment.


    Tuesday, September 22, 2015 9:36 AM
  • I can see it even on console session. Just not from WMI. That sucks. Thanks for the quick reply Jrv!

    On a side note i'm trying to disable folder redirection for a GPO whenever user is doing RDP with a WMI filter so perhaps you can point me into a different direction if you can?

    Tuesday, September 22, 2015 11:06 AM
  • For GPO issues post in the GP forum: Group Policy


    • Proposed as answer by Mike Laughlin Tuesday, September 22, 2015 12:12 PM
    • Marked as answer by Jack_Tan Wednesday, September 23, 2015 5:34 AM
    Tuesday, September 22, 2015 11:10 AM
  • Right i'll post a new question over there. Thanks for the help!!
    Wednesday, September 23, 2015 5:35 AM