?
Solved

How to silently execute a .reg file within batch scripting.

Posted on 2008-06-25
7
Medium Priority
?
1,667 Views
Last Modified: 2012-08-14
Hello,

I have a batch file that does a few things and one of them I'm having trouble making it do is add a .reg file to the registry.  The file is named "cleanmgr.reg."  I want this registry information added before diskcleanup runs, because it will dictate what disk cleanup will remove.  I'm using Notepad and 'word wrap' is turned off.  It's not adding the file to the registry though.  Here is my code for trying to add it via script:

:dskClean
REGEDIT.exe /S cleanmgr.reg
CLEANMGR /sagerun:#
0
Comment
Question by:zbox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 

Author Comment

by:zbox
ID: 21864615
Things I have tried:

I have opened command prompt.  Ran ' regedit.exe cleanmgr.reg ' and this is without the /s, so it prompts me "Do you really want to add this to the registry."  I select, yes, and get this error: "Cannot importn cleanmgr.reg: Error opening the file.  There may be a disk or file system error."

But I know nothing is wrong with the file, because I can go to the file itself, double click on it and select, yes, to add it to registry and it works!  However, what I need is for it too successfully be added via my batch file.

Thanks for any ideas or comments,

zbox
0
 
LVL 3

Accepted Solution

by:
ofkr earned 2000 total points
ID: 21864649
Can you try to give full path for cleanmgr.reg. eg. "C:\scripts\cleanmgr.reg"

REGEDIT.exe /s "C:\scripts\cleanmgr.reg"

If you still can't manage, you will need to check your syntax in reg file.
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21864658
Have you tried using reg import?

Also, try specifying the full path to the reg file you want to import - most likely it is this causing it to fail if manually importing works.
reg import cleanmgr.reg

Open in new window

0
Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

 
LVL 3

Expert Comment

by:ofkr
ID: 21864663
Do you include RegistryEditorVersion "REGEDIT4" in your .reg file?

Format should be
---------------------------
RegistryEditorVersion
Blank line
[RegistryPath1]
"DataItemName1"="DataType1:DataValue1"
DataItemName2"="DataType2:DataValue2"
Blank line
[RegistryPath2]
"DataItemName3"="DataType3:DataValue3"
0
 
LVL 3

Expert Comment

by:ofkr
ID: 21864694
Also check if you are pointing some local file within your file, you should use double backslash instead of one. something like  C:\\Program Files\\Microsoft ActiveSync\\Profiles
0
 

Author Comment

by:zbox
ID: 21866108
the first solution worked.  I did try the file path method, but you know what I forgot to add the " " around the filepath.  I'm still learning!  hehe.  but I'm glad it was an easy fix.  

Thanks again for fast response and great ideas from all of you, I learned a lot this question.

zbox
0
 

Author Closing Comment

by:zbox
ID: 31470517
Thanks.  I didn't know the filepath required parantheses "".  That solved the problem with flying colors! woot!!

thanks again EE

zbox
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question