Solved

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

Posted on 2008-06-25
7
1,663 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
  • 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 500 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
This article will show, step by step, how to integrate R code into a R Sweave document
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

820 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