Results 1 to 4 of 4

Thread: URGENT - Getting PC personal Settings in VB ie userprofile

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    2

    Smile URGENT - Getting PC personal Settings in VB ie userprofile

    Hi Can anyone help

    I am trying to get the command prompt %userprofile% variable into VB 6.0

    this returns .....

    c:\winnt\profiles\<username> or
    c:\document and settings\<username>

    I understand there is Kernel32.dll and advapi32.dll

    I have used GetWindowsDirectory but all this returns is c:\winnt for NT and c:\document and settings\ for Win 2000 and XP but I need it working for all OS.

    I had thought of getting the system OS and then inserting "\profile\" it but thats not great programming.


    Any help is welcome.

    Gary
    Last edited by GaryB1; Feb 23rd, 2005 at 03:07 PM. Reason: Urgent replys required

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: URGENT - Getting PC personal Settings in VB ie userprofile

    I guess the GetUserProfileDirectory API is what you want? An example :

    VB Code:
    1. Private Const TOKEN_QUERY = (&H8)
    2. Private Declare Function GetAllUsersProfileDirectory Lib "userenv.dll" Alias "GetAllUsersProfileDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
    3. Private Declare Function GetDefaultUserProfileDirectory Lib "userenv.dll" Alias "GetDefaultUserProfileDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
    4. Private Declare Function GetProfilesDirectory Lib "userenv.dll" Alias "GetProfilesDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
    5. Private Declare Function GetUserProfileDirectory Lib "userenv.dll" Alias "GetUserProfileDirectoryA" (ByVal hToken As Long, ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
    6. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    7. Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
    8. Private Sub Form_Load()
    9.     'KPD-Team 2000
    10.     'URL: [url]http://www.allapi.net/[/url]
    11.     'E-Mail: [email][email protected][/email]
    12.     Dim sBuffer As String, Ret As Long, hToken As Long
    13.     'set the graphics mode of this form to 'persistent'
    14.     Me.AutoRedraw = True
    15.     'create a string buffer
    16.     sBuffer = String(255, 0)
    17.     'retrieve the all users profile directory
    18.     GetAllUsersProfileDirectory sBuffer, 255
    19.     'show the result
    20.     Me.Print StripTerminator(sBuffer)
    21.     'create a string buffer
    22.     sBuffer = String(255, 0)
    23.     'retrieve the user profile directory
    24.     GetDefaultUserProfileDirectory sBuffer, 255
    25.     'show the result
    26.     Me.Print StripTerminator(sBuffer)
    27.     'create a string buffer
    28.     sBuffer = String(255, 0)
    29.     'retrieve the profiles directory
    30.     GetProfilesDirectory sBuffer, 255
    31.     'show the result
    32.     Me.Print StripTerminator(sBuffer)
    33.     'create a string buffer
    34.     sBuffer = String(255, 0)
    35.     'open the token of the current process
    36.     OpenProcessToken GetCurrentProcess, TOKEN_QUERY, hToken
    37.     'retrieve this users profile directory
    38.     GetUserProfileDirectory hToken, sBuffer, 255
    39.     'show the result
    40.     Me.Print StripTerminator(sBuffer)
    41. End Sub
    42. 'strips off the trailing Chr$(0)'s
    43. Function StripTerminator(sInput As String) As String
    44.     Dim ZeroPos As Long
    45.     ZeroPos = InStr(1, sInput, Chr$(0))
    46.     If ZeroPos > 0 Then
    47.         StripTerminator = Left$(sInput, ZeroPos - 1)
    48.     Else
    49.         StripTerminator = sInput
    50.     End If
    51. End Function


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    2

    Talking Re: URGENT - Getting PC personal Settings in VB ie userprofile

    thankyou most helpful

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: URGENT - Getting PC personal Settings in VB ie userprofile

    You're welcome


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width