Link to home
Start Free TrialLog in
Avatar of zhongxi
zhongxi

asked on

Getting Deskstop Path

I am trying to copy a file from one location to the desktop. But I am facing problem to get the path of desktop since the path of desktop is different from each other.
This Window function is used.
(CopyFile ("File.txt", "Special\\NewFile.txt", FALSE))

Can anyone help?
thanx
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
LPITEMIDLIST pidl;
char buf[520];

SHGetSpecialFolderLocation(hwnd, CSIDL_DESKTOP, &pidl);
SHGetPathFromIDList(pidl, buf);

MultiByteToWideChar(CP_ACP, 0, buf, -1, wsz, MAX_PATH);

Good luck
ryancys mentioned the same in the VB code.
Rosh :)
Avatar of vkaushik
vkaushik

Use this

Dim WSHShell as Object
dim DesktopPath as string

  Set WSHShell = CreateObject("WScript.Shell")
  if (not WSHShell is nothing) then
      DesktopPath = WSHShell.SpecialFolders("Desktop")
  end if

You can retrieve other windows folders also

AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates
vkaushik: can you please tell me how is your answer different from mine?