How do I find the current users desktop directory?

Blitz3D Forums/Blitz3D Programming/How do I find the current users desktop directory?

Cold Storage(Posted 2005) [#1]
I'm writing a program that needs to create a folder and files on the desktop.

How do I know where it is for sure?

:O)


Sweenie(Posted 2005) [#2]
Read the key "Desktop" under the following registry path.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
You will find alot of other user-specific paths here as well.

This should work with NT, 2000, XP and 2003.
Not sure about Win 95 & Win 98 though.


Picklesworth(Posted 2005) [#3]
But never mind the old Windows'.
If we're afraid to take advantage of new features because they weren't there before, than there's no point MS adding new features :D (And they already seem to be doing that with Office, which should, by now, have every feature one could possibly imagine...)

Anyway, it's probably there anyway for all versions. Can't see how it wouldn't be. And if its not, a blank directory to start in turns up the documents folder, which is pretty close.


splinux(Posted 2005) [#4]
You can use getenv to find it.


path1$=GetEnv$("userprofile")
desktop$=path1$+"\Desktop"
Print desktop

WaitKey()
End




Sweenie(Posted 2005) [#5]
You can use getenv to find it.


That will only work when the user have an english installation of windows.

On my installation the desktop folder is called "Skrivbord", which is Swedish.

Using that method, you would need to have a list of "Desktop" translated to all different languages that Windows has been translated to.


splinux(Posted 2005) [#6]
Yes.
I have another idea: you can ask to the user and memorize the answer.


Sweenie(Posted 2005) [#7]
LOL

You mean something like this could pop up during installation?

"While you are waiting for the installation to finish I have a question for you.
What is 'Desktop' called in your language?"

:)


splinux(Posted 2005) [#8]
No, i mean that it asks the full path for the Desktop.


Sweenie(Posted 2005) [#9]
Oh, sorry. :/

Anyway, that would be the easiest solution for the developer but I think that the average user don't have a clue where the desktop folder is.


splinux(Posted 2005) [#10]
Another idea: the program could use readdir to read the content of the user directory and then select the most probably desktop folder.


Cold Storage(Posted 2005) [#11]
As the software I'm writing is only for an English market at present ( not my choice - choice of the person I'm developing for! ) then the getenv solution is absolutely spot on!

Many thanks to all esp. SpLinux! ;O)


big10p(Posted 2005) [#12]
I hope the person you're developing for has XP because GetEnv$("userprofile") returns nothing on my win98SE machine.


Cold Storage(Posted 2005) [#13]
Yeah... Just tried that on my '98 machine too. :O(

Back to drawing board(!)

( ...mutter...Microsoft...grumble... )


ozak(Posted 2005) [#14]
Why not use the user32.dll? Just add a few decls (just can't remember them off the top of my head. Search the net for the proper funcs)