Solved

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

Posted on 2008-06-25
7
1,659 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:ofkr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.  I didn't know the filepath required parantheses "".  That solved the problem with flying colors! woot!!

thanks again EE

zbox
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
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)

744 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

17 Experts available now in Live!

Get 1:1 Help Now