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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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!
David Johnson, CDRetiredCommented:
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

Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Steve KnightIT ConsultancyCommented:
David, his batch is in link I posted before.
Shaun VermaakTechnical SpecialistCommented:
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
Steve KnightIT 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.