Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Help With Batch And Registry


  • Please log in to reply
3 replies to this topic

#1 thisismydisplayname

thisismydisplayname

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:01:33 AM

Posted 21 November 2007 - 10:24 PM

I'm trying to make a batch file backup the registry , with the date and time of when the
backup was created. The problem is that there is some sort of problem with the
environment variables being in the paths. When this is invoked, a box pops pops up
titled "Registry Editor" saying, "Cannot export C:\autoregbackups\auto-reg-backups-
created-on-wed 11/21/07-22:20:09.37.reg:Error opening the file. There may be a disk
or file system error."

Any ideas on how I could get this to work? Here's the code I'm having problems with.


[codebox]set now=%date%-%time%
if not exist "%SystemDrive%\autoregbackups" (mkdir "%SystemDrive%\autoregbackups")
attrib "%SystemDrive%\autoregbackups" -s -h -r
attrib "%SystemDrive%\autoregbackups\explanation.txt" -s -h -r
@echo The Registry.bat file you ran always creates a backup of the registry, reguardless of weather or not the user says to. Each backup file should be a backup of only parts of the registry edited by this, and named accordingly>%SystemDrive%\autoregbackups\explanation.txt
regedit.exe /e "%SystemDrive%\autoregbackups\auto-reg-backup-created-on-%now%.reg"
attrib "%SystemDrive%\autoregbackups\auto-reg-backup-created-on-%now%.reg" +h +s +r
attrib "%SystemDrive%\autoregbackups\explanation.txt" +h +s +r
attrib "%SystemDrive%\autoregbackups" +h +s +r

echo some message so i know the stuff above executed.
pause[/codebox]

(I'm trying to make the batch file back this up and then allow the user to edit certain
things in the registry.)

Edited by thisismydisplayname, 21 November 2007 - 10:30 PM.


BC AdBot (Login to Remove)

 


#2 Platypus

Platypus

  • Moderator
  • 13,985 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Australia
  • Local time:03:33 PM

Posted 22 November 2007 - 06:35 AM

First in line would be the slash and colon characters - they can't be used in filenames.

Characters illegal in filenames: ? [ ] / \ = + < > : ; " , * |

Top 5 things that never get done:

1.


#3 usasma

usasma

    Still visually handicapped (avatar is memory developed by my Dad


  • BSOD Kernel Dump Expert
  • 25,090 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Southeastern CT, USA
  • Local time:01:33 AM

Posted 22 November 2007 - 08:34 AM

Post crashed during brain cramp! Sorry! :thumbsup:

Edited by usasma, 22 November 2007 - 08:46 AM.

My browser caused a flood of traffic, sio my IP address was banned. Hope to fix it soon. Will get back to posting as soon as Im able.

- John  (my website: http://www.carrona.org/ )**If you need a more detailed explanation, please ask for it. I have the Knack. **  If I haven't replied in 48 hours, please send me a message. My eye problems have recently increased and I'm having difficult reading posts. (23 Nov 2017)FYI - I am completely blind in the right eye and ~30% blind in the left eye.<p>If the eye problems get worse suddenly, I may not be able to respond.If that's the case and help is needed, please PM a staff member for assistance.

#4 thisismydisplayname

thisismydisplayname
  • Topic Starter

  • Members
  • 24 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:01:33 AM

Posted 22 November 2007 - 09:17 AM

with the explanations.txt, you're right, it was trying to access it before it was sure it was being created.

everything was being created by the batch though. it's just i couldn't make that one .reg file, but as i realized reading the first reply, the %date% and %time% added colons and slashes to the name, making it invalid (the source of the problem). after reading that, I got everyting else working great! (thankyou platypus)

now the only thing i need help with is suppressing the message "The operation completed successfully." I tried putting @ in front of the reg export command, but that didn't work. (echo is off)


also, here's the altered code i have for this now:

:hs3
echo You want to %hideshow% the %accedit% account, correct?
set /p confirmation=(Y/N): 
if %confirmation%==cancel (goto cancel)
if %confirmation%==n (goto hs)
if not %confirmation%==y (goto hsinvalid2)
set backedupreg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList"
set home=hs5
goto loop
:hs5
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" /t REG_DWORD /v "%ccedit%" /d "%hsvalue%" /f
echo.
goto start
:loop
if not exist "%SystemDrive%\autoregbackups" (mkdir "%SystemDrive%\autoregbackups" attrib "%SystemDrive%\autoregbackups" -s -h -r
:tworandomnumber
set filename=%random%%random%
if exist "%SystemDrive%\autoregbackups\%filename%.reg" (goto tworandomnumber)
if exist "%SystemDrive%\autoregbackups\backuplog.txt" (attrib "%SystemDrive%\autoregbackups" -s 
-h -r)
if not exist "%SystemDrive%\autoregbackups\backuplog.txt" (@echo This is the log of which registry keys have been backed up.>%SystemDrive%\autoregbackups\backuplog.txt)
@echo %filename%.reg is a backup of the %backedupreg% on %date% at %time%.>>"%SystemDrive%\autoregbackups\backuplog.txt"
@echo.>>"%SystemDrive%\autoregbackups\backuplog.txt"
@echo.>>"%SystemDrive%\autoregbackups\backuplog.txt"
@echo.>>"%SystemDrive%\autoregbackups\backuplog.txt"
@echo.>"%SystemDrive%\autoregbackups\%filename%.reg"
@reg export %backedupreg% "%SystemDrive%\autoregbackups\%filename%.reg"
attrib "%SystemDrive%\autoregbackups\backuplog.txt" +s +h +r
attrib "%SystemDrive%\autoregbackups\%filename%.reg" +h +s +r
attrib "%SystemDrive%\autoregbackups" +h +s +r
goto %home%

it all works fine, and there are absolutely no problem with any of the variables in it.

Edited by thisismydisplayname, 22 November 2007 - 09:22 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users