How do I change the 'Desktop' directory programmaticly

I want to change the default directory of the 'Desktop' (normally C:\windows\desktop) to another directory, so that the desktop will display all files in this new directory on the desktop instead. I want to do this WITHOUT rebooting.
I know how to modify the registry (if this is neccecary).

Please Help,

  Dirk Manders

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.

Hi dms@,

 I don't know, but have you already tried to change this directory in the registry? Maybe you can try, but I suggest you first make a backup of your registry, before doing it. Besides I think this is what windows does when you've multiple users on one PC.

You can find this directory under :


or for multiple users :


Good luck and let me know something.

I'll try to find another solution.
c.u. Zif.
Hi Zif,

I tried it, but nothing happened. It looks like there is something missing to make desktop "refresh". Reboot could be the answer but dms@ said (and I guess why) he doesn't want to force a  restart.
Any ideas ?

Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

It is a procedure ResetDisplay in win32.hlp but I can't find it in user32 lib
dms@Author Commented:
Yeah, that was my problem in the first place. I already figured out the registry modifying thing. But there is something else: After changing the registry entry you mensioned and restarting Windows (wich eventually is NOT the idea - but anyhow), the registry entry is set back to its original value ! How can this be ? Maybe because Windows saves it's current desktop settings when shutting down ? Any suggestions ?

Hi all,

I got the same results of you dms@ ! I think it's due to another entry of registry that is:
HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

Note the .Default in the patch. I have a piece of code to change wallpaper bitmap that rids of the set back, but I couldn't find smth similar to desktop directory. This is  the code:

//change the Wallpaper key in the registry, after that: SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, nil, SPIF_SENDWININCHANGE);

where SPIF_SENDWININCHANGE makes the new setting persistent. I think that changing desktop directory need smth like that.

Bye (still thinking...)

dms@Author Commented:
Yeah, you're right: it does need something like that, but the question remains 'WHAT ???'.
BTW: a little of subject, yet related: Does anyone know where Windows stores the postion of the icons on the Desktop ? It's probable somewhere in the registry, but where ?

-- still hoping someone can find a problem to my initial    problem....
dms@Author Commented:
erhm, find a SOLUTION that is :-)
Give us some time to search for a complete answer. My intention in the previous comment is to raise a proccess called "brain storm". Very usefull to achieve solutions.

P.S.: What did you mean with "erhm, find a SOLUTION that is :-)"
dms@Author Commented:

(that last comment was because I said: '..find a problem to my problem', while I meant to say '..find a solution to my problem'.
Hi all, sorry but I've had some work to do in the field. Now, on the really problem, haven't had luck yet. But I know where you can find the icons on the desktop, here is some code. It's quit easy :

procedure TForm1.Button1Click(Sender: TObject);
PIDL: Pointer;
Path: LPSTR;
Path := StrAlloc(MAX_PATH);
SHGetSpecialFolderLocation(Handle, CSIDL_DESKTOP, @PIDL);
if SHGetPathFromIDList(PIDL, Path) then // returns false if folder isn't
part of file system
  OpenDialog1.InitialDir := Path;

CSIDL_DESKTOP            = $0000;
  CSIDL_PROGRAMS           = $0002;
  CSIDL_CONTROLS           = $0003;
  CSIDL_PRINTERS           = $0004;
  CSIDL_PERSONAL           = $0005;
  CSIDL_STARTUP            = $0007;
  CSIDL_RECENT             = $0008;
  CSIDL_SENDTO             = $0009;
  CSIDL_BITBUCKET          = $000a;
  CSIDL_STARTMENU          = $000b;
  CSIDL_DRIVES             = $0011;  // My Computer
  CSIDL_NETWORK            = $0012;
  CSIDL_NETHOOD            = $0013;
  CSIDL_FONTS              = $0014;
  CSIDL_TEMPLATES          = $0015;
dms@Author Commented:
Yeah, that gets me the Icons alright, but not the actual POSITION of the icons on the desktop (from the top and left of the screen, I didn't mean the position on the HDD).

An answer to this problem would be OK, But I really hope that someone can find the answer to my initial problem.
Sorry, see that I didn't read your comment correctly.
Hi Zif / dms,

I sugest you to reject Zif's answer otherwise it will be auto-graded, dms will loose the points and other experts cannot help. I'm sure Zif will not care, right ?

Still working on it,
No, really no problem if you reject my answer.
dms@Author Commented:
It wasn't THE answer, so I have no choice but to reject (sorry ZifNab !)

As a sidenote:
 I've found an aplication that can do what I want to be able to do: Norton Navigator. This  program alows one to create multiple desktops and switch from one to another. I recon  that is also changes the desktop directory, because copying desktop items each time a  'new desktop' is selected would take to much time (I've tried it).

Still the question remains.... HOW ???
Yo all!

I found something interesting.... Maybe this can help.... Didn't looked further but, it can be handy...

Getting the Win95 Desktop ListView Handle


                          How do I get a handle to the Windows 95 Desktop to access the
                          Desktop icons?


                          The Windows 95 Desktop is overlayed with a ListView component.
                          You simply need to get a handle to the ListView. Example:

                           function GetDesktopListViewHandle: THandle;
                             S: String;
                           Result := FindWindow('ProgMan', nil);
                           Result := GetWindow(Result, GW_CHILD);
                           Result := GetWindow(Result, GW_CHILD);
                           SetLength(S, 40);
                           GetClassName(Result, PChar(S), 39);
                           if PChar(S) <> 'SysListView32' then Result := 0;

                          Once you have the handle, you can use the list view-related API
                          functions in the CommCtrl unit to manipulate the desktop. See
                          the LVM_xxxx messages in the Win32 online help.

                          For example the following line of code:


                          will align the desktop icons to the left side of the Windows 95 desktop.

I have the strange feeling you can get all your needs with the LVM's.....
What about :

 1. Copie the list
 2. Remove all items
 3. Take another list and copy all to the list (Handle desktop?)
 4. Update the list!!!!!
 5. We got the result! I hope.

 Maybe easier to just change the handle...

As I meant to say, .... this must be the SOLUTION to our problem. If so, let me know,...

Regards, Zif.
Sorry for interrupting your discussion, why not just move the files in and out of the desktop folder ?
It's not the "perfect" solution, but it's quite fast, as it relatively takes no time for the system to move even huge files and folders wich contains lot's of files.
Well, if you have a few thousand's it might (but i'd like to see a screen-shot of that deskop ;-)
Keep up your good work, this is just a work around !!!
Sorry, i forgot to mention that the workaround will only be fast if the individual folders(desktops) are placed on the same drive.

dms@Author Commented:
KE: This sounds like a simple solution, but it isn't what I want. I want to be able to do it the other way around (I mensioned before that I already tried the thing you mensioned).

ZIF: This looks VERY promising ! I'll try it as soon as possible and will let you know. Man, if this works then you REALLY deserve those 595 points !
Sorry, but I read that you was copying the files into the desktop, and not moving them which is significantly faster - have you tried to move them instead ?

dms@Author Commented:
No, I haven't tried that yet. I'm know that your suggestion works, but it is not what I want - I really want to change the default directory that Windows uses to display the desktop icons. I'm sure it must be possible.

ZIF: I've tried your idea, and it works - but: It still doesn't actually change the default Desktop directory, it only moves files of another directory to them - wich is NOT the idea.
There MUST be some way to make Windows re-load the icons in the default desktop directory (wich I want to change), without rebooting.
Hi all,

I think there is a serious problem with moving files to desktop directory. What if the system goes down before moving the original files back ? Changing the desktop directory will be more confident.

Don't give up dms. People here are working on it...

I see your point itamar, but you can always get some serious damage when a system crashes, no matter what you're doing (except for doing nothing) :-).

dms: I think that the problem could be solved if you can figure oyt, how the explorer can be restarted. I do not suggest a killtask, there has to be another way - especially on Win95. On NT this task would be straightforward, by stopping and starting the exploerer process, in between you change the registry.
You can "simulate" it on 95 by pressing CTRL-ALT-DELETE and END the explorer task - and select Cancel on the Logoff dialog - wait a few seconds for the task message to appear, and
select end task. This will reload the explorer.
To select the desktop folder, create a registry string in
HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Exploerer\User Shell Folders\ with the name Desktop and the value <APath>.
I don't know how you get rid of the logoff message in 95, and neither do i know who's responsible for loading the explorer.
Maybee you can trick the system by making an inplace explorer.exe (or point to a new shell), that is responsible for starting and stopping the original explorer. It's a long time since I moved to NT, so you are on your own here.
I've looked for a function that could reload the explorer while it's running, and there was a promissing one, but it's not implemented yet - maybee in Windows 98. Maybee you can figure out how Norton are reloading the explorer - they could send a Windows Message ore something similar.
Hi dms,

So moving them works. But you want to change the desktop, well instead of changing the desktop change the files in the desktop and always work with the desktop directory. The other 'desktop directorys' are stored in your own defined directorys. Then if you want to change your desktop, just move the files between these directories and that 's it! You've changed the desktop!
Have you tried just changing the handle of the desktop directory to another directory?

Regards, Zif.
dms@Author Commented:
Wich Handle ? I don't think there is a handle to the actual desktop directory. I think Windows just fills the Desktop 'Listview' with all the items in C:\Windows\Desktop at startup.

So there are 2 solutions:
1) Do what KE said. First changing the Desktop dir in the registry and then restarting     Explorer. // This idea should work but restarting Explorer would take up too much time.
2) Do what ZIF suggested. Simulating what Windows does on startup: loading all files     from a directory and storing them in the Desktop Listview. // Better idea.

Either way there is still one major problem: If I add/remove icons, they will automaticly be aligned, how can I get the original positions from the current desktop icons. I recon there positions must be on stored on disk, 'cause Windows must also know these positions when putting the icons on the desktop on startup.

dms@: I disagree on your judgement.of the best solution, however that's up to you which one you decide.
1. If you change the desktop directory in registry, and restart the explorer the icon positions should be retained.
2. The "simulated" restart, as i descibed it, of the Win95 explorer isn't the true restart time - there's a significant delay, because of the OS is waiting for the task to respond.
Try this one instead:
Modify the registry setting as descibed earlier.
Select shutdown from your startmenu. Hold down CTRL-ALT-SHIFT and select NO. Now your explorer is unloaded. Start it again by dbl-click on the blank desktop, and choose run from the taskmanager, select C:\windows\explorer and run it. If you can do these few steps programatically, it's should be fast enough - and besides it WILL retain the icon positions etc., so you don't have to fiddle around with the ListViews etc. - which will take a serious amount of time to implement.
So the only thing that's left to solve, is how to shutdown the explorer without a logoff dialog.

dms@Author Commented:
I Will give it a try, and I'll let you know

That's my proposed answer, I tryed to well comment the code
So everything should be in there, I tryed it and it does what
you asked (I think)
You have to take care of two things:
-You have to wait a moment before restarting explorer, cause
the old instance is not completly removed, maybe with:
while FindWindow(pchar('Progman'), nil)

-When you restart explorer it launches again the programs in
run, but look at what I say in the code.

Make a new app
drop a button on the form
here the buttonclick code follows:

procedure TForm1.Button1Click(Sender: TObject);
  h: HWND; //the explorer handle
  r: TRegIniFile; //the registry key
  p: string; //the new desktop path
  p := 'c:\windows\temp';
  //we ask the new path we want to use for the desktop path
  if inputQuery('Let''s change the desktop path !!', 'Please enter the new desktop path', p) then
    //first we change the right registry key that designate the current user
    //desktop path
     //the root is HKEY_CURRENT_USER by default
    r := TRegIniFile.Create('Software\Microsoft\Windows\CurrentVersion\Explorer');
     //if it's the same, nothing is changed
    if p <> 'c:\windows\desktop' then
      r.WriteString('User Shell Folders', 'desktop', p)
      r.DeleteKey('User Shell Folders', 'desktop');

    //then we kill the explorer, and launch him again for the
    //changes to take effect
    //I tryed all sort of WM_systemChange and WM_UserChanged to ask
    //the explorer to reffresh things, but it did not work
    //I tryed to do the things with winHack 95 v2 but the default
    //desktop change was restored to the normal state after reboot
     //here we are looking for the exlporer handle
    h := FindWindow(pchar('Progman'), nil);
     //we are asking explorer to close itSelf
    PostMessage(h, WM_QUIT, 0, 0);
     //we are launching the explorer back again
     //but first we shall wait a second, cause if we do it too fast
     //the old instance is not completly removed, we the new comes up
    WinExec('Explorer.exe', SW_SHOW);
    //one side effect is that explorer launches again all the
    //apps that are registered in the run section
    //but either you know a explorer param that avoids that
    //or you read the run section and delete the keys before
    //killing explorer, and after that you restore them

I hope this does what you want.

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
The position of the Item can be found by LVM_GETITEMPOSITION.

wParam = (WPARAM) (int) i;
lParam = (LPARAM) (POINT FAR *) ppt;
// Corresponding macro
BOOL ListView_GetItemPosition(HWND hwnd, int i, POINT FAR* ppt);

The LVM_GETITEMPOSITION message retrieves the position of a list view item. You can send this message explicitly or by using the ListView_GetItemPosition macro.



Handle to the list view control.


Index of the list view item.


Pointer to a POINT structure that receives the position of the item's upper-left corner, in view coordinates.

Return Value

Returns TRUE if successful or FALSE otherwise.

Regards, Zif.
Yo dms@,

Already looked at these functions? (Pitty, only for NT) So you only can use these for NT applications...

CreateDesktop, GetThreadDesktop, OpenDesktop, SetProcessWindowStation

Regards, Zif!
dms@Author Commented:
Please hang on folks, I'll try these solutions at the end of the week (I'm kinda busy with school at the moment). I will let you know.....
Seems like you got the thing to work jeurk. I expect that the explorer will not send a WM_EndSession to any of the running task's, when it's closed by the WM_Quit.
If it actually works, I think that dms@ is better of with this solution, rather than "hand-coding" everything on his own.
No offence zifnab.
Now the last part would be to figure out when the explorer is actually unloaded - i don't think that sleeps is a secure way of doing it. BTW. you code states sleep(10) and you comment that it's a second. I were sure that sleep was specified in ms.
Whichever, it's better to do the job safely, by querying the taskmanager or smth. like that.
I don't think that explorer send's a WM_EndSession, even if I have not
checked it out. I tryed the prog I wrote and the prog's like delphi and others don't asked for saving and were still here
after the explorer's rebirth.
About the way to figure out when the explorer is unloaded, what's about:
while FindWindow(pchar('Progman'), nil)
You are right by saying that sleep(10) is not a second and that
it's specified in ms.
If your applications remains open, the WM_EndSession is not send; so it should work safely.
I don't know if FindWindows( etc. ) is a secure way.
It's not for sure which order the OS objects is destroyed, so maybee the function will trigger while the explorer is shut down (which in some cases could take longer, due to errors, and hanging tasks, printers etc.).
I think the best way would be to check if the explorer process is running.
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

From novice to tech pro — start learning today.