How to refresh the desktop without restarting explorer.exe?

2

I have enough knowledge about registry files that i know how and where to change the desktops location through a script.

I am looking for a way to "refresh" (update/reload/synchronize) the desktop once changes to the registry occur.

The solution needs to be done automatically, i.e. Ran from a script or program however I can not and will not want to kill the explorer.exe process as that harms more of the system than intended.

Notes related to answers, not question:

The F5 refresh Apparently works but I have so far been able to get it to work with an autoit script. The issue was i was changing an environment variable value which was just a default location of it, and did not utilize the windows api of SHSetKnownFolder. I need to figure out how to get this function inside my batch/vbs scripts.

If you believe Killing the explorer.exe forcefully does not harm the computer, i can accept that if the fact that the amount of time needed to reboot it far outweighs the basic method of changing the desktop location through the user interface.

The thing may be intentionally looking for is a windows powershell cmdlett, that requires api call SHSetKnownFolderPath.

The thing that i want to happen is what occurs at the end of this video but from a batch or vbs script.

Jouster500

Posted 2016-07-10T18:39:05.167

Reputation: 220

Comments are not for extended discussion; this conversation has been moved to chat.

– Mokubai – 2016-07-10T20:44:45.687

Wouldn't it suit your purpose to just completely change the contents of the same location? Maybe use a symbolic link; change the link target, then trigger F5. – JDługosz – 2016-07-10T23:57:10.270

@JDługosz : we have already been over this. F5 does not update the desktop. While in hindsight it should, it does not do it for this class of problems – Jouster500 – 2016-07-10T23:58:57.340

I mean, by not changing the name of the directory but seemingly changing the contents of the same directory, F5 would work normally as with any normal change. It no longer needs the load-time settings to be reloaded. Follow me? – JDługosz – 2016-07-11T00:17:44.863

Another thought: there are settings changed broadcast messages that are sent to top-level windows. Maybe it responds to that? – JDługosz – 2016-07-11T00:18:56.197

@JDługosz ah yes that method.While for smaller purposes this would suit what I need, however the original scope of the project that i had in mind for this does not want this. The aim was to turn the desktop into a moving library that would change its contents to current location that a user was in the file system. Kind of like how user is operating within a terminal. I wanted to implement this for the desktop so i can quickly work on projects and save everything to it in a user friendly manner. The aim is to not move files to new locations because sometimes the locations im in actively need it – Jouster500 – 2016-07-11T00:25:42.527

Pls read again. Symbolic link. Change one thing, seems to the explorer to change whole contents. Change the symlink destination, rather than the registry entry. – JDługosz – 2016-07-11T00:28:20.833

@JDługosz : oh shoot, im sorry. So like when you right click the desktop folder, and in the location tab, change that folder location; that is changing the symlink for the desktop? – Jouster500 – 2016-07-11T00:30:42.140

I don't know. I think it varies with the Windows version. Best if you do mimic that unless it's internal to its own dialog box prompt and can't be triggered. But I was thinking you create a symlink and set the desktop folder once, to that, putting up with the restart. Now you can retarget the symlink and explorer thinks you changed the whole contents of the self-same directory. Symbolic link and junction can be treated differently; try each to see. – JDługosz – 2016-07-11T00:36:39.213

@JDługosz :That is a pretty clever way of approaching it and it may actually save me a lot of lines of code! I still don't believe that its changes can take place like that. Are you a linux user yourself? If you ever wanted to make changes to a file so for example ~/.bashrc, you would need to source it so the changes would take place. So perhaps we need to look for something which "source" the desktop – Jouster500 – 2016-07-11T00:41:32.583

The desktop isn't a file. Explorer does handle changes made to the directory tree representing the desktop, just not the setting saying which directory that is. – JDługosz – 2016-07-11T11:17:28.473

Check the wrapper function here.. using PS. http://stackoverflow.com/questions/25709398/set-location-of-special-folders-with-powershell

– w32sh – 2016-07-17T20:12:19.830

Answers

4

To refresh the content of the desktop (for example after changing its location) simply click on an empty section and press F5.

This only works when handling API calls that are maintained by the Explorer.exe process, which is why you originally discovered killing the Explorer.exe process did what you need in the first place.

Yes, you could change the registry value of the desktop, but because you didn't do it through normal or correct means, the typical F5 refresh didn't work.
Other scenarios where you may have encountered issues for example, if the network connection is lost while the actual desktop path has not changed, Explorer will give an error that the location is no longer accessible. If the network is restored, Explorer will simply not update.

In your case, the SHSetKnownFolderPath which you discovered with autoit (which is also a C++ script for Windows), performs the method correctly allowing you to click the desktop and press F5, issuing a refresh which is given the ability to update thanks to the API.

LPChip

Posted 2016-07-10T18:39:05.167

Reputation: 42 190

Unfortunately this is incorrect. F5 does not make any changes to the desktop location when i am using my script. The explorer.exe process needs to be reinitialized without killing it if changes are to take effect – Jouster500 – 2016-07-10T19:08:13.457

Normally F5 will work. I don't know why it won't work for you then. – LPChip – 2016-07-10T19:17:52.787

You can try using the script that i use in order to manually change desktop locations for my windows machine for yourself and see if you can understand the situation. This is just to make sure that its not a difference in windows machines. The answer that i posted to this is the three scripts i used to run this.

– Jouster500 – 2016-07-10T19:21:49.827

@PIMP_JUICE_IT : yeah i wrote those scripts, wrote that answer, asked that question, asked it here, and still dealing with the same thing from over a year ago =. All i want is the process that activates when you click the apply button when changing the location of the desktop folder by right clicking for its properties. – Jouster500 – 2016-07-10T21:04:28.030

Alright something fishy is going on here.Doing some more digging i came across information about the API call SHSetKnownFolderPath, i mounted this API call to an autoit script executed it. I noticed that it changed the desktop location accordingly in the registry and upon refreshing the desktop with F5 caused the update to take place. I think i was setting the wrong variable to update with my scripts which was probably why the desktop change never took place after killing explorer

– Jouster500 – 2016-07-16T22:27:36.937

Good to hear you got it fixed. That means my answer was right all along. (not that I doubted that...) Would you mind accepting my answer then, so you can indicate to everyone that its fixed? Keep in mind, the original question is answered. You still need help but with a different question. You should therefor consider asking a new question specifically for that part and at the right location, which is Stack Overflow. – LPChip – 2016-07-17T13:19:28.027

I cant accept it just yet. Theres still some information that needs to be organized and done first such as stating f5 only works after invoking the win api call shsetknownfolderpath instead of manually changing the shell folders in the registry, which is changed as a result because of the API call – Jouster500 – 2016-07-17T15:13:58.483

I'm sorry, but your question states: Refresh explorer without restarting it. My answer tells you exactly that. You have confirmed that it works but that your script needs alteration. That is outside of the scope of this current question. Therefor this is answered. If you need more help, I gladly help if it is in my power, but it should be in a new question and quite likely on Stack Overflow where all the programmers are. – LPChip – 2016-07-17T15:27:03.637

1The answer is incomplete and vague as to why f5 should work, and provides no insight to future users looking at this question any guidance with regards to the same problem. – Jouster500 – 2016-07-17T16:33:24.400