Solved

Getting Deskstop Path

Posted on 2003-11-04
9
383 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:zhongxi
9 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 150 total points
Comment Utility
In vb, try:

Public Type SHITEMID
    cb As Long
    abID As Byte
End Type
Public Type ITEMIDLIST
    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_COMMON_FAVORITES = &H1F
Public Const CSIDL_INTERNET_CACHE = &H20
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:
GetSpecialfolder(CSIDL_DESKTOP)

Hope this helps
0
 
LVL 9

Assisted Solution

by:bhagyesht
bhagyesht earned 150 total points
Comment Utility
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
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
LPITEMIDLIST pidl;
char buf[520];

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

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

Good luck
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
ryancys mentioned the same in the VB code.
Rosh :)
0
 
LVL 1

Expert Comment

by:vkaushik
Comment Utility
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
0
 
LVL 9

Expert Comment

by:bhagyesht
Comment Utility
vkaushik: can you please tell me how is your answer different from mine?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 152
countX 22 69
mapAB Challlenge 35 84
python question 5 57
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now