Friday, October 29, 2004

MSDN error on VS2003 while running as non-admin

I've recently dropped my main XP user down to the "average schmo" level like I should (and like I have in my primary development VirtualPC image.) When I tried to pull up the help on anything the installation wizard for VS2003 would pop up, eventually failing with this error:

Error 1606.Could not access network location wwwroot$: Unable to get security info for this object.

In case anyone else has this problem, here's how you fix it (verbatim from Felix Wang):

  • Log on with the Admin user.

  • Rename the following file:

    C:\Program Files\Common Files\Microsoft Shared\Office10\mso.dll

  • Launch VS.Net and let the reparation to finish.

  • Launch MSDN.

  • Close VS.Net and MSDN.

  • Search for the file named "CookDoc.dll". By default, it should be in
    "C:\Program Files\Common Files\Microsoft Shared\MSDN".

  • Let's register the file by the following command:

    RegSvr32 "C:\Program Files\Common Files\Microsoft Shared\MSDN\CookDoc.dll"

  • Logon with the original user.


  • Scooped from usenet on microsoft.public.vsnet.setup in this thread. In case this link doesn't work the original post is titled "VS.NET/MSDN Annoyance" on Mar 9, 2004.

    [Listening to: Concrete Blonde - It's a Man's World]

    CreateProcessAsUser

    Any blog entry that includes usage instructions of use in rare circumstances and with caution deserves a link. K. Scott Allen's sample code / wrapper around CreateProcessAsUser

    [Listening to: Iron Maiden - Caught Somewhere in Time]

    Tuesday, October 26, 2004

    Easily Creating a StrongNameMembershipCondition for an Assembly

    Another gem from Shawn Farkas: Easily Creating a StrongNameMembershipCondition for an Assembly

    [Listening to: Electric Light Orchestra - Turn to Stone]

    Creating an AppDomain with limited permissions

    Shawn Farkas has to be on my top 10 list of bloggers. His blog entries and snippets are awesome and (eerily enough) tend to be right along the lines of stuff that I'm going to need. How does he know what I'm doing? Hey Shawn, that isn't you hanging around in the bushes outside my office window is it?

    Without further ado: Creating an AppDomain with limited permissions.

    [Listening to: Eartha Kitt - Where is my man]

    More Performance Tidbits for library writers

    More Performance Tidbits for library writers from the performance guru Rico "measure first" Mariani.

    At some point either they'll figure out a way to really profile in a VPC image or I'll have to knuckle under and install VS2005 on my host PC. 'Til then, my head is firmly in the sand.

    [Listening to: Alice in Chains - Junkhead]

    Monday, October 25, 2004

    Getting the Current Permissions in a Named Permission Set

    Shawn Farkas posted a snippet on Getting the Current Permissions in a Named Permission Set. I like snippets. Snippets are good. Long live snippets.

    Does it make sense for me to define my own Named Permission Set for my service? Don't know yet. Haven't spent enough time looking.

    [Listening to: Kittie - In Winter]

    Friday, October 22, 2004

    Programatically changing file permissions

    I'm back to implementing some permission related unit tests that I balked at earlier.

    It took me a bit of time to find how to remove all permissions from a file. Since I don't want to have to go through this again I'll post it here.

    Basically I'm pulling what I found in Keith Brown's absolute must read wiki: The .NET Developer's Guide to Windows Security in How to program with SIDs into a class.

    I implemented it in a typical Resource Acquisition Is Initialization manner using IDispose so that I know I'll restore the permissions to their original after my tests are done.

    Here's the class (a little light on error checking for brevity):

    class ApplySecuritySettingsToFile : IDisposable
    
    {
    #region Private Members
    private FileSystemAccessRule m_AccessRule = null;
    private FileInfo m_FileInfo = null;
    #endregion


    #region Constructor
    public ApplySecuritySettingsToFile (string fileName,
    FileSystemAccessRule accessRule)
    {
    if (fileName == null && accessRule == null)
    return;


    m_FileInfo = new FileInfo (fileName);
    m_AccessRule = accessRule;


    FileSecurity sd = m_FileInfo.GetAccessControl ();
    sd.AddAccessRule (m_AccessRule);
    m_FileInfo.SetAccessControl (sd);
    }
    #endregion


    #region Dispose pattern
    private bool m_bIsDisposed = false;


    ~ApplySecuritySettingsToFile ()
    {
    Dispose ();
    }


    public void Dispose ()
    {
    if (!m_bIsDisposed)
    {
    if (m_FileInfo != null && m_AccessRule != null)
    {
    FileSecurity sd =
    m_FileInfo.GetAccessControl ();
    sd.RemoveAccessRule (m_AccessRule);
    m_FileInfo.SetAccessControl (sd);
    }


    GC.SuppressFinalize (this);
    m_bIsDisposed = true;
    }
    }
    #endregion
    }
    And here's how you use it to Deny FullControl (i.e. remove all permissions) to file C:\temp\temp.txt for the BUILTIN\users group:
    using (new ApplySecuritySettingsToFile (@"C:\temp\temp.txt",
    
    new FileSystemAccessRule (
    new SecurityIdentifier (
    WellKnownSidType.BuiltinUsersSid,
    null),
    FileSystemRights.FullControl,
    AccessControlType.Deny)
    )
    )
    {
    // You (and everyone else for that matter) now have
    // no permissions whatsoever to C:\temp\temp.txt

    }
    You could just as easily add permissions using AccessControlType.Allow.

    Hope it helps.

    [Listening to: Marilyn Manson - Mother Inferior Got Her Gunn]

    Thursday, October 21, 2004

    Monday, October 18, 2004

    Number Formatting in .NET

    An overview of Number Formatting in .NET via Kit George of the BCL Team.

    I too have spent far too much time looking for the right format string on MSDN. This is a step in the right direction.

    [Listening to: Rage Against the Machine - The Ghost of Tom Joad]

    Thursday, October 14, 2004