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?
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.

Ryan ChongSoftware Team Lead, ex-Business Systems Analyst , ex-Senior Application EngineerCommented:
In vb, try:

Public Type SHITEMID
    cb As Long
    abID As Byte
End Type
    mkid As SHITEMID
End Type

Public Const NOERROR = 0

'Public Const ERROR_SUCCESS As Long = 0
'Public Const MAX_PATH As Long = 260
Public Const CSIDL_DESKTOP = &H0                   '(desktop)
Public Const CSIDL_INTERNET = &H1                  'Internet Explorer (icon on desktop)
Public Const CSIDL_PROGRAMS = &H2                  'Start Menu\Programs
Public Const CSIDL_CONTROLS = &H3                  'My Computer\Control Panel
Public Const CSIDL_PRINTERS = &H4                  'My Computer\Printers
Public Const CSIDL_PERSONAL = &H5                  'My Documents
Public Const CSIDL_FAVORITES = &H6                 '(user)\Favourites
Public Const CSIDL_STARTUP = &H7                   'Start Menu\Programs\Startup
Public Const CSIDL_RECENT = &H8                    '(user)\Recent
Public Const CSIDL_SENDTO = &H9                    '(user)\SendTo
Public Const CSIDL_BITBUCKET = &HA                 '(desktop)\Recycle Bin
Public Const CSIDL_STARTMENU = &HB                 '(user)\Start Menu
Public Const CSIDL_DESKTOPDIRECTORY = &H10         '(user)\Desktop
Public Const CSIDL_DRIVES = &H11                   'My Computer
Public Const CSIDL_NETWORK = &H12                  'Network Neighbourhood
Public Const CSIDL_NETHOOD = &H13                  '(user)\nethood
Public Const CSIDL_FONTS = &H14                    'windows\fonts
Public Const CSIDL_TEMPLATES = &H15
Public Const CSIDL_COMMON_STARTMENU = &H16         '(all users)\Start Menu
Public Const CSIDL_COMMON_PROGRAMS = &H17          '(all users)\Programs
Public Const CSIDL_COMMON_STARTUP = &H18           '(all users)\Startup
Public Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19  '(all users)\Desktop
Public Const CSIDL_APPDATA = &H1A                  '(user)\Application Data
Public Const CSIDL_PRINTHOOD = &H1B                '(user)\PrintHood
Public Const CSIDL_LOCAL_APPDATA = &H1C            '(user)\Local Settings
                                                   '\Application Data (non roaming)
Public Const CSIDL_ALTSTARTUP = &H1D               'non localized startup
Public Const CSIDL_COMMON_ALTSTARTUP = &H1E        'non localized common startup
Public Const CSIDL_COOKIES = &H21
Public Const CSIDL_HISTORY = &H22
Public Const CSIDL_COMMON_APPDATA = &H23           '(all users)\Application Data
Public Const CSIDL_WINDOWS = &H24                  'GetWindowsDirectory()
Public Const CSIDL_SYSTEM = &H25                   'GetSystemDirectory()
Public Const CSIDL_PROGRAM_FILES = &H26            'C:\Program Files
Public Const CSIDL_MYPICTURES = &H27               'C:\Program Files\My Pictures
Public Const CSIDL_PROFILE = &H28                  'USERPROFILE
Public Const CSIDL_PROGRAM_FILES_COMMON = &H2B     'C:\Program Files\Common
Public Const CSIDL_COMMON_TEMPLATES = &H2D         '(all users)\Templates
Public Const CSIDL_COMMON_DOCUMENTS = &H2E         '(all users)\Documents
Public Const CSIDL_COMMON_ADMINTOOLS = &H2F        '(all users)\Start Menu\Programs
                                                   '\Administrative Tools
Public Const CSIDL_ADMINTOOLS = &H30               '(user)\Start Menu\Programs
                                                   '\Administrative Tools
Public Const CSIDL_FLAG_CREATE = &H8000&           'combine with CSIDL_ value to force
                                                   'create on SHGetSpecialFolderLocation()
Public Const CSIDL_FLAG_DONT_VERIFY = &H4000       'combine with CSIDL_ value to force
                                                   'create on SHGetSpecialFolderLocation()
Public Const CSIDL_FLAG_MASK = &HFF00              'mask for all possible flag values

'not used
'Public Const CSIDL_SYSTEMX86 = &H29               'x86 system directory on RISC
'Public Const CSIDL_PROGRAM_FILESX86 = &H2A        'x86 C:\Program Files on RISC
'Public Const CSIDL_PROGRAM_FILES_COMMONX86 = &H2C 'x86 Program Files\Common on RISC

'public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
Public Declare Function SHGetSpecialFolderLocationNew Lib "shell32.dll" Alias "SHGetSpecialFolderLocation" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
'Public Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)

Public Function GetSpecialfolder(CSIDL As Long) As String
    Dim r As Long, path As String
    Dim IDL As Long
    'Get the special folder
    r = SHGetSpecialFolderLocationNew(100, CSIDL, IDL)
    If r = NOERROR Then
        'Create a buffer
        path$ = Space$(512)
        'Get the path from the IDList
        '<Note>: Opposite function of SHSimpleIDListFromPath
        r = SHGetPathFromIDList(ByVal IDL, ByVal path$)
        'Remove the unnecessary chr$(0)'s
        GetSpecialfolder = Left$(path, InStr(path, Chr$(0)) - 1)
        Exit Function
    End If
    GetSpecialfolder = ""
End Function

Use like:

Hope this helps

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 following code does it it uses windows scripting to achive the task you can add it in vb directly.

Dim myWSh
Set myWSh = CreateObject("WScript.Shell")
MsgBox myWSh.SpecialFolders.Item("Desktop")
Set myWSh = Nothing

other special folders are

Folder Windows version
AllUsersDesktop Windows 2000
AllUsersStartMenu Windows 2000
AllUsersPrograms Windows 2000
AllUsersStartup Windows 2000
Desktop Windows 98/ME, Windows 2000
Favorites Windows 98/ME, Windows 2000
Fonts Windows 98/ME, Windows 2000
My Documents Windows 98/ME, Windows 2000
NetHood Windows 98/ME, Windows 2000
PrintHood Windows 98/ME, Windows 2000
Programs Windows 98/ME, Windows 2000
Recent Windows 98/ME, Windows 2000
SendTo Windows 98/ME, Windows 2000
Start Menu Windows 98/ME, Windows 2000
StartupB Windows 2000
Templates Windows 2000
Roshan DavisCommented:
char buf[520];

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

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

Good luck
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Roshan DavisCommented:
ryancys mentioned the same in the VB code.
Rosh :)
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

vkaushik: can you please tell me how is your answer different from mine?
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.