• I have a sheduling engine that runs jobs on windows 2003 server.
  • It runs as a particular domain user DOM\mtidsql.
  • I don't have access to log on as the user but I have admin access.
  • I need to be able to script storing a password in an environment variable that is specific to the user
  • The user does not appear to have an environment on the target platform because HKU\SID does not exist in the registry for the user. (SID is the users domain SID) but it has a profile C:\Documents And Settings\mtidsql
  • HKU\SID does not exist
  • I cant add HKU\SID\Environment\VAR_NAME .... using reg.exe, it returns ERROR: The parameter is incorrect.

Here's a few ideas:

  • You could mount the user's registry hive and add the value manually. Look at the "Load Hive..." functionality in REGEDIT.

  • You could logon interactively as the user and add the appropriate value using the GUI.

  • You could use "RUNAS" to open a command-prompt as the user and add the value to their registry (HKEY_CURRENT_USER\Environment) from there.

  • Thanks: GUI is not an option, this is a scripted install + I don't know the user password May 11 '11 at 14:19
  • @Paddy Carroll: When you say "a scripted install" it makes me wonder if you can just shoehorn a "REG ADD HKEY_CURRENT_USER\..." into the installation script. If not, look at using "REG LOAD" and "REG UNLOAD" to load the user's hive, add the entry to it, and unload the hive. May 11 '11 at 14:41
  • REG ADD has been tried and failed ( as described ), reg load\save only operate on the local machine May 12 '11 at 9:52
  • @Paddy Carroll: Your posting doesn't mention the use of "REG ADD". It does indicate that you're trying to add to "HKU\SID\...". That's going to be problematic. Running "REG ADD HKCU\..." or loading the user's hive and modifying it will work. Adding to "HKU\SID\..." will not. Insofar as "REG LOAD" running on the local machine just run the script on the machine where the profile is located. Why can't you do that? You can also "REG LOAD" a hive from a UNC path just fine, too, so you could mount the hive on your machine remotely, modify it, and unmount it. May 12 '11 at 12:02

You can probably use Group Policy Preferences to set the environment variable, but I've not really tested it for a user like you describe. And like any GPO, you can put security filtering on it to ensure that only the one user can apply it. Example given below:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.