Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My research says there are four ways to do this. I started at the <a href="http://technet.microsoft.com/en-us/library/cc757263.aspx" rel="noreferrer">Microsoft Logon Script documentation pages and fanned out from there</a>.</p> <h1>Login Script Batch File</h1> <h2>Windows Server 2000, 2003, 2008</h2> <p>Login batch file (.BAT) scripts are just a temporary instance of a CMD window, and the environment variables set in there go away as soon as the login window closes.</p> <pre><code>set MYVAR=MyValue </code></pre> <p>Won't work for the aforementioned reason.</p> <p>So, alternatively, I can try to set the variable via directly writing to the registry like so for a System Environment Variable:</p> <pre><code>reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v MYVAR /t REG_EXPAND_SZ /d MyValue </code></pre> <p>or to the User Environment Variables like so:</p> <pre><code>reg add HKCU\Environment /v MYVAR /t REG_EXPAND_SZ /d MyValue </code></pre> <p>The drawback here is that the variables, though written to registry, are not read until the next login for all I can see. A new CMD window shows no trace of them until the user re-logs-in.</p> <p><br/></p> <h1>Login Script WSH VBS File</h1> <h2>Windows Server 2000, 2003, 2008</h2> <p>With a Visual Basic Script (VBS) login script, you can use a more programmatic method to access the environment variables. This is looking like my most viable approach. <a href="http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23898348.html" rel="noreferrer">This example would append to the end of PATH</a>.</p> <pre><code>Set WSHShell = WScript.CreateObject("WScript.Shell") Set WshEnv = WshShell.Environment("SYSTEM") WshEnv("Path") = WshEnv("Path") &amp; ";M:\DB\whatever\" </code></pre> <p>This example would just set the variable.</p> <pre><code>Set WSHShell = WScript.CreateObject("WScript.Shell") Set WshEnv = WshShell.Environment("SYSTEM") WshEnv("MYVAR") = "MyNewValue" </code></pre> <p>This approach yields variables that are immediately available via a CMD window. No reboot is required like the batch file registry writes.</p> <p><br/></p> <h1>ADM File</h1> <h2>Windows Server 2000, 2003, 2008</h2> <p>ADM files are a way to expose custom functionality of settings to the Group Policy Editor. It seems tricky to get them installed and visible on the domain controller so I'm jumping over this option.</p> <p><a href="http://support.microsoft.com/default.aspx?scid=228460" rel="noreferrer">Microsoft Support TechNet Reference on ADM File Locations.</a><br/> <a href="http://www.winserverkb.com/Uwe/Forum.aspx/windows-server-sbs/17515/SBS-Group-Policy-to-assign-registry-settings" rel="noreferrer">Another article about ADM files and using them to set Registry settings.</a><br/> <a href="http://www.tomshardware.com/forum/221564-46-adding-environment-variables" rel="noreferrer">Tom's Hardware on ADM Files.</a></p> <pre><code>---- set.adm ---- CLASS MACHINE CATEGORY "Environment" POLICY "Self dfined variables" KEYNAME "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" PART "Set MyVar1 =" EDITTEXT DEFAULT "MyValue1" VALUENAME MyVar1 ; EXPANDABLETEXT ; add expandabletext if it can contain Variables itself END PART END POLICY END CATEGORY ---- set.adm ---- </code></pre> <p><br/></p> <h1>Group Policy Preferences (GPP)</h1> <h2>Windows Server 2008</h2> <p>Windows Server 2008 h<a href="http://www.thincomputing.net/blog/windows-server-2008-group-policy-preferences-the-end-of-the-login-sc.html" rel="noreferrer">as a new feature</a> called the <a href="http://technet.microsoft.com/en-us/library/cc770493.aspx" rel="noreferrer">Environment Extensions for the Group Policy Preferences</a>. It allows you to conveniently set what otherwise required complex batch scripts. The new items exposed include registry values, environment variables, and more. <a href="http://www.gpoguy.com/Portals/0/Group%20Policy%20Preferences%20Overview.pdf" rel="noreferrer">A quick how-to guide is available here</a>.</p> <p>I can't use this option because my clients don't have Windows Server 2008.</p> <p><br/></p> <h1>Summary</h1> <p>Please tell me based on your experiences as Windows Administrators which of these works best and why. I'm just a desktop developer, and need an admin's insight.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload