Gary Herndon
August 5th, 1999, 03:02 PM
I am trying to use the Package Manager with VB6 to install my application that is written for 95/98/NT. Is there a variable that I can access to represent the desktop path, since it is different for every user on NT or 95/98? Any ideas are appreciated. Thanks.
-Gary Herndon
Chris Eastwood
August 6th, 1999, 03:07 AM
I'm not sure about the install program - you can always
rewrite it yourself as it comes with the source code.
The following code allows you to access the desired path
of *all* the special folders in windows 9x/NTx.
It exposes one method and an ENUM, so to get the location
of the desktop simply :
sDeskTop = oFolders.GetSpecialFolder(spfDeskTopDir)
Paste the code into a class module and off you go :
option Explicit
'/////////////////////////////////////////////
' 1999 J.LeVasseur <lvasseur@tiac.net> '
' Adapted from USENET post by Chris Eastwood '
'---------------------------------------------
private Type SHITEMID
cb as Long
abID as Byte
End Type
private Type ITEMIDLIST
mkid as SHITEMID
End Type
'--------------------------------------
public Enum SHFolder
spfPrograms = &H2
spfControls = &H3
spfPrinters = &H4
spfPersonal = &H5
spfFavorites = &H6
spfStartup = &H7
spfRecent = &H8
spfSendTo = &H9
spfBitBucket = &HA
spfStartMenu = &HB
spfDeskTopDir = &H10
spfDrives = &H11
spfNetWork = &H12
spfNetHood = &H13
spfFonts = &H14
spfTemplates = &H15
spfCommonStartMenu = &H16
spfCommonPrograms = &H17
spfCommonStartup = &H18
spfCommonDeskTopDir = &H19
spfCommonAppData = &H1A
End Enum
'-----------------------------
private Declare Function SHGetPathFromIDList Lib _
"shell32.dll" Alias "SHGetPathFromIDListA" _
(byval pidl as Long, byval pszPath as string) as Long
private Declare Function SHGetSpecialFolderLocation _
Lib "shell32.dll" (byval hwndOwner as Long, _
byval nFolder as Long, pidl as ITEMIDLIST) as Long
private Declare Function lstrlen Lib "kernel32" _
Alias "lstrlenA" (byval lpString as string) as Long
'-----------------------------
public Function GetSpecialFolder(byval CSIDL as SHFolder) as string
Dim lRetVal as Long
Dim szPath as string
Dim szTmp as string
Dim IDL as ITEMIDLIST
Const ERRNOERROR as Long = 0
'-----------------------------------------------
on error GoTo errGetSpecialfolder
lRetVal = SHGetSpecialFolderLocation(0, CSIDL, IDL)
If lRetVal = ERRNOERROR then
szPath = Space$(255)
lRetVal = SHGetPathFromIDList(byval IDL.mkid.cb, byval szPath)
If lRetVal <> 0 then
szTmp = Left$(szPath, lstrlen(szPath))
szTmp = szTmp & IIf(Right$(szTmp, 1) = "\", "", "\")
GetSpecialFolder = szTmp
End If
End If
Exit Function
errGetSpecialfolder:
GetSpecialFolder = ""
End Function
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb