Members
Technology Zones
IBM Learning Center
Articles
Hosted By
Info
|
[38] Advanced Files & Folders
Last post 07-28-2006 2:30 PM by unitled. 14 replies.
-
01-01-1999 12:00 AM
|
|
Advertisement
|
|
-
-
-
-
lae0502


- Joined on 01-30-2003

- Points 5
|
Re: How do you Open a Folder on the Desktop?
Normally, the folders on the Desktop are stored on the systems partition. So you have to find out which it is. Then you have to find out, the username of the currently loggod in user, because the desktop folders (for example in the german version of W2k) are stored in "[SystemPartition]:\Dokumente und Einstellungen\[Username]\Desktop".
To archive your goal, you paste the Code below into a module and call the function "getdesktopfolder" which returns a string. If you are using another version of Windows, you have to find out the equivalent path to "Dokumente und Einstellungen".
Lars
Private S1 As String
Private Declare Function GetUserName Lib "AdvAPI32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function FindUserName() As String
S1 = Space(512)
GetUserName S1, Len(S1)
FindUserName = Trim$(S1)
End Function
Public Function GetWindowsDirectory() As String
Dim s As String
Dim c As Long
s = String$(MAX_LENGTH, 0)
c = GetWindowsDirectoryB(s, MAX_LENGTH)
If c > 0 Then
If c > Len(s) Then
s = Space$(c + 1)
c = GetWindowsDirectoryB(s, MAX_LENGTH)
End If
End If
GetWindowsDirectory = IIf(c > 0, Left$(s, c), "")
End Function
Public Funtion getdesktopfolder() As String
a = GetWindowsDirectory
a = Left(a, 3) 'extract drive letter
a = a & "\Dokumente und Einstellungen\"
a = a & FindUserName & "\Desktop"
getdesktopfolder = a
End Function
|
|
-
-
-
-
-
jawsper


- Joined on 04-11-2003

- Points 25
|
to get the desktop folder....
first add this (in a module):
Code:
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Public Type SHITEMID
cb As Long
abID As Byte
End Type
Public Type ITEMIDLIST
mkid As SHITEMID
End Type
Public Const MAX_PATH As Integer = 260
Private Const CSIDL_PROGRAM_FILES = &H26 ' Program Files
Private Const CSIDL_STARTMENU = 11 ' Start Menu
Private Const CSIDL_DESKTOP = &H0 ' The Desktop
then, in the form:
Code:
Public Function fGetSpecialFolder(CSIDL As Long) As String
Dim sPath As String
Dim IDL As ITEMIDLIST
fGetSpecialFolder = ""
If SHGetSpecialFolderLocation(frmMain.hWnd, CSIDL, IDL) = 0 Then
sPath = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then fGetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & ""
End If
End Function
then to get the desktop folder (or start menu or program files):
Code:
string_desktop_folder = fGetSpecialFolder(CSIDL_DESKTOP)
string_startmenu_folder = fGetSpecialFolder(CSIDL_STARTMENU)
string_prog_files_folder = fGetSpecialFolder(CSIDL_PROGRAM_FILES)
easy, not??
(i found this somewhere on this site.. i didn't make this myself)
---------------------------------- so, why arent you reading my extremely interesting post above? ;)
|
|
-
-
-
-
-
-
-
Page 1 of 1 (15 items)
|
Search
Code Samples
New Members
|