Page 1 of 1

Refreshing desktop and running script on the background

Posted: 30 Aug 2018 09:33
by Gaverek
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

Re: Refreshing desktop and running script on the background

Posted: 30 Aug 2018 14:57
by Gaverek
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

Re: Refreshing desktop and running script on the background

Posted: 30 Aug 2018 16:47
by Gaverek
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?

Re: Refreshing desktop and running script on the background

Posted: 30 Aug 2018 17:09
by Gaverek
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.

Re: Refreshing desktop and running script on the background

Posted: 31 Aug 2018 09:35
by Gaverek
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

Re: Refreshing desktop and running script on the background

Posted: 31 Aug 2018 10:49
by aGerman
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

Re: Refreshing desktop and running script on the background

Posted: 31 Aug 2018 11:35
by Gaverek
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

Re: Refreshing desktop and running script on the background

Posted: 31 Aug 2018 16:21
by Gaverek
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

Re: Refreshing desktop and running script on the background

Posted: 01 Sep 2018 10:05
by Ed Dyreen
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.

Re: Refreshing desktop and running script on the background

Posted: 01 Sep 2018 17:15
by aGerman
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