Aggiungi un modulo alla tua applicazione e inserisci quanto segue:
.codice:Option Explicit Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10 Private Const MAX_PATH As Integer = 260 Private Declare Function SHGetSpecialFolderPath Lib "shell32" Alias "SHGetSpecialFolderPathA" (ByVal hwndOwner As Long, ByVal lpszPath As String, ByVal nFolder As Long, ByVal fCreate As Long) As Long Public Function GetDesktopPath() As String Dim buffer As String * 260 If SHGetSpecialFolderPath(0, buffer, CSIDL_DESKTOPDIRECTORY, 0) = 0 Then Err.Raise 51, "GetDesktopPath", "SHGetSpecialFolderPath returned FALSE." GetDesktopPath = Left$(buffer, InStr(buffer, Chr$(0))) End Function
La funzione GetDesktopPath ti restituirà il percorso del desktop.
P.S.: il nome dell'utente corrente comunque si può estrarre usando Environ$("USERNAME"), ma è bene usare il metodo che ti ho suggerito, visto che la posizione della cartella del desktop non è c:\documents and settings\<nome utente>\Desktop su tutti i computer (sul mio ad esempio è d:\documents and settings\<nome utente>\Desktop). Lo stesso discorso vale per tutte le altre cartelle "speciali", come ad esempio la cartella Documenti o la "Dati applicazioni".

Rispondi quotando