Batch File Add System Variable

2020. 3. 1. 12:54카테고리 없음

  1. Variables In Batch Files
Batch

Variables In Batch Files

We have a program that is used on all our systems that needs the 'Environment Variables' under 'User Variables'for 'TEMP' and 'TMP' changed fromVariable name: TEMPVariable value:%USERPROFILE%AppDataLocalTempVariable name: TMPVariable value:%USERPROFILE%AppDataLocalTempTo:Variable name: TEMPVariable value: C:TempVariable name: TMPVariable value: C:TempIs there any way to do this through a command prompt?I am hoping to make a batch file that i can run on pc's instead of manually editing each pc through the control panel. You could use a combination of SETX (included on Vista and later, or as a download for XP) and PSEXEC:Download which will contain PSEXEC (it is a command line utility so run from cmd.exe).Then run PSEXEC against a file that contains (one per line) each IP address or domain name of each host you want to address and issue the SETX command.All in all would look something like this:psexec.exe @file cmd /C SETX PATH '%TEMP%;C:Temp'You may also want to specify domain admin credentials (note these go out in the clear) or common local admin credentials with the -u and -p arguments. Yep, there are many ways to do this.Do note that if you are not in a domain environment, the GPO method would not work and as long as you have a set of local administrator credentials common among machines, the route I wrote out would work. In the same way you could use PSEXEC to add the.reg file route as well.If you are on a domain, the GPO route may be the best (and safest) method.A third way (just so you have options) is to write a simple.bat file with either the.reg add command or the SETX command and put that on a file share. Then use the free Specops GPupdate program to 'Run an executable remotely' and call the batch file. The benefit of this route is that you will get real-time feedback on what computers you successfully hit and which failed.Edit: This requires being on a domain, but at least gives you feedback of success/failure vs the emptiness of a gpupdate.