How do I find the current users desktop directory?
Blitz3D Forums/Blitz3D Programming/How do I find the current users desktop directory?
| ||
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) |
| ||
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. |
| ||
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. |
| ||
You can use getenv to find it. path1$=GetEnv$("userprofile") desktop$=path1$+"\Desktop" Print desktop WaitKey() End |
| ||
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. |
| ||
Yes. I have another idea: you can ask to the user and memorize the answer. |
| ||
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?" :) |
| ||
No, i mean that it asks the full path for the Desktop. |
| ||
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. |
| ||
Another idea: the program could use readdir to read the content of the user directory and then select the most probably desktop folder. |
| ||
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) |
| ||
I hope the person you're developing for has XP because GetEnv$("userprofile") returns nothing on my win98SE machine. |
| ||
Yeah... Just tried that on my '98 machine too. :O( Back to drawing board(!) ( ...mutter...Microsoft...grumble... ) |
| ||
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) |