Determine user profile type (local, roaming, temporary etc)

December 16, 2009 — Leave a comment

Here’s some code I wrote recently that uses the GetProfileType Windows API to determine what type of profile the currently logged on user is using.

Note: You can view a nicer formatted version of the code here in my post on vbforums: http://www.vbforums.com/showthread.php?p=3682198

Anyway, here is the code:

Const PT_LOCAL As UInteger = 0
Const PT_TEMPORARY As UInteger = 1
Const PT_ROAMING As UInteger = 2
Const PT_MANDATORY As UInteger = 4

<System.Runtime.InteropServices.DllImportAttribute("Userenv.dll", EntryPoint:="GetProfileType")> _
Public Shared Function GetProfileType(ByRef pdwflags As UInteger) As Boolean
End Function

'Example method
Private Sub SomeMethod()
    'Declare our variable that will hold the result
    Dim ProfileType As UInteger
    'Call the API and pass in the variable declared above
    GetProfileType(ProfileType)
    'Check to see what the value of the variable is now
    Select Case ProfileType
        Case PT_LOCAL
            MessageBox.Show("Using a local profile")
        Case PT_TEMPORARY
            MessageBox.Show("Using a temporary profile")
        Case PT_ROAMING
            MessageBox.Show("Using a roaming profile")
        Case PT_MANDATORY
            MessageBox.Show("Using a mandatory profile")
    End Select
End Sub

Hope that helps someone out in the future.

No Comments

Be the first to start the conversation!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s