User With Password Is Needed for Virtual PC's Integrated Services

Illustration

Integration features were always thing you installed first on your new virtual machine. Greatest benefit was seamless mouse movement between host and virtual machine, but there were other thing like clock synchronization and clipboard sharing.

New version of Virtual PC (Windows 7 beta) also offers thing you may noticed on remote desktop - ability to share local resources (direct replacement for old shared folders).

Because Remote Desktop is underlying protocol, in order to share resources, you need to have user with password on your virtual machine. This was problem for me since I often skip this step. Once you try to enable integration features, you are presented with logon screen. It will not accept empty password and there is no obvious way to escape from it.

It took me a while to figure that, once you disable integration features, you can logon. Once I had Windows under control, I have assigned password to user and integration components did like it. Since that password can be remembered automatically, there is no need to enter it manually every time.

Although it is slightly more cumbersome to setup, I do like this Remote Desktop style.

Virtual Disk Management From PowerShell

Illustration

Since my presentation on KulenDayz 2009 is over, I will share here PowerShell scripts for creating and mounting virtual disks under Windows Server 2008 R2. For those who really need it on Windows 7, there is solution with C# dll called from PowerShell (or just use small sample application).

Here are also links to some older post that cover most of what I was speaking about:

If you are C# soul, you may also want to check my WinDays post.

Windows 7 E

Microsoft decided to ship Windows 7 without Internet Explorer 8 for customers inside European Union, Switzerland and Croatia. While this seems similar to “N” versions of Vista, there is small but significant difference - there will be no full version of Windows 7 available in those countries.

For those who wish to read little bit more, there is Microsoft’s statement and European’s Commission reply to it. I will not go too much into politics of this, although initial European Commission proposal of bundling competition’s browsers inside Windows 7 seems highly idiotic to me. Why on earth would anybody accept this?

When error occurs in Firefox (although we all know that Firefox doesn’t crash), who will get support calls? If customer got Firefox with Windows, he will call Microsoft since probably 90% of them will have no idea that Mozzila even exists. When they fail to get an answer, they will be angry at Microsoft since, in their mind, this is Microsoft’s problem. The only winning move is not to play, and that is exactly what Microsoft did by removing IE.

Although I am Croatian MSDN subscriber (thanks Marc), I hope that this decision will not affect me and that I will still be able to download normal version of Windows 7 with IE. I do want Internet Explorer on my computer (although I have Firefox and Chrome also installed).

I also hope that full version and “E” will share same key. Since they are essentially the same, probably nothing in license will forbid installing Windows from full DVD instead from crippled one. I would use this to install Windows on other people’s computers. It saves me time installing all necessary programs and they can download whatever browser they prefer later.

If everything else fails, I hope that I will at least get option to install it via Windows Update (which is conveniently separated from browser since Windows Vista). This will at least allow me to install it with patches.

Final result will be known on August, 22nd.

[2009-06-26: Because of compliance, it seems that upgrade will not be available in “E” version.]

[2009-07-24: Microsoft proposed “ballot screen” selection to European Commission. Internet Explorer would come with Windows 7 and other browsers will be offered for download after installation.]

Creating Virtual Disk

After open and attach, most common virtual disk operation will be create.

Here it is:

string fileName = @"D:\test.vhd";

long size = 128 * 1024 * 1024;

IntPtr handle = IntPtr.Zero;

var parameters = new CREATE_VIRTUAL_DISK_PARAMETERS();
parameters.Version = CREATE_VIRTUAL_DISK_VERSION.CREATE_VIRTUAL_DISK_VERSION_1;
parameters.Version1.BlockSizeInBytes = 0;
parameters.Version1.MaximumSize = size;
parameters.Version1.ParentPath = IntPtr.Zero;
parameters.Version1.SectorSizeInBytes = CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_SECTOR_SIZE;
parameters.Version1.SourcePath = IntPtr.Zero;
parameters.Version1.UniqueId = Guid.Empty;

var storageType = new VIRTUAL_STORAGE_TYPE();
storageType.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHD;
storageType.VendorId = VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT;

int res = CreateVirtualDisk(ref storageType, fileName, VIRTUAL_DISK_ACCESS_MASK.VIRTUAL_DISK_ACCESS_ALL, IntPtr.Zero, CREATE_VIRTUAL_DISK_FLAG.CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION, 0, ref parameters, IntPtr.Zero, ref handle);
if (res == ERROR_SUCCESS) {
} else {
    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Native error {0}.", res));
}

// close handle to disk
CloseHandle(handle);

System.Windows.Forms.MessageBox.Show("Disk is created.");

Of course, in order for this to work, few P/Interop definitions are needed:

public const Int32 ERROR_SUCCESS = 0;

public const int CREATE_VIRTUAL_DISK_PARAMETERS_DEFAULT_SECTOR_SIZE = 0x200;
public const int VIRTUAL_STORAGE_TYPE_DEVICE_VHD = 2;
public static readonly Guid VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT = new Guid("EC984AEC-A0F9-47e9-901F-71415A66345B");

public enum CREATE_VIRTUAL_DISK_FLAG : int {
  CREATE_VIRTUAL_DISK_FLAG_NONE                     = 0x00000000,
  CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION = 0x00000001
}

public enum CREATE_VIRTUAL_DISK_VERSION : int {
  CREATE_VIRTUAL_DISK_VERSION_UNSPECIFIED = 0,
  CREATE_VIRTUAL_DISK_VERSION_1            = 1
}

public enum VIRTUAL_DISK_ACCESS_MASK : int {
  VIRTUAL_DISK_ACCESS_ATTACH_RO = 0x00010000,
  VIRTUAL_DISK_ACCESS_ATTACH_RW = 0x00020000,
  VIRTUAL_DISK_ACCESS_DETACH    = 0x00040000,
  VIRTUAL_DISK_ACCESS_GET_INFO  = 0x00080000,
  VIRTUAL_DISK_ACCESS_CREATE    = 0x00100000,
  VIRTUAL_DISK_ACCESS_METAOPS   = 0x00200000,
  VIRTUAL_DISK_ACCESS_READ      = 0x000d0000,
  VIRTUAL_DISK_ACCESS_ALL       = 0x003f0000,
  VIRTUAL_DISK_ACCESS_WRITABLE  = 0x00320000
}


[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CREATE_VIRTUAL_DISK_PARAMETERS {
  public CREATE_VIRTUAL_DISK_VERSION Version;
  public CREATE_VIRTUAL_DISK_PARAMETERS_Version1 Version1;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CREATE_VIRTUAL_DISK_PARAMETERS_Version1 {
  public Guid UniqueId;
  public Int64 MaximumSize;
  public Int32 BlockSizeInBytes;
  public Int32 SectorSizeInBytes;
  public IntPtr ParentPath;
  public IntPtr SourcePath;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct VIRTUAL_STORAGE_TYPE {
  public Int32 DeviceId;
  public Guid VendorId;
}


[DllImportAttribute("kernel32.dll", SetLastError = true)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern Boolean CloseHandle(IntPtr hObject);

[DllImport("virtdisk.dll", CharSet = CharSet.Unicode)]
public static extern Int32 CreateVirtualDisk(ref VIRTUAL_STORAGE_TYPE VirtualStorageType, String Path, VIRTUAL_DISK_ACCESS_MASK VirtualDiskAccessMask, IntPtr SecurityDescriptor, CREATE_VIRTUAL_DISK_FLAG Flags, int ProviderSpecificFlags, ref CREATE_VIRTUAL_DISK_PARAMETERS Parameters, IntPtr Overlapped, ref IntPtr Handle);

I think that this is as short as it gets without hard-coding values too much.

If you hate copy/paste, you can download this code sample. Notice that this code only creates virtual disk. If you want to take a look at more details, check full code sample.

P.S. Notice that this code will work with Windows 7 RC, but not with beta (API was changed in meantime).

P.P.S. If you get “Native error 1314.” exception, you didn’t run code as user with administrative rights. If you get “Native error 80.”, file you are trying to create is already there.

Windows Media Center Without IR Extender

Illustration

I tried to configure my MAXtv to work with Windows Media Center. Since that set-top box has S-Video, I though this would be really easy. Oh, how wrong I was.

Someone at Microsoft decided that you MUST have small piece of hardware attached if you wish to receive signal from any external port. Message said it all: “IR Hardware Not Detected”. That small piece is usually called IR blaster and its sole purpose is emulating remote toward your set-top box. While that is useful in normal circumstances, you may not need it all time (e.g. you want to control set-top box with universal remote - like Logitech’s Harmony 555).

However, there is a solution. Installing virtual Vista MCE IR blaster driver takes care of missing hardware and lying to Media Center takes care of configuring it.

Once configured, everything works fine, but I wonder why I needed to jump through hoops to get my S-Video input working.