October 25, 2007
@ 03:51 PM

I'm still relatively new to Vista and although I like, some things drive me crazy:

I am now using Powershell extensively and work a lot on the main profile which is located in C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1.

I have an alias in Powershell to edit the profile in Notepad2.exe so I can quickly edit it and then reload the shell.

When starting the shell, my profile show it's version as a date. Recently I noted that the date shown and the one in the profile.ps1 file don't match. After some poking around it turned out that I had started notepad2.exe as a normal user who doesn't have write access to the system directory. Even though it loads the file from

C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

Vista's file virtualization kicks in when saving it, so it ends up at:

C:\Users\pete\AppData\Local\VirtualStore\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

It's pretty useless there because Powershell still needs it under C:\Windows\System32\.

So knowing this, I started only editing the profile as an administrator. I usually have a second Powershell open to run admin stuff, here the function I use for starting it:

function su
{
  if ($tnNT6x -eq $TRUE)
  {
    $ShellApp = New-Object -ComObject Shell.Application
    $ShellApp.ShellExecute("$PSHOME\powershell.exe","","","runas")
  }
  else
  {
    WinAppEx "runas.exe" "/user:$tnAdminUser $PSHOME\powershell.exe"
  }
}
However today I ran into a similar problem even as an administrator. I was adjusting my profile for Windows 2008 Server. For the first time I am using a 64Bit version and once again the profile I am editing is not the one that is loaded by the shell.

notepad2.exe $PSHOME\profile.ps1

is executed as

notepad2.exe C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

>However when restarting the Powershell my changes are not there. Turns out using:

notepad.exe C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

works fine. The problem here is that notepad2.exe and most other text editors are 32bit applications where notepad.exe is 64bit.

When a 32bit application tries to save something into System32 the OS redirects it to SysWow64. Remember under a 64Bit Windows the 32bit files are in SysWow64 and the 64bit files are in System32, pretty confusing if you ask me.

This means I can not use any 32bit application to edit a file in System32, so for now I have to use Window's own notepad.exe.

P.S. After installing Windows 2008 Server I was looking to Powershell because they claim it is now part of the OS. It wasn't there and it wasn't a separate download either. Turns out as with most other features, you have to install it through the 'Turn Windows features On and Off' section under 'Programs and Features'.
 
Categories: IT Pro

October 6, 2007
@ 01:09 PM

I was going to encrypt the connection strings in some web.config files on a production server. I followed the instructions in the MSDN Library 'Walkthrough: Encrypting Configuration Information Using Protected Configuration'

http://msdn2.microsoft.com/en-us/library/dtkwfdky.aspx

However when I ran

aspnet_regiis.exe -pa "NetFrameworkConfigurationKey" "NT AUTHORITY\NETWORK SERVICE"

I got the following error:

Adding ACL for access to the RSA Key container...
Could not access the RSA key container. Make sure that the ACLs on the container
allow you to access it.
Failed!

I was running the command under an administrator account, so I expected to have all the access in the world. I used Process Monitor to find out where the problem was: The file

C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys\ d6d986f09a1ee04e24c949879fdb506c_34b3925e-0f96-4fb7-a312-e89b0b98f24a

Seems to have the RSA key and the ACLs of it allowed full access to SYSTEM and one other user that isn’t an administrative account. I added permissions for the Administrators group and now the command worked fine.


 
Categories: ASP.Net