none
Win32_Environment SessionName environment variable not found

    Question

  • Hi Guys,

    I'm trying to write a simple WMI query language 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,
    Edmund

    Wednesday, September 23, 2015 5:34 AM

Answers

All replies

  • > 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.
     
    If you have a close look, you will notice that %username%,
    %userprofile%, %appdata% and numerous others are missing, too.
     
    These are "volatile" variables, created at session initialization, and
    volatile variables are never visible in WMI. Either you find another
    class that can help, or you peek in registry (HKCU\Volatile Environment).
     
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    Wednesday, September 23, 2015 8:42 AM
  • Hi Martin,

    Thanks for the feedback! I wasn't aware of the term or rather the feature "volatile" variables.

    I did quick peek on the registry path you provided and the value is there where i need it! However quick google doesn't provide much examples of how do we manipulate the win32_registry / win32_registryaction class via WQL. Can you share me any example uses of these 2 class if you're aware of it? MSDN class KB isn't helping much.

    Appreciate your help!

    Wednesday, September 23, 2015 9:37 AM
  • > examples of how do we manipulate the win32_registry /
    > win32_registryaction class via WQL. Can you share me any example uses of
    > these 2 class if you're aware of it? MSDN class KB isn't helping much.
     
    By default, WQL does not support registry - the registry provider only
    has methods, no properties. And since I use scripting, I cannot really
    help with that. But if you use SCCM, I remember that SCCM implements
    some custom MOFs that expose registry values...
     
    Anyway - if you are in a terminal session, you would need the session
    number to find the session name - and since WQL is somewhat static, this
    might be difficult.
     
    I'd suggest to describe your requirements, might be that there's a
    totally different approach :) I understand that you want to determine
    console/rdp, but why?
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    Wednesday, September 23, 2015 9:57 AM
  • Well we do have SCCM implemented. But that seems to be another level a complexity i suppose.

    So basically i'm implementing a folder redirection policy on users to redirect their folders to a network share for backup. I wanted to filter the GPO to not apply if user is RDP-ing into a server because imagine if multiple user RDP-ing it would using up disk space for the redirected folder caching!

    Wednesday, September 23, 2015 10:36 AM
  • > So basically i'm implementing a folder redirection policy on users to
    > redirect their folders to a network share for backup. I wanted to filter
    > the GPO to not apply if user is RDP-ing into a server because imagine if
    > multiple user RDP-ing it would using up disk space for the redirected
    > folder caching!
     
    Since RDS servers usually have a fast connection to filers, I'd suggest
    to rather disable offline files on the RDS servers. Much easier to deal
    with :-)
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    Wednesday, September 23, 2015 1:50 PM
  • Hi Martin,

    Sorry for the long overdue reply. I tried disabling offline files to no avail. Looks like folder redirection & offline files are 2 rather different policies. I end up have to abandon this. Thanks for your suggestion and help anyway! really appreciate it!

    Wednesday, September 30, 2015 9:04 AM
  • > Sorry for the long overdue reply. I tried disabling offline files to no
    > avail.
     
    Depending on how you tried, you might inadvertently have picked one of
    the Offline Policy settings that work only with XP.
     
    To make sure, disable the Offline files service (CscService).
     

    Greetings/Grüße, Martin

    Mal ein gutes Buch über GPOs lesen?
    Good or bad GPOs? - my blog…
    And if IT bothers me - coke bottle design refreshment (-:
    Wednesday, September 30, 2015 3:26 PM