Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/05/2009, 04:07
Marcelote
 
Fecha de Ingreso: mayo-2009
Mensajes: 31
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Visual Basic en Vista

Hola, yo tuve un problema parecido. Supuse que la ruta "\Usuarios\" en Vista es virtual, así que usé la siguiente función, que te devuelve la ruta real del usuario activo y además haces independiente a tu programa de la versión del sistema operativo.

sería: GetUserRoot() & "\AAAA\... etc

Espero que te sirva.

Código:
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function GetUserProfileDirectory Lib "userenv.dll" Alias "GetUserProfileDirectoryA" (ByVal hToken As Long, ByVal lpProfileDir As String, lpcchSize As Long) As Boolean

Public Function GetUserRoot() As String
    Dim sBuffer As String
    Dim hToken As Long
    sBuffer = String(255, 0)
    OpenProcessToken GetCurrentProcess, TOKEN_QUERY, hToken
    GetUserProfileDirectory hToken, sBuffer, 255
    GetUserRoot = StrZToStr(sBuffer)
End Function

Function StrZToStr(ByVal StrZ As String) As String
    On Error GoTo StringError
    If InStr(StrZ, vbNullChar) > 0 Then
        StrZToStr = left(StrZ, InStr(StrZ, vbNullChar) - 1)
    Else
        StrZToStr = StrZ
    End If
    Exit Function
StringError:
    StrZToStr = vbNullString
End Function