Refreshing desktop and running script on the background

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Gaverek
Posts: 7
Joined: 30 Aug 2018 09:27

Refreshing desktop and running script on the background

#1 Post by Gaverek » 30 Aug 2018 09:33

Hello, I'm actually working on a script that moves every single icon from the desktop to another location, which has already been accomplished, here is the code I'm using:

Code: Select all

robocopy %USERPROFILE%\Desktop\ C:\SWAT /MOVE /S /E
md %USERPROFILE%\Desktop
The thing is, I'm running this script every 5 minutes on every user computer by setting it as a scheduled task on a GPO, so, seeing the command window every 5 minutes on the screen can be annoying, also, folder's doesn't dissapear at all if desktop is not being refreshed.

Is there a simple way to refresh the desktop after executing the code above and also running the script in the background?

Thanks in advance
Last edited by Gaverek on 31 Aug 2018 08:15, edited 1 time in total.

Gaverek
Posts: 7
Joined: 30 Aug 2018 09:27

Re: Refreshing desktop and running script on the background

#2 Post by Gaverek » 30 Aug 2018 14:57

Solved it calling the .bat script in a .vbs with this code

Code: Select all

Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c MoveItemsFromDesktop.bat"
oShell.Run strArgs, 0, false
Hope it helps someone else. :D

Gaverek
Posts: 7
Joined: 30 Aug 2018 09:27

Re: Refreshing desktop and running script on the background

#3 Post by Gaverek » 30 Aug 2018 16:47

Now I'm having another problem with this, the thing is that I'm having to run 2 times the vbs script to execute all the commands on the .bat file, does anyone knows why and how to solve it?

Gaverek
Posts: 7
Joined: 30 Aug 2018 09:27

Re: Refreshing desktop and running script on the background

#4 Post by Gaverek » 30 Aug 2018 17:09

I think that calling 2 .bat files from the .vbs script may work but I'm not an expert in .vbs scripting so I don't know how to implement it. Hope someone that knows how to do it reads this.

Gaverek
Posts: 7
Joined: 30 Aug 2018 09:27

Re: Refreshing desktop and running script on the background

#5 Post by Gaverek » 31 Aug 2018 09:35

Solved it converting my bat file with this online batch to .exe converter http://www.f2ko.de/en/ob2e.php just remember to mark the invisible radio button

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Refreshing desktop and running script on the background

#6 Post by aGerman » 31 Aug 2018 10:49

I don't see any good possibility to refresh the desktop using batch. But what I'm really wondering is ...
1) Why do you need to permanently move the desktop folder and recreate it?
2) Why are you doing it using Batch if you don't like the console window?
3) Why do you use one of these terrible bat2exe thingies with all of their side effects instead of using a compilable language from the beginning if you believe a script isn't good enough?

Steffen

Gaverek
Posts: 7
Joined: 30 Aug 2018 09:27

Re: Refreshing desktop and running script on the background

#7 Post by Gaverek » 31 Aug 2018 11:35

Hi aGerman, thanks for replying, I'm doing this because my boss wanted it, he just doesn't like seeing things on peoples desktop, his issues not mines, I'm just here doing what I'm being asked and payed for. I'm using batch because it was the only way I thought of doing it and used the bat2exe because it was the simpliest way to do what I wanted at the moment which was make the batch script run in the background

Gaverek
Posts: 7
Joined: 30 Aug 2018 09:27

Re: Refreshing desktop and running script on the background

#8 Post by Gaverek » 31 Aug 2018 16:21

You were right after all aGerman, using the converter is not a good idea, in stead I did a do until loop on my vbscript so that it executed the batch file 2 times and that solved my problem

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Refreshing desktop and running script on the background

#9 Post by Ed Dyreen » 01 Sep 2018 10:05

aGerman wrote:
31 Aug 2018 10:49
I don't see any good possibility to refresh the desktop using batch.

Code: Select all

echo. &<nul set /p "=  :/ Restart 'explorer.EXE'
:: (
	>nul taskkill /im explorer.EXE /f &&start explorer.EXE
	<nul set /p "=  :/ Restart 'explorer.EXE'"
:: )
<nul set /p "= [OK]" &echo. 
This will work but you will loose all active explorer windows and any moved icons will be restored to their location they had at logon. I mean visual location as stored in the registry not physical location obviously. This part of code is extracted from a batch that configures the desktop. Removing/moving icons etcetera... Actually this part of code runs at the end after i edited the registry so my icons are placed on screen location exactly where i want them.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Refreshing desktop and running script on the background

#10 Post by aGerman » 01 Sep 2018 17:15

Ed Dyreen wrote:
01 Sep 2018 10:05
This will work but you will loose all active explorer windows
Some other possibilities that may work under certain circumstances:
XP

Code: Select all

rundll32.exe user32.dll,UpdatePerUserSystemParameters
before Win10

Code: Select all

ie4uinit.exe -ClearIconCache
Win10

Code: Select all

ie4uinit.exe -show
Steffen

Post Reply