Jump to content

help for "reg add" command in *.cmd


darksimoon

Recommended Posts

hi friends :hello:

i want to chance the default place of my temp folders and then delete previous temp folders and clean new temp folder

to do this, i have wrote a cmd file as follows

=========newtemp.cmd=================

md %systemdrive%\temp

rd /s /q "%userprofile%\Local Settings\Temp"

rd /s /q "%systemdrive%\Documents and Settings\Administrator\Local Settings\Temp"

rd /s /q "%systemdrive%\Documents and Settings\Default User\Local Settings\Temp"

rd /s /q "%systemroot%\temp"

reg add newtemp.reg

DEL /F /S /Q "%systemdrive%\TEMP\*.*"

==========================

and a reg file to chance the default places for temp folders

========newtemp.reg==================

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]

"TEMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,00,76,\

00,65,00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00

"TMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,00,76,00,\

65,00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]

"TEMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,00,76,\

00,65,00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00

"TMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,00,76,00,\

65,00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager\Environment]

"TEMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,00,76,\

00,65,00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00

"TMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,00,76,00,\

65,00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00

[HKEY_CURRENT_USER\Environment]

"TEMP"="%systemdrive%\\Temp"

"TMP"="%systemdrive%\\Temp"

==========================

here is the question; instead of applying registry entries with the "reg add newtemp.reg" command from my batch file, why not write it inside my newtemp.cmd file like runonceex.cmd ? in this way one cmd file is enough both cleaning temp folders and chancing the default temp folders.

but i dont know how to do that.

i tried to do it by learning the parameters from reg add /? in a cmd window but it didnt work. it allways give me "too many parameters" error.

pls show me a general info and example so that i can do it by myself... :) thanks in advance.

Link to comment
Share on other sites


To apply a regfile, you have to use the reg import command. So in your runonceex.cmd you should use the command "reg add newtemp.reg".

A little better would be to use this line in your cmdlines.txt, cause when it is executed there, no user except the default user exists and so the HKCU entries are taken for the default user, also for the user you run the runonceex with.

Edited by Doc Symbiosis
Link to comment
Share on other sites

@ darksimoon

In your example, you need to change

  • reg add newtemp.reg to regedit /s newtemp.reg

Here is a way you can redirect the 'user temp' folders to the same location as '\WINDOWS\Temp' for everyone at once with no requiremrnt to remove them later in your cleanup routine. Use this in cmdlines.txt

@Echo off&Pushd %UserProfile%\..\Default User
Reg load HKU\TempHiv NTUSER.DAT>Nul 2>&1||Goto :Eof
Reg add HKU\TempHiv\Environment /v TEMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
Reg add HKU\TempHiv\Environment /v TMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
:Un_
Reg unload HKU\TempHiv>Nul 2>&1||Goto Un_

Although this is not what you require, it shows you the REG ADD syntax you can use and a method of applying current user registry entries to all users.

Link to comment
Share on other sites

Here is a way you can redirect the 'user temp' folders to the same location as '\WINDOWS\Temp' ...

Is this alike the option that is available in nlite? I was curious incase I needed to do look into this way of changing it myself to the temp folder like you showed. Thanks

tmp1sp.th.jpg

Edited by matthewk
Link to comment
Share on other sites

  • 2 weeks later...

hello yzwöl

how are you friend? i tried the cmd file you provide me but it didnt work and gave me error in a way that "wrong parameter" that occurs twice at the same window. in order to determine the fault, i made a new cmd file which contains just these lines:

code

====================================

Reg add HKU\TempHiv\Environment /v TEMP /t REG_EXPAND_SZ /d "%%SYSTEMROOT%%\Temp" /f>Nul

Reg add HKU\TempHiv\Environment /v TMP /t REG_EXPAND_SZ /d "%%SYSTEMROOT%%\Temp" /f>Nul

====================================

and the result is same. i mean the fault must be somewhere here. can you help me pls about it. and meanwhile i want to assign all temp and tmp folders to %systemdrive% not %systemroot% in order to avoid defragmentation in the system folder. pls help me about it or correct me if i am wrong... thanks in advance :)

@matthewk

hey friend thanks for your help. as amatter of fact i want to do it in unattended way. but it might be helpfull by registry snapping method. but this is my last alternative..

Link to comment
Share on other sites

@Echo off&Pushd %UserProfile%\..\Default User
Reg load HKU\TempHiv NTUSER.DAT>Nul 2>&1||Goto :Eof
Reg add HKU\TempHiv\Environment /v TEMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
Reg add HKU\TempHiv\Environment /v TMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
:Un_
Reg unload HKU\TempHiv>Nul 2>&1||Goto Un_

Can you explain the double pipe || in your batch script.

Link to comment
Share on other sites

Try this instead!

@Echo off
Reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TEMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
Reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
Pushd %UserProfile%\..\Default User
Reg load HKU\TempHiv NTUSER.DAT>Nul 2>&1||Goto :Eof
Reg add HKU\TempHiv\Environment /v TEMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
Reg add HKU\TempHiv\Environment /v TMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
:Un_
Reg unload HKU\TempHiv>Nul 2>&1||Goto Un_

@darksimoon

Just change the %SystemRoot% to %SystemDrive% etc. as necessary for your purposes.

<Edit>

Bilou the double pipe just means 'if unsuccessful then'

</Edit>

Edited by Yzöwl
code tags fixed for easier to read code
Link to comment
Share on other sites

  • 1 month later...

@Yzöwl

hello Yzöwl, how are you ? :) i hope you're in a good mood. :)

friend, i have tried your batch file but it gave an error message called "too many parameters" i opened it to understand and categorized (in order to understand easly and tidy since the copy/paste has made it untidy) but it looks allright. nothing seems wrong. i also examine and compared your batch file about superhidden files.

So i have decided to send you the batch file itself in order to prevent misunderstanding. can you check and correct it for me please ? i dont want to tire you and i have done my best. as a last solution i am applying you.

thanks in advance :)

temp_tidied_.cmd

Link to comment
Share on other sites

You need to add quotes around the first two key names as they have a space in them

Reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TEMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul
REG add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TMP /t REG_EXPAND_SZ /d "%%SystemRoot%%\Temp" /f>Nul

Link to comment
Share on other sites

  • 1 year later...

I'm trying to do the exact opposite on my Windows 2000 install.

Although each user does have a Temp folder (located in the Local Settings folder of their user account) there is still a useless Temp folder in C:\Windows that I would like to get rid of.

I can't just delete the folder using a batch file because it's considered "in use" due to the two Session manager environment Registry keys that define TEMP and TMP as %SystemRoot%\TEMP.

If I just go through and replace all instances of %%SystemRoot%%\TEMP with %%USERPROFILE%%\Local Settings\Temp in Yzöwl's cmdlines.txt example, will it prevent the creation of the %SystemRoot%\TEMP reg key and C:\Window\Temp folder so that I don't have to subsequently delete them?

Link to comment
Share on other sites

  • 3 years later...

Hi Friend,

First of all I am not a computer savvy like you. I have a silly doubt.

I am trying to add and delete some registry keys so wat I did was I typed (((((reg add "hklm\system\currentcontrolset\control\session manager\PendingFileRenameOperations" /f

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" /f)))))))

this in a notepad. Can u please tell me how to execute this? I mean wat I am trying to do is if I click on that file it should create an entry in registry.

Thanxs in Advance

From Laxmi.

Link to comment
Share on other sites

this in a notepad.

Why all those brackets? :unsure:

Have in Notepad:


@ECHO OFF
ECHO reg add "hklm\system\currentcontrolset\control\session manager\PendingFileRenameOperations" /f
reg add "hklm\system\currentcontrolset\control\session manager\PendingFileRenameOperations" /f
PAUSE
ECHO reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" /f
PAUSE

save the file as "all files" manually giving it a .cmd extension.

Double click on it.

If it does what you want, you can remove the ECHO lines and the PAUSE statements allright.

Please NOTE that the board software wrap arounds long lines, make sure that the lines that seem like beginning with "Auto Update" are actually the "tail of the preceding line.

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...