Determine User's Windows Profile Type
Here is a quick bit of code I wrote that shows how to use the GetProfileType API to determine if the user is using a local, roaming, temporary, or mandatory windows profile. Just posting it here as there seems to be no examples of using this API from VB.NET on google (or pinvoke.net) :)
Here are the API definitions I am using:
vb.net 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
''' <summary>
''' Determines the type of Windows profile being used by the user
''' </summary>
''' <param name="pdwflags">Output parameter</param>
<System.Runtime.InteropServices.DllImportAttribute("Userenv.dll", EntryPoint:="GetProfileType")> _
Public Shared Function GetProfileType(ByRef pdwflags As UInteger) As Boolean
End Function
and here is an example of how to use it in a method:
vb.net Code:
Dim ProfileType As UInteger
GetProfileType(ProfileType)
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
Tested on Windows XP 32 bit and Windows 7 64 bit
Re: Determine User's Windows Profile Type
Hi Chris -
Is it possible to use this code to check the remote machine users profile type ?
Any suggestins?
Re: Determine User's Windows Profile Type
I dont think there is any way you can use this API to do that no, but I believe this API works by reading the value of the "State" value in the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\SID
Replace that last part of the path ("SID") with the SID of the user that you want to get the profile type of.
Re: Determine User's Windows Profile Type