<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>jaredpar's WebLog : LUA</title><link>http://blogs.msdn.com/jaredpar/archive/tags/LUA/default.aspx</link><description>Tags: LUA</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Detecting if you are an Admin</title><link>http://blogs.msdn.com/jaredpar/archive/2007/08/01/detecting-if-you-are-an-admin.aspx</link><pubDate>Wed, 01 Aug 2007 18:56:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4171063</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/4171063.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=4171063</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=4171063</wfw:comment><description>&lt;p&gt;This came up on an internal alias.&amp;nbsp; A customer wanted to know how to determine if there were running as an admin in a tool.&amp;nbsp; Below is a sample program that will print out whether or not you are the machine admin or a member of the machine administrators group.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;This is essentially the same as the code in a previous post of mine but ported to VB.&amp;nbsp; &lt;a title="http://blogs.msdn.com/jaredpar/archive/2005/11/07/489942.aspx" href="http://blogs.msdn.com/jaredpar/archive/2005/11/07/489942.aspx"&gt;http://blogs.msdn.com/jaredpar/archive/2005/11/07/489942.aspx&lt;/a&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: blue"&gt;Imports&lt;/span&gt; System.Security.Principal
&lt;span style="color: blue"&gt;Module&lt;/span&gt; Module1

    &lt;span style="color: blue"&gt;Function&lt;/span&gt; IsRunningAsLocalAdmin() &lt;span style="color: blue"&gt;As&lt;/span&gt; &lt;span style="color: blue"&gt;Boolean&lt;/span&gt;
        &lt;span style="color: blue"&gt;Dim&lt;/span&gt; cur &lt;span style="color: blue"&gt;As&lt;/span&gt; WindowsIdentity = WindowsIdentity.GetCurrent()
        &lt;span style="color: blue"&gt;For&lt;/span&gt; &lt;span style="color: blue"&gt;Each&lt;/span&gt; role &lt;span style="color: blue"&gt;As&lt;/span&gt; IdentityReference &lt;span style="color: blue"&gt;In&lt;/span&gt; cur.Groups
            &lt;span style="color: blue"&gt;If&lt;/span&gt; role.IsValidTargetType(&lt;span style="color: blue"&gt;GetType&lt;/span&gt;(SecurityIdentifier)) &lt;span style="color: blue"&gt;Then&lt;/span&gt;
                &lt;span style="color: blue"&gt;Dim&lt;/span&gt; sid &lt;span style="color: blue"&gt;As&lt;/span&gt; SecurityIdentifier = &lt;span style="color: blue"&gt;DirectCast&lt;/span&gt;(role.Translate(&lt;span style="color: blue"&gt;GetType&lt;/span&gt;(SecurityIdentifier)), SecurityIdentifier)
                &lt;span style="color: blue"&gt;If&lt;/span&gt; sid.IsWellKnown(WellKnownSidType.AccountAdministratorSid) &lt;span style="color: blue"&gt;OrElse&lt;/span&gt; sid.IsWellKnown(WellKnownSidType.BuiltinAdministratorsSid) &lt;span style="color: blue"&gt;Then&lt;/span&gt;
                    &lt;span style="color: blue"&gt;Return&lt;/span&gt; &lt;span style="color: maroon"&gt;True&lt;/span&gt;
                &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;If&lt;/span&gt;

            &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;If&lt;/span&gt;
        &lt;span style="color: blue"&gt;Next&lt;/span&gt;

        &lt;span style="color: blue"&gt;Return&lt;/span&gt; &lt;span style="color: maroon"&gt;False&lt;/span&gt;
    &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Function&lt;/span&gt;

    &lt;span style="color: blue"&gt;Sub&lt;/span&gt; Main()
        Console.WriteLine(&lt;span style="color: maroon"&gt;"Is Admin {0}"&lt;/span&gt;, IsRunningAsLocalAdmin())
    &lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Sub&lt;/span&gt;

&lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Module&lt;/span&gt;
&lt;/pre&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4171063" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/VB/default.aspx">VB</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/LUA/default.aspx">LUA</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/DotNet/default.aspx">DotNet</category></item><item><title>Determining if you're an Administrator from Powershell</title><link>http://blogs.msdn.com/jaredpar/archive/2007/01/19/determining-if-you-re-an-administrator-from-powershell.aspx</link><pubDate>Fri, 19 Jan 2007 22:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1494359</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/1494359.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=1494359</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=1494359</wfw:comment><description>&lt;P&gt;Here's a handy PowerShell function I used to determine if I'm currently running as an Administrator in PowerShell&lt;/P&gt;
&lt;P&gt;# Determine if I am running as an Admin&lt;BR&gt;function AmIAdmin()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;$ident = [Security.Principal.WindowsIdentity]::GetCurrent()&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;foreach ( $groupIdent in $ident.Groups )&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;if ( $groupIdent.IsValidTargetType([Security.Principal.SecurityIdentifier]) )&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$groupSid = $groupIdent.Translate([Security.Principal.SecurityIdentifier])&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ( $groupSid.IsWellKnown("AccountAdministratorSid") -or $groupSid.IsWellKnown("BuiltinAdministratorsSid"))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $true;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;return $false;&lt;BR&gt;}&lt;BR&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1494359" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/LUA/default.aspx">LUA</category></item><item><title>LUA + MSI + Luanch program now on Vista</title><link>http://blogs.msdn.com/jaredpar/archive/2006/12/06/lua-msi-luanch-program-now-on-vista.aspx</link><pubDate>Wed, 06 Dec 2006 23:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1225010</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/1225010.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=1225010</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=1225010</wfw:comment><description>&lt;P&gt;I'm a &lt;STRONG&gt;huge&lt;/STRONG&gt; fan of the LUA support in Vista.&amp;nbsp; It has it's quirks but it's a major step forward for Windows programming.&amp;nbsp; As a former *nix guy I've had to run LUA the hard way before Vista.&amp;nbsp; The support in Vista is tons better than it used to be.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;There are a few areas that are still not optimal.&amp;nbsp; One of them that's been bugging me lately are legacy MSI installers.&amp;nbsp; Vista almost always correctly elevates and offers to run the installer as Admin.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;This causes a small problem though with some legacy MSI's.&amp;nbsp; A lot of MSI have a check box at the end of the MSI setup with text similar to "Launch SuchAndSuch Program Now".&amp;nbsp; The problem is who the program launches as.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Prior to Vista there was no auto-priviledge elevation.&amp;nbsp; So most people ran MSI's as there normal user account which was an admin.&amp;nbsp; Launching the process at the end of the MSI was just fine.&lt;/P&gt;
&lt;P&gt;Now in Vista most people run as a normal user and MSI's elevated.&amp;nbsp; So this feature will now, on legacy MSI's, launch the program as an Administrator rather than your normal user account.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Without the help of a tool, there's no good way to detect when this happens.&amp;nbsp; To be safe, I always un check that box and manually start the app so I know it will be running under my normal account.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1225010" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/LUA/default.aspx">LUA</category></item></channel></rss>