Solved

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

Posted on 2008-06-25
7
1,664 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 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

734 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