# Reg in Batch file help



## MikeSwim07 (Apr 28, 2007)

I have this command in my batch file,

reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Test123 /d "%Systemdrive%\test123.bat" /f

And it doesn't add it to the registry, why?

Thanks


----------



## jdean (Jan 20, 2002)

Works fine for me. I get a message saying "The operation completed successfully". Are you seeing this? Are you sure that you have checked the value in the registry? Try reg with the /QUERY option.

Or are you saying that the autorun doesn't work? I haven't tested this but I suspect you need to specify the name of an executable and that a batch file won't work properly. The way to handle this would be something like:

%ComSpec% /c %SystemDrive%\test123.bat

Or you could avoid all of this (the registry and the cmd /c) by just copying the batch file into the Startup folder.


----------



## MikeSwim07 (Apr 28, 2007)

> Works fine for me. I get a message saying "The operation completed successfully". Are you seeing this?


No


----------



## MikeSwim07 (Apr 28, 2007)

It's saying:

"Error: Too many command-line paramaters"


----------



## jdean (Jan 20, 2002)

I copied the line from your original message, pasted it into a batch file, and ran it without a problem. Can you try doing this just to make sure we're doing exactly the same thing?

If this fails, please type "reg" at the command prompt. When I do this, it says:

Console Registry Tool for Windows - version 3.0

and then provides some information on how to use the command. Do you see the same thing? What operating system are you using?


----------



## Codiah (Sep 27, 2008)

A good solution to this is to have your batch file write the .reg file..

Reg file information here>> myregfile.reg

have it write it out that way and then have it run the reg file silently and then delete the written reg file... a good work around for when things don't want to cooperate..


----------



## MikeSwim07 (Apr 28, 2007)

When I only typed "reg" in cmd, I got what you got above.

This is what I get back from the batch file, 

Error: Too many command-line parameters

I am using Windows XP


----------



## Codiah (Sep 27, 2008)

Put this inside of your batch file, it will do the trick.. it will write a registry file, apply it, and delete the registry file so it doesn't get left on the drive..


```
ECHO Windows Registry Editor Version 5.00>> test123.reg
ECHO.>> test123.reg
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]>> test123.reg
; add>> test123.reg
"Test123"="%Systemdrive%\test123.bat">> test123.reg
::
REGEDIT.exe /S test123.reg
DEL /Q test123.reg
```
Should fix your problem...


----------



## MikeSwim07 (Apr 28, 2007)

Why did you add this to your reg file?

; add>> test123.reg


----------



## Codiah (Sep 27, 2008)

Just the way i've always done it... Dunno if it would make a difference or not without it...


----------



## devil_himself (Apr 7, 2007)

Can You Try This One And Tell Me The Results


```
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Test123" /d "%Systemdrive%\test123.bat" /f
```


----------



## TheOutcaste (Aug 8, 2007)

MikeSwim07 said:


> reg ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Test123 /d "%Systemdrive%\test123.bat" /f





devil_himself said:


> ```
> reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Test123" /d "%Systemdrive%\test123.bat" /f
> ```


Both of these work for me just fine



MikeSwim07 said:


> "Error: Too many command-line paramaters"


This is often due to a space in a parameter that isn't quoted. If you type *Current Version* instead of *CurrentVersion* in the key name you'll get that error. If you copy and paste the line it shouldn't happen though, as there is no space in the key name, so I don't know why it's not working for you.



MikeSwim07 said:


> Why did you add this to your reg file?
> 
> ; add>> test123.reg


any line starting with a ; is a comment. it's not needed, it's just there to document what the file is doing.

I did have one strange incident a while back. Seems the command prompt couldn't read end of line characters properly so any lines that did not have a blank line in between were being combined and executed as one line. Closing then re-opening the Command Prompt fixed that though. You might try rebooting just for grins.

Jerry


----------



## Genocide_Hoax (Oct 26, 2008)

It works fine for me, may be when you saved the file you had your notepad's wordwrap checked thts why its not wrkin on ur side, so edit the file uncheck the word wrap and save it again. The whole command must be in the same line. Secondly, If you are trying to run the bat using a program or something then you have to use "\\" instead of "\".


----------

