Welcome to MSDN Blogs Sign in | Join | Help

jaredpar's WebLog

Code, rants and ramblings of a programmer.

Syndication

News

Now Reading

Expert F#

What's a better book to read when learning F#?

Essential WPF

Thus far the best book I've read on WPF. Gets right down to working with WPF and the goals/history.

Purely Functional Data Structures

Reading this book makes me feel like I'm back in college. It will really get your mind going and is best read with a whiteboard handy.

Blog Roll

Eric Lippert
Dustin Campbell
Jon Skeet
Coding Horror
Brian McNamara
Brian Bondy
Hub FS
Full List

Using PowerShell to update ACLS

I've been an avid fan of running as a limited user account (LUA) for almost all of my computing career.  It's in large part a holdover from my *NIX days but it's an important practice for Windows as well. I'm very excited about this being the default for Windows going forward starting with Vista. 

The bad news is that not everyone is quite LUA compliant yet.  This hits me hardest with PowerShell when I'm trying to run some auto update scripts that change the Registry.  There are a lot of programs I use that still store their settings in HKLM or the likes.  So I've added a PowerShell script that will grant me access to those keys as an LUA.  It was written a long time ago so it doesn't utilize the get/set-acl commandlets but it runs just the same.

# Give the user access to the registry entry
function GrantLuaRegistryKey([string]$regkeyPath)
{
	[string]$ident = "{0}\{1}" -f ${env:\userdomain}, ${env:\username};
	$rights = [Enum]::Parse([Security.AccessControl.RegistryRights], "FullControl"); 
	$allow = [Enum]::Parse([Security.AccessControl.AccessControlType], "Allow");
	$iFlags = [Enum]::Parse([Security.AccessControl.InheritanceFlags], "ContainerInherit,ObjectInherit");
	$pFlags = [Enum]::Parse([Security.AccessControl.PropagationFlags], "None");
	$rule = new-object Security.AccessControl.RegistryAccessRule $ident,$rights,$iFlags,$pFlags,$allow;
	$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($regkeyPath, $true);
	
	# Add the rule to the collection
	$col = $key.GetAccessControl();
	$col.AddAccessRule($rule);
	$key.SetAccessControl($col);
	$key.Close();
}

Published Wednesday, November 29, 2006 4:21 PM by Jared Parsons

Filed under:

Comments

# Interesting Finds: Week after Thanksgiving 3 @ Wednesday, November 29, 2006 10:58 PM

Jason Haley

# Interesting Finds: Week after Thanksgiving 3 @ Wednesday, November 29, 2006 10:58 PM

Jason Haley

New Comments to this post are disabled
Page view tracker