Posts tagged ‘Windows’

Emulated Managed Windows Pipes with Standard Input and Output

Pipes are around since Unix, Linux and Windows 95. Pipes are a way of communication between two programs. It’s a virtual channel to the process. Normally it is a system function call in the kernel.dll.

A pipe is a one way channel that you can write or read. So to write and read basically we need to have a two channels. One for reading and one for writing.

In managed world, we don’t have spawn (Windows) function or fork (Linux) function to create a copy of the process. So the first trick is to create the same process with different arguments. Than redirect the standard input and output to our current process. Basically these are kind of pipes. You may know the pipe operator (|) available from the shell which redirects the standard output of the program to the standard input of the main process. What’s more in this is we write to the child process’ standard output. So we program in a way that the child process waits some commands from the parent process, execute the command and output results to parent process.

In this sample there are two processes, talking to each other.

using System;
using System.Collections.Generic;
using System.Text;
 
namespace WinPipes
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                //parent
                Console.WriteLine("Parent");
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
 
                proc.StartInfo.Arguments = "child";
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardInput = true;
 
                proc.Start();
                System.IO.StreamReader str = proc.StandardOutput;
 
                Console.WriteLine("How many messages ?");
                int messageCount ;
                int.TryParse(Console.ReadLine(), out messageCount);
 
                proc.StandardInput.WriteLine(messageCount);
 
                for (int i = 0; i < messageCount; i++)
                {
                    Console.WriteLine("Sending Hello" + (i + 1));
                    proc.StandardInput.WriteLine("hello" + (i + 1));
                    Console.WriteLine(str.ReadLine());
                }
                Console.ReadLine();
            }
            else
            {
                // child
                int count = Convert.ToInt32(Console.ReadLine());
                for (int i = 0; i < count; i++)
                {
                    Console.WriteLine("Re - " + Console.ReadLine());
                }
 
            }
        }
    }
}

Parent
How many messages ?
3
Sending Hello1
Re - hello1
Sending Hello2
Re - hello2
Sending Hello3
Re - hello3

Pipes are not available in .Net Framework 2.0 and 3.0. However .Net Framework 3.5 will include managed classes for pipes. The best way to do pipes in a system level to invoke the system calls using some unmanaged code. For kernel the function name is CreatePipe or CreateNamedPipe. There is also a function int the standard C library called _pipe. Pinvoke.net is the best reference for calling kernel functions from the managed environment.

Vista Developer Day at Microsoft UK

I just surprised when I see an event from Microsoft about Windows Vista. I was expecting it, but not before the real release of Vista. Anyway, it is a bit late for telling that, but Vista Developer Launch is this weekend at Microsoft Campus in Reading.

This is a 2 day event 19th and 20th January. 19th January will be some sessions about Windows Vista or Office 2007. 20th January will be practice. So they invite us to code in a huge room which sounds really cool. They also claim that they have 1000 of Windows Vista copies.

On Friday, I have to work so I will not join the first day. However if I can wake up, I really want to go on Saturday for coding with people :). If you like to join me, just contact me… I was invited for a dinner on Friday night and I just couldn’t make it..

Google’s Malware Warning

My windows became unbootable, I was receiving and I logged to my linux partition. I was looking for the bootdisks for my flash drive because I don’t have an XP cd (Laptop gave only the ghost image of Windows CD), I needed to have chkdsk command at least, so I googled for “windows boot disk usb chkdsk” then clicked the 2nd result which is “Bootdisk.Com Top Ten TuneUp Tips” the link goes to http://www.google.co.uk/interstitial?url=http://www.bootdisk.com/topten.htm site and the Malware Warning page.


Malware


I wouldn’t know, It is nice to know that, although I am totaly in an another platform (I am in linux and can’t boot windows) it is nice to have that.

I found BartPE bootable cd for the solution of my problem. It is uses Windows XP files and can be used for the bootable cd or bootable flash disk.

Here are links that you can find more information :

.Net Framework 3.0

WinFX has been renamed to .Net framework 3. Although .Net framework 3 is simple and easy to remember, I get used to Winfx.
I liked WinFX. It was like Win32, Win16..
Just like the avalon case renames to WPF, new names will be remembered at last.

Apparently there is no new version come up on the download page. So hopefully some new packages will come up. Another 1.5GB will wait us, and another system maintenance, uninstall the previous one and install the new one, than interestingly some things will stop working….

WinFX -> .NET Framework 3

InfoCard -> Windows CardSpace

.Net Framework 3
Soma .Net Framework 3 blog

netframeworkimage.png

Dual boot linux and windows with windows boot manager — Vista RTM Update

They are many documents on the web for doing that. However most of them needs to have an installed linux based system to do that. Installing linux without destruction your harddisk is possible for years. I assume that you have windows installed. Here is the walkthrough to do that.

  1. Allocate space for linux partition. The main partition for linux has to be primary partition just like your windows partition. You might need a partition tool to resize and change partition type to do that operation.
  2. Install linux on the partition that you have just created. On the installation screens, for the boot loader, select the partition itself as the partition (don’t select mbr). When the installation has finished, your computer restarts and windows will be restarted. Don’t be afraid linux is somewhere in your disk.
  3. You need dd for windows to set linux to the boot manager.
  4. Extract the contents of dd in a folder and run

    dd --list

    D:\Tools\dd>dd –list
    rawwrite dd for windows version 0.3.
    Written by John Newbigin
    This program is covered by the GPL. See copying.txt for details
    Win32 Available Volume Information
    \\.\Volume{c5d941f0-8093-11da-b7d7-806d6172696f}\
    link to \\?\Device\HarddiskVolume1
    fixed media
    Mounted on c:\
    \\.\Volume{c5d941f1-8093-11da-b7d7-806d6172696f}\
    link to \\?\Device\HarddiskVolume3
    fixed media
    Mounted on d:\
    \\.\Volume{5c5aa360-7406-11da-b7c2-806d6172696f}\
    link to \\?\Device\CdRom0
    CD-ROM
    Mounted on e:\
    \\.\Volume{23c0e842-75dd-11da-a45d-000e3536c876}\
    link to \\?\Device\CdRom1
    CD-ROM
    Mounted on x:\
    NT Block Device Objects
    \\?\Device\CdRom0
    \\?\Device\CdRom1
    \\?\Device\Harddisk0\Partition0
    link to \\?\Device\Harddisk0\DR0
    Fixed hard disk media. Block size = 512
    \\?\Device\Harddisk0\Partition1
    link to \\?\Device\HarddiskVolume1
    \\?\Device\Harddisk0\Partition2
    link to \\?\Device\HarddiskVolume2
    Fixed hard disk media. Block size = 512
    \\?\Device\Harddisk0\Partition3
    link to \\?\Device\HarddiskVolume3
    \\?\Device\Harddisk0\Partition4
    link to \\?\Device\HarddiskVolume4
    Fixed hard disk media. Block size = 512


    to find the linux partition.

  5. Once you think you’ve found it just use this command to generate the boot file.

    dd if=\\?\Device\HarddiskVolume2 of=linux.boot bs=512 count=1

    D:\Tools\dd>dd if=\\?\Device\HarddiskVolume2 of=linux.bot bs=512 count=1
    rawwrite dd for windows version 0.3.
    Written by John Newbigin
    This program is covered by the GPL. See copying.txt for details
    1+0 records in
    1+0 records out

    Here Partition2 is the linux partition. You need to feel that from the dd –list output

  6. Move the generated file to the root C:
  7. Then add
    C:\LINUX.BOOT="Linux"

    to boot.ini file.

Vista Update

The above process is still working for Windows Vista beside boot.ini file. Instead we need to bcdedit to add the new entry.

Run cmd and execute the following commands to add the linux entry

bcdedit /create /d “Linux” /application BOOTSECTOR
bcdedit /set {LinuxID} device boot
bcdedit /set {LinuxID} PATH \LINUX.BOOT
bcdedit /displayorder {LinuxID} /addlast
bcdedit /timeout 5

Here you are you have used windows boot manager to do that inside windows.

Mono on Windows just like linux

There is two live cds especially designed for mono on linux.

  1. Monoppix
  2. Mono Live

Both distributions include mono librarires and tools. Mono Live distribution includes some applications written in mono like beagle or tomboy. Also it includes some known ASP.Net web applications. As a result it is 200Mb more than monoppix.
These cds are live cds meaning that you can boot from them and work on them without the need of a harddisk. As .net developer you will probably use windows and maybe you want to give a try to the opensource alternative. It is difficult to switch to live cds than go back to windows. Instead there is a tool to emulate your processor on windows (on linux as well actually) called qemu. This tool can also work on windows. You can download qemu in windows. You can boot any live cd distribution with this tool.

Simply just edit your .bat file
qemu -L . -m 300 -cdrom ./monoppix.iso
qemu -L . -m 300 -cdrom ./monolive.iso

Monoppix