Solved

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

Posted on 2008-06-25
7
1,660 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now