Changes to registry using a batch file

P

Patrick

Hello,

I am trying to modify the following key from:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="F:\I386"

to:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"

using a batch file with the "REG import" command to call a .reg file.
If I launch the batch file in a command prompt I get "The operation
completed successfully". But after I check regedit the changes were
not made. I

f I double click on the reg file and click on yes the changes are
made.

Your help is greatly appreciated
 
P

Pegasus [MVP]

Patrick said:
Hello,

I am trying to modify the following key from:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="F:\I386"

to:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"

using a batch file with the "REG import" command to call a .reg file.
If I launch the batch file in a command prompt I get "The operation
completed successfully". But after I check regedit the changes were
not made. I

f I double click on the reg file and click on yes the changes are
made.

Your help is greatly appreciated

Let's have a look at your batch file and your .reg file.
 
J

Jon Wallace

Hey Patrick,

A couple of things...

This might sound like a silly question but are you refreshing (F5) your
REGEDIT view when you have run your batch file. To see the change you
typically have to refresh if you already have REGEDIT open and at the key...

Secondly, rather than maintaining a seperate .REG file, you can use the
following command to achieve what you want - it's a bit cleaner -

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v SourcePath /t
REG_SZ /d "C:\I386" /f

Hope this helps,
Jon

www.insidetheregistry.com
 
P

Patrick

The batch file is :

REG import \\orion\Install\Programs\Microsoft\SNMP\path.reg
REG import \\orion\Install\Programs\Microsoft\SNMP\root.reg

First .REG file is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"

and second .REG is

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"SourcePath"="C:\"

Thank you

I am trying to modify the following key from:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="F:\I386"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"
using a batch file with the "REG import" command to call a .reg file.
If I launch the batch file in a command prompt I get "The operation
completed successfully". But after I check regedit the changes were
not made. I
f I double click on the reg file and click on yes the changes are
made.
Your help is greatly appreciated

Let's have a look at your batch file and your .reg file.- Hide quoted text -

- Show quoted text -
 
P

Pegasus [MVP]

The batch file is :

REG import \\orion\Install\Programs\Microsoft\SNMP\path.reg
REG import \\orion\Install\Programs\Microsoft\SNMP\root.reg

First .REG file is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"

and second .REG is

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"SourcePath"="C:\"

Thank you

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

There is a simple but highly effective method to solve such problems: You
use the "reg export" function to see what the format should look like, then
you apply the same rules to your own import. If you did this then you would
immediately see that you must double all back-slashes.
 
P

Patrick

Hey Patrick,

A couple of things...

This might sound like a silly question but are you refreshing (F5) your
REGEDIT view when you have run your batch file.  To see the change you
typically have to refresh if you already have REGEDIT open and at the key....

Secondly, rather than maintaining a seperate .REG file, you can use the
following command to achieve what you want - it's a bit cleaner -

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v SourcePath/t
REG_SZ /d "C:\I386" /f

Hope this helps,
Jon

www.insidetheregistry.com

--




I am trying to modify the following key from:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="F:\I386"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"
using a batch file with the "REG import" command to call a .reg file.
If I launch the batch file in a command prompt I get "The operation
completed successfully". But after I check regedit the changes were
not made. I
f I double click on the reg file and click on yes the changes are
made.
Your help is greatly appreciated

Hi John,

I did refresh I even restarted the machine but not changes. Would the
add command work even if the key is already created?

Regards
 
P

Patrick

The batch file is :

REG import \\orion\Install\Programs\Microsoft\SNMP\path.reg
REG import \\orion\Install\Programs\Microsoft\SNMP\root.reg

First .REG file is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"

and second .REG is

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"SourcePath"="C:\"

Thank you

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

There is a simple but highly effective method to solve such problems: You
use the "reg export" function to see what the format should look like, then
you apply the same rules to your own import. If you did this then you would
immediately see that you must double all back-slashes.

Actually I did that and the reg entry contained the double
backslashes, but I removed them when it did not work just to test it.
Sorry I copied the modified reg file. But the weird thing is if I use
the reg import command in the batch file "with the double back slash"
it doesn't work but when I double click on the reg file and click on
Yes it works.
 
J

Jon Wallace

Yes... that's what the /f switch is for at the end of it - to force
overwrite without prompt...

Do a REG ADD /? in the command prompt to see the full syntax...

Hope this helps,
Jon

www.insidetheregistry.com

---

Hey Patrick,

A couple of things...

This might sound like a silly question but are you refreshing (F5) your
REGEDIT view when you have run your batch file. To see the change you
typically have to refresh if you already have REGEDIT open and at the
key...

Secondly, rather than maintaining a seperate .REG file, you can use the
following command to achieve what you want - it's a bit cleaner -

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v SourcePath
/t
REG_SZ /d "C:\I386" /f

Hope this helps,
Jon

www.insidetheregistry.com

--




I am trying to modify the following key from:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="F:\I386"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"
using a batch file with the "REG import" command to call a .reg file.
If I launch the batch file in a command prompt I get "The operation
completed successfully". But after I check regedit the changes were
not made. I
f I double click on the reg file and click on yes the changes are
made.
Your help is greatly appreciated

Hi John,

I did refresh I even restarted the machine but not changes. Would the
add command work even if the key is already created?

Regards
 
P

Pegasus [MVP]

The batch file is :

REG import \\orion\Install\Programs\Microsoft\SNMP\path.reg
REG import \\orion\Install\Programs\Microsoft\SNMP\root.reg

First .REG file is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"

and second .REG is

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"SourcePath"="C:\"

Thank you

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

There is a simple but highly effective method to solve such problems: You
use the "reg export" function to see what the format should look like,
then
you apply the same rules to your own import. If you did this then you
would
immediately see that you must double all back-slashes.

Actually I did that and the reg entry contained the double
backslashes, but I removed them when it did not work just to test it.
Sorry I copied the modified reg file. But the weird thing is if I use
the reg import command in the batch file "with the double back slash"
it doesn't work but when I double click on the reg file and click on
Yes it works.

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

I strongly disagree. I tested your command before posting my reply and it
behaved as expected. I think you're not reporting everything you do or see,
same as you did not report the double backslash issue in your original post.
 
P

Patrick

"Patrick" <[email protected]> wrote in message
The batch file is :
REG import \\orion\Install\Programs\Microsoft\SNMP\path.reg
REG import \\orion\Install\Programs\Microsoft\SNMP\root.reg
First .REG file is:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"
and second .REG is
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"SourcePath"="C:\"

Thank you
===================

There is a simple but highly effective method to solve such problems: You
use the "reg export" function to see what the format should look like,
then
you apply the same rules to your own import. If you did this then you
would
immediately see that you must double all back-slashes.

Actually I did that and the reg entry contained the double
backslashes, but I removed them when it did not work just to test it.
Sorry I copied the modified reg file. But the weird thing is if I use
the reg import command in the batch file "with the double back slash"
it doesn't work but when I double click on the reg file and click on
Yes it works.

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

I strongly disagree. I tested your command before posting my reply and it
behaved as expected. I think you're not reporting everything you do or see,
same as you did not report the double backslash issue in your original post.

It's up to you to believe what you want, I have nothing to hide as I
want to solve this issue. Btw I agree with you that this command
should work since have another batch file which modify an entry in the
HKEY_Classes and it works perfectly it's just this one that is not
working eventhough I receive "The operation
completed successfully" but no changes.
 
P

Pegasus [MVP]

"Patrick" <[email protected]> wrote in message
The batch file is :
REG import \\orion\Install\Programs\Microsoft\SNMP\path.reg
REG import \\orion\Install\Programs\Microsoft\SNMP\root.reg
First .REG file is:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"
and second .REG is
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"SourcePath"="C:\"

Thank you
===================

There is a simple but highly effective method to solve such problems:
You
use the "reg export" function to see what the format should look like,
then
you apply the same rules to your own import. If you did this then you
would
immediately see that you must double all back-slashes.

Actually I did that and the reg entry contained the double
backslashes, but I removed them when it did not work just to test it.
Sorry I copied the modified reg file. But the weird thing is if I use
the reg import command in the batch file "with the double back slash"
it doesn't work but when I double click on the reg file and click on
Yes it works.

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

I strongly disagree. I tested your command before posting my reply and it
behaved as expected. I think you're not reporting everything you do or
see,
same as you did not report the double backslash issue in your original
post.

It's up to you to believe what you want, I have nothing to hide as I
want to solve this issue. Btw I agree with you that this command
should work since have another batch file which modify an entry in the
HKEY_Classes and it works perfectly it's just this one that is not
working eventhough I receive "The operation
completed successfully" but no changes.

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

The message "completed successfully" is misleading - you see it regardless
of the result.

To find out the cause of your problem, do this:
1. Manually create a registry value that is very similar to the one you wish
to import.
2. Use "reg.exe export" to export this value to a .reg file.
3. Modify this file slightly.
4. Use "reg.exe import" to import the modified value.
5. Use the same format for your real registry import.
End of story!
 
P

Patrick

"Patrick" <[email protected]> wrote in message
Thebatchfileis :
REG import \\orion\Install\Programs\Microsoft\SNMP\path.reg
REG import \\orion\Install\Programs\Microsoft\SNMP\root.reg
First .REGfileis:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"SourcePath"="C:\I386"
and second .REG is
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup]
"SourcePath"="C:\"
Thank you
===================
There is a simple but highly effective method to solve such problems:
You
use the "reg export" function to see what the format should look like,
then
you apply the same rules to your own import. If you did this then you
would
immediately see that you must double all back-slashes.
Actually I did that and the reg entry contained the double
backslashes, but I removed them when it did not work just to test it.
Sorry I copied the modified regfile. But the weird thing is if I use
the reg import command in thebatchfile"with the double back slash"
it doesn't work but when I double click on the regfileand click on
Yes it works.

I strongly disagree. I tested your command before posting my reply and it
behaved as expected. I think you're not reporting everything you do or
see,
same as you did not report the double backslash issue in your original
post.

It's up to you to believe what you want, I have nothing to hide as I
want to solve this issue. Btw I agree with you that this command
should work since have anotherbatchfilewhich modify an entry in the
HKEY_Classes and it works perfectly it's just this one that is not
working eventhough I receive  "The operation
completed successfully" but nochanges.

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

The message "completed successfully" is misleading - you see it regardless
of the result.

To find out the cause of your problem, do this:
1. Manually create aregistryvalue that is very similar to the one you wish
to import.
2. Use "reg.exe export" to export this value to a .regfile.
3. Modify thisfileslightly.
4. Use "reg.exe import" to import the modified value.
5. Use the same format for your realregistryimport.
End of story!

Thank you both for your help I tried the

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v
SourcePath /t
REG_SZ /d "C:\I386" /f

and it worked perfectly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top