Saturday, January 14, 2006

Registering a MshSnapIn with LUA

The new Beta 3 version of Monad introduces the idea of a single shell. Instead of being forced to create a new shell to host all of your CmdLet's you can load them into the current running shell. This is done via the concept of MshSnapIn's.

MshSnapIn's are a way of identifying, grouping and providing a common install. Snap ins are installed by a common utility called InstallUtil that comes with the .NET Framework. By default the installer writes the snap in information under HKLM:\software\Microsoft\MSH\1\MshSnapIns thus preventing LUA users from registering snap ins.

By modifing the permissions on that key slightly you can enable a normal user to register MSH snapins. Here a MSH method to do so.

function UpdateSnapInPermissions
{
[string]$ident = "{0}\{1}" -f ${env:\userdomain}, ${env:\username};
$rights = [Enum]::Parse([System.Security.AccessControl.RegistryRights], "CreateSubKey,QueryValues,SetValue");
$allow = [Enum]::Parse([System.Security.AccessControl.AccessControlType], "Allow");
$rule = new-object System.Security.AccessControl.RegistryAccessRule $ident,$rights,$allow;
$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("software\microsoft\msh\1\MshSnapIns", $true);

# Add the rule to the collection
$col = $key.GetAccessControl();
$col.AddAccessRule($rule);
$key.SetAccessControl($col);
$key.Close();
}

0 Comments:

Post a Comment

<< Home