?
Solved

Finding the Windows Desktop Directory

Posted on 2000-03-09
10
Medium Priority
?
185 Views
Last Modified: 2010-04-04
Is there a quick one-line way of finding the Windows Desktop Directory so that an application can save a file to it independent of directory structure. e.g. c:\windows\desktop, or c:\windows\users\frank\desktop etc..???

Looking for an answer asap on this so am prepared to offer 400 points for this one.
0
Comment
Question by:gmnt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2601039
Here's one solution. Not a one liner but short enough, I think:

function GetDesktopFolderName: String;

var
  AReg: TRegIniFile;

begin
  Result := '';
  AReg := TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer');
  Result := AReg.ReadString('Shell Folders', 'Desktop', '');
  AReg.Free;
end;


Ciao, Mike
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2601067
and here's another one:

function GetDesktopFolder: String;

var
  Buffer: array[0..MAX_PATH] of Char;
  PIDL: PItemIDList;

begin
  SHGetSpecialFolderLocation(Handle, CSIDL_DESKTOP, PIDL);
  SHGetPathFromIDList(PIDL, Buffer);
  Result := Buffer;
end;

Ciao, Mike
0
 

Author Comment

by:gmnt
ID: 2601073
How does this react if, for example, the PC has multiple users and there are a number of desktop folders? Does it use the desktop of the currently active user i.e. the one actually logged in and running the application?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:Lischke
ID: 2601082
Yep, the folder of the currently logged in user is returned.

Ciao, Mike
0
 

Author Comment

by:gmnt
ID: 2601181
I think the first one is easier to understand - Are there any specifics I need e.g. in "uses" etc or just declare the function at the top?
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2601209
Nothing special to consider. Just take in Registry into the uses clause and copy the code out. Btw: the second code is not much harder than the first one. You need to include ShlObj and with this SHGet* stuff you are independent of eventual changes Microsoft makes to the registry in future Windows versions.

Ciao, Mike
0
 

Author Comment

by:gmnt
ID: 2601334
I'm getting errors:
Undeclared identifier: 'Handle'
Unsatisfied forward or external declaration: 'TfrmMain.GetDesktopFolder'

I've included ShlObj and have declared the function with all the others:

procedure btnAboutClick(Sender: TObject);
procedure cmbSlot1Change(Sender: TObject);
function GetDesktopFolder: String;
private
      { Private declarations }

Any suggestions (btw using Delphi 4)
0
 
LVL 10

Accepted Solution

by:
Lischke earned 1600 total points
ID: 2601355
Oops, sorry. Replace Handle simply with 0. This was the handle of my TForm, but you don't need this value to pass.

Ciao, Mike
0
 

Author Comment

by:gmnt
ID: 2601810
I needed an answer fast, and got it.
A nice quick and clean answer - much appreciated.
Garth.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2601997
I'm always glad to help (in particular when so many points are involved ;-)).

Good luck until next time,

Ciao, Mike
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question