<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>On The Mark &#187; UAC</title>
	<atom:link href="http://markmonica.com/tag/uac/feed/" rel="self" type="application/rss+xml" />
	<link>http://markmonica.com</link>
	<description>IT blogging by Mark Monica</description>
	<lastBuildDate>Fri, 20 Jan 2012 21:06:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Possible VB2008 BUG: My.User.IsInRole (When UAC ON)</title>
		<link>http://markmonica.com/2009/10/29/possible-vb2008-bug-my-user-isinrole-when-uac-on/</link>
		<comments>http://markmonica.com/2009/10/29/possible-vb2008-bug-my-user-isinrole-when-uac-on/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 18:31:25 +0000</pubDate>
		<dc:creator>Mark Monica</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.net]]></category>
		<category><![CDATA[My.User.IsInRole]]></category>
		<category><![CDATA[UAC]]></category>

		<guid isPermaLink="false">http://markmonica.com/2009/10/29/possible-vb2008-bug-my-user-isinrole-when-uac-on/</guid>
		<description><![CDATA[<p>Posted in <a href="http://markmonica.com/category/programming/" title="Programming">Programming</a><a href="http://markmonica.com/category/programming/vb-net/" title="VB.net">VB.net</a></p>Scenario &#160; On machines where Vista/W7 is installed there appears to be an issue when checking to see if a user is in a role.&#160; User Account Control (UAC) must be on to reproduce the issue.&#160; The result is that the value returned is always FALSE even when the user does belong to the group. [...]]]></description>
			<content:encoded><![CDATA[<p>Posted in <a href="http://markmonica.com/category/programming/" title="Programming">Programming</a><a href="http://markmonica.com/category/programming/vb-net/" title="VB.net">VB.net</a></p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><h3>Scenario</h3>
<p>&#160;</p>
<p>On machines where Vista/W7 is installed there appears to be an issue when checking to see if a user is in a role.&#160; User Account Control (UAC) must be on to reproduce the issue.&#160; The result is that the value returned is always FALSE even when the user does belong to the group.</p>
<p>&#160;</p>
<h3>Sample Code (UAC must be on to produce error)</h3>
<p>&#160;</p>
<p><font size="2" face="Courier New"><strong><em>If My.User.IsInRole(“My Domain\My Group”) Then</em></strong></font></p>
<p><font size="2" face="Courier New"><strong><em>&#160;&#160;&#160;&#160; Return True</em></strong></font></p>
<p><strong><em><font size="2" face="Courier New">Else</font></em></strong></p>
<p><font size="2" face="Courier New"><strong><em>&#160;&#160;&#160;&#160; Return False</em></strong></font></p>
<p><font size="2" face="Courier New"><strong><em>End If</em></strong></font></p>
<p><strong><em><font size="2" face="Courier New"></font></em></strong></p>
<h3>Workaround</h3>
<p>&#160;</p>
<p>To get around this I created a function using other .Net functions.</p>
<p><font size="2" face="Courier New"><em>Public Function IsInUserRole(ByVal RoleToFind As String) As Boolean </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160; Dim id As WindowsIdentity = WindowsIdentity.GetCurrent       <br />&#160;&#160;&#160; Dim irc As IdentityReferenceCollection </em></font></p>
<p> <font size="2" face="Courier New"><em>&#160;&#160;&#160; &#8216; Gets a SID list of groups the user belongs to </em></font>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160; irc = id.Groups </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160; For Each ir As IdentityReference In irc </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8216; Need to convert the SID to plain english</em></font></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:5606f97e-143e-4b45-b368-635a1acae258" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/VB.net" rel="tag">VB.net</a>,<a href="http://technorati.com/tags/My.User.IsInRole" rel="tag">My.User.IsInRole</a>,<a href="http://technorati.com/tags/UAC" rel="tag">UAC</a></div>
<p><font size="2" face="Courier New"><em>       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim act As NTAccount = CType(ir.Translate(Type.GetType(&quot;System.Security.Principal.NTAccount&quot;)), NTAccount) </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; If act.Value = RoleToFind Then </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Return True </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; End If </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160; Next </em></font></p>
<p><font size="2" face="Courier New"><em>&#160;&#160;&#160; Return False </em></font></p>
<p><font size="2" face="Courier New"><em>End Function </em></font></p>
<div class="shr-publisher-74"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://markmonica.com/2009/10/29/possible-vb2008-bug-my-user-isinrole-when-uac-on/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

