Hi Guys,
There is interesting problem down here.
I use this code
If My.User.CurrentPrincipal.IsInRole("Administrators") Then
MsgBox("Administrator")
Else
MsgBox("Not Administrator")
End If
in two different applications with below specs:
1. Windows Form Application with .NET Framework 3.5 (VB.NET)
2. WPF Windows Applciation with .NET Framework 3.5 (VB.NET)
In WinForm app it shows Administrator in Message Box. But, in WPF it shows Not Administrator.
What is reason behind this ? Any idea ?
Thanks,
Regards,
Itz.Irshad
Loading

VulpesRank #55 · 29.2K reputationPosted Apr 12, 2012, 8:23 AM EDT
If it's the latter and both machines are running either Vista or Windows 7, then it could be due to a difference in UAC settings.
Muhammad Irshad53 reputationPosted Apr 12, 2012, 8:44 PM EDT
Both apps are running on same machine and OS is not either Win 7 or Vista. It's Win XP.
Thanks
Regards,
Itz.Irshad
VulpesRank #55 · 29.2K reputationPosted Apr 13, 2012, 12:37 AM EDT
Does the code I suggested in your previous thread for Windows 7 exhibit similar behaviour?
Muhammad Irshad53 reputationPosted Apr 13, 2012, 1:35 AM EDT
Anyhow, Thanks for your time.
Regards,
Itz.Irshad
brunda kRank #3,804 · 389 reputationPosted Apr 13, 2012, 11:15 AM EDT
http://stackoverflow.com/questions/1521520/how-to-use-windows-authentication-in-wpf
http://www.dreamincode.net/code/snippet1558.htm
My.User.Name is emptyWindows Form Application with .NET Framework 3.5 (VB.NET) - Properties - EnableapplicationFramework - Authentication mode(Windows)
But WPF Windows Applciation with .NET Framework 3.5 (VB.NET) - Properties-EnableApplicationFramework,there is no option of Authentication mode
so we need use My.User.InitializeWithWindowsuser()
I tried this code and it worked in windows7
My.User.InitializeWithWindowsUser()
If My.User.IsAuthenticated Then
If My.User.IsInRole("Administrators") Then
Label1.Content = "Admin"
Else
Label1.Content = "Not admin"
End If
End If