{solved}Broken Batch File

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rooster5105
Posts: 2
Joined: 31 May 2012 19:36

{solved}Broken Batch File

#1 Post by rooster5105 » 31 May 2012 19:45

I wrote a batch file that randomly selects an image from a specified directory and copies it to system32\oobe\info\backgrouds\backgrounddefault.jpg to customize my logon screen.

This batch worked when I wrote it and for almost 3 years after. Had to reinstall my laptop the other day, so I dug it out of burial, and now I cannot get it to work.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set folder=C:\Users\Rooster\backgroundgirls\
set destination=c:\Windows\System32\oobe\info\backgrounds\backgroundDefault.jpg
set count=0
set x=0
for /r "%folder%" %%G in (*.jpg) do (
echo %%G
set /a BACK_!count!=%%~G
set /a count+=1
echo count = !count!
)

set /a x="%random% %% count"
echo !x!
set chosen=!BACK_%x%!
echo chosen = %chosen%
copy /y “%chosen%” “%destination%” 1>nul


I am not quite sure what's failing here, except that %chosen% always equals zero (which means, no background is chosen) anyone got any ideas just from reading it? (PS Mind the unnecessary echos, using them to debug things)

System info:
Gateway NV55S02U
AMD A6-3400 APU w/ Integrated Radeon HD 6520M
Windows 7 Home Premium SP1

Edit:: Marked as solved
Last edited by rooster5105 on 31 May 2012 20:20, edited 1 time in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help! This batch file suddenly broke, I don't know why!

#2 Post by Squashman » 31 May 2012 20:03

Not on a pc right now but I am pretty sure since you are copying to the system directory the batch file would need to be run with elevated privileges on Windows 7.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help! This batch file suddenly broke, I don't know why!

#3 Post by foxidrive » 31 May 2012 20:05

In this line take out the /a

set /a BACK_!count!=%%~G


And check the double quotes in the copy command - they are not regular double quotes.

rooster5105
Posts: 2
Joined: 31 May 2012 19:36

Re: Help! This batch file suddenly broke, I don't know why!

#4 Post by rooster5105 » 31 May 2012 20:11

Gah!!!

Foxdrive, thanks a mil man, I had put that /a in there last night as just a test, the real problem it turns out was those damned quotes. I would have never even have thought to look at that. Well, now the only thing left to do is edit this batch into the registry. Thanks again!

~Rooster

(P.S.) How do I mark as solved?

Post Reply