Vista file virtualization madness

25 October 2007

I'm still relatively new to Windows Vista and although I like it, 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'.

Tags: IT Pro | Windows

Pages in this section

Categories

ASP.Net | Community | Development | IIS | IT Pro | Security | SQL (Server) | Tools | Web | Work on the road | Windows