How to change the wallpaper randomly to all users of the domain every day without being repeated?

Hello All,

I come to you because I need your help!

Currently I have a Batch and Script, which allows me to change the wallpaper automatically and randomly to all users of the domain, both work changing the images, however I have noticed that sometimes repeats a wallpaper without finishing the cliclo of xx images published in a folder.

Greetings and thanks from the atheist for your valuable help!

Richard AbogadoSystem Administrator OSAsked:
Who is Participating?
Steve KnightConnect With a Mentor IT ConsultancyCommented:
If you do want to continue in a similar way to now I would suggest something like this... that will rename the files as they are used so that it knows not use them again until there are no more left and it resets them all to "on" again.

Instead of renaming the files if you can't then you could do something similar with keeping a text file of which ones to use still etc. perhaps.


@echo off
set folder=C:\Scripts\Wallpaper\wallpapers
set destfolder=C:\Scripts\Wallpaper\wallAplicated
REM Get count of the number of .bmp files in folder above then get random number then divide
REM it by the count and take remainder.  No. is 0 to count -1

REM Rename all files to "Y_" and their name to be included in the random list if there are none left - or it is the first run
if not exist "%folder%\Y_*.JPG" (
  echo Resetting to full list of images
  rename "%folder%\*.jpg" "Y_*.jpg"

for /f "delims=" %%C in ('dir /b /a-d "%folder%\Y_*.jpg" ^| find /c /v ""') do set /A num=%random% %% %%C

for /f "delims=" %%F in ('dir /b /a-d "%folder%\Y_*.jpg" ^| more +%num%') do set name=%%F & goto next


echo Wallpaper is now %name%
copy "%folder%\%name%" "%destfolder%\wallpaper.jpg" 
REM Rename back to remove the Y_ to exclude from next random choice
rename "%folder%\%name%" "%name:~2%"

Open in new window

Steve KnightIT ConsultancyCommented:
Will have a look back tomorrow if others don't first.  Old question comment came from is here:

Richard AbogadoSystem Administrator OSAuthor Commented:
Ok I'll be waiting! Thank you!
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

David Johnson, CD, MVPOwnerCommented:
please post your batch and your script.  Random doesn't mean that it will use all values with no repeats.  It is simply random..  i.e. you flip a coin 10 times you get 7 heads and 3 tails, you do it again you get 2 heads and 8 tails.  The odds do not change per coin flip, it is still 50/50.  If you flip a coin 8 times and get 8 heads, the odds on flipping a tail remain the same 50/50.  I've known people betting the farm that it will be tails since in their opinion it has to be tails (I enjoy taking their money :=)

computers are really bad at random number generation and without randomizing the seed of the random number generator you will get the same random results.  one method is to use the milliseconds since the computer was started.  There are many more escoritic methods of random number generation i.e. atmospheric noise.

i.e. 100  random numbers from 0-9
Imports System.Text

Module Module1

    Dim _random As Random = New Random()

    Function GetLetter() As Integer
        Dim number As Integer = _random.Next(0, 9)
        Return number
    End Function

    Sub Main()
        For j As Integer = 0 To 9
            Dim builder As New StringBuilder
            For i As Integer = 0 To 9
                Dim letter = GetLetter()
            Dim s As String = builder.ToString()
            builder = Nothing
    End Sub
End Module

Open in new window

Steve KnightIT ConsultancyCommented:
David, his batch is in link I posted before.
Shaun VermaakTechnical Specialist/DeveloperCommented:
You can use a process similar to this and just replace the file in the source folder. If will then sync via GPO file preferences and replace on computers
Richard AbogadoSystem Administrator OSAuthor Commented:
Hello! Excuse me, I was indisposed.

Thanks for replying!

David: You have many reasons in the probability!!

Shaun: It looks complex, I'll do some tests with the indicated procedure and I'll let you know how it went.

Steve: This one looks very practical, I try it and I warn you.

I want to thank both of you for your valuable time helping me.


Richard AbogadoSystem Administrator OSAuthor Commented:

I just tried the script sent by Steve and it works correctly, I think it was the most practical and uncomplicated.

Thank you very much everyone for your help, especially Steve for being attentive from the beginning of my question.

Greetings and I am also at your service,

Steve KnightIT ConsultancyCommented:
No problem, glad it helped.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.