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
brunda kPosted Apr 13, 2012, 3:15 PM
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
Muhammad IrshadPosted Apr 13, 2012, 5:35 AM
Anyhow, Thanks for your time.
Regards,
Itz.Irshad
VulpesPosted Apr 13, 2012, 4:37 AM
Does the code I suggested in your previous thread for Windows 7 exhibit similar behaviour?
Muhammad IrshadPosted Apr 13, 2012, 12:44 AM
Both apps are running on same machine and OS is not either Win 7 or Vista. It's Win XP.
Thanks
Regards,
Itz.Irshad
VulpesPosted Apr 12, 2012, 12:23 PM
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.