Quantcast
Channel: StudioSysAdmins Message Board
Viewing all articles
Browse latest Browse all 3749

Setting environment variables in Windows login scripts

$
0
0
By Nick Allevato -
hmm curious por sue why not GPO?


On Fri, Jul 19, 2013 at 12:49 PM, Jean-Francois Panisset <panisset@gmail.com> wrote:
This may be old news to experienced Windows folks, but we just spent a bunch of time trying to get this to work, so I figured I would share. In a Windows 7 environment, you may want to set environment variables via a login script (and for some reason the GPO approach may not be appropriate), but the problem is that by the time Windows is processing the login script, the rest of the environment (Windows Explorer and such) already exists, so your environment variables are set in a subshell (probably wrong terminology) and don't affect the rest of your environment. They do get recorded in the Registry, so when you log out and log back in you will then get the values you want, but this can cause some weird problems when someone logs in to a machine for the first time, or when values change in the login script but don't appear to propagate.

Apparently the only way to get your current session to see environment variable updates is to send a WM_SETTINGCHANGE Win32 message to all running processes, which tells them to refresh their environment. This can be done from PowerShell:

http://poshcode.org/2049

but that requires enabling PowerShell script execution on every client. As an alternative, here's a small C program that you can call at the end of your login script:

#include <Windows.h>

int main(int argc, char* argv[])

{DWORD dwReturnValue = 0;

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue);

return dwReturnValue;

}

JF


To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscribe



--
Nick Allevato | Systems Administrator?
5th Kind?Digital Asset Management
www.5thkind.com | c:?661.645.3507




Viewing all articles
Browse latest Browse all 3749

Trending Articles