<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Care, Share and Grow! : Virtual Server</title><link>http://blogs.msdn.com/saurabh_singh/archive/tags/Virtual+Server/default.aspx</link><description>Tags: Virtual Server</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Programmatically managing Virtual Server using C#</title><link>http://blogs.msdn.com/saurabh_singh/archive/2008/10/25/programmatically-managing-virtual-server-using-c.aspx</link><pubDate>Sat, 25 Oct 2008 04:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9015523</guid><dc:creator>Saurabh Singh</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/saurabh_singh/comments/9015523.aspx</comments><wfw:commentRss>http://blogs.msdn.com/saurabh_singh/commentrss.aspx?PostID=9015523</wfw:commentRss><wfw:comment>http://blogs.msdn.com/saurabh_singh/rsscomments.aspx?PostID=9015523</wfw:comment><description>&lt;p&gt;Virtual Server 2005 (VS2005) is a well-known tool to manage Virtual Machines (VMs) on a host server. It is a great feature to manage virtualization for hardware/software. Most often one would use the VS2005 Web Admin&amp;nbsp; interface to manage VMs. But at times (like the way it recently happened for a customer of mine) one may want to programmatically control the VMs. This would most often sound a necessity if you would like to provide end users access to manage basic VM activities like turn on/off, save state etc. etc. without giving them access to everything as in through the VS2005 Web Admin site. &lt;/p&gt; &lt;p&gt;Here are some code snippets/sample web application/links in case you would like to try your hands on something like this.&lt;/p&gt; &lt;p&gt;Let me show you a typical screen-shot of how VS2005 Web Admin interface looks like.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_2.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb.png" style="border-width: 0px;" alt="image" mce_src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb.png" border="0" height="388" width="640"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_8.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb_3.png" style="border-width: 0px;" alt="image" mce_src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb_3.png" border="0" height="126" width="338"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;To programmatically manage the Virtual machines on a host server, you need to add a reference to a COM object for your .Net application which exposes various properties/methods.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_4.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb_1.png" style="border-width: 0px;" alt="image" mce_src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb_1.png" border="0" height="380" width="463"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Visual Studio will add a COM Interop layer for this. You should see the following in your Visual Studio project:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_6.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb_2.png" style="border-width: 0px;" alt="image" mce_src="http://blogs.msdn.com/blogfiles/saurabh_singh/WindowsLiveWriter/a6ba50994cc4_4155/image_thumb_2.png" border="0" height="35" width="275"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Ensure we add a namespace as "using Microsoft.VirtualServer.Interop;" in the web/form page.&lt;/p&gt; &lt;p&gt;Here are code snippets (in C#) to:&lt;/p&gt; &lt;p&gt;a. &lt;b&gt;Turn On/Restore from a saved state &lt;/b&gt;for a Virtual machine on a local host machine.&lt;/p&gt; &lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_TurnedOff || vm.State == VMVMState.vmVMState_Saved)&lt;br&gt;                {&lt;br&gt;                        VMTask vt = vm.Startup();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;b. &lt;b&gt;Turn Off &lt;/b&gt;a Virtual machine on a local host machine.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_Running || vm.State == VMVMState.vmVMState_Paused)&lt;br&gt;                {&lt;br&gt;                        &lt;span style="color: rgb(0, 128, 0);"&gt;// Turn the power off on the Guest VM&lt;/span&gt;&lt;br&gt;                        Label1.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;"Forcefully shutting down VM..."&lt;/span&gt;;&lt;br&gt;                        VMTask vt = vm.TurnOff();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br&gt;                            Label1.Text = &lt;span style="color: rgb(0, 96, 128);"&gt;"Not ready for a turn off. Please wait and try again after a few seconds..."&lt;/span&gt;;&lt;br&gt;                 }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;c. &lt;b&gt;Save state&lt;/b&gt; of a Virtual machine on a local host machine.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_TurnedOff || vm.State == VMVMState.vmVMState_Saved)&lt;br&gt;                {&lt;br&gt;                        VMTask vt = vm.Startup();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;d. &lt;b&gt;Pause &lt;/b&gt;a Virtual machine on a local host machine.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_TurnedOff || vm.State == VMVMState.vmVMState_Saved)&lt;br&gt;                {&lt;br&gt;                        VMTask vt = vm.Startup();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;e. &lt;b&gt;Resume&lt;/b&gt; a Virtual machine on a local host machine.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_TurnedOff || vm.State == VMVMState.vmVMState_Saved)&lt;br&gt;                {&lt;br&gt;                        VMTask vt = vm.Startup();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;f. &lt;b&gt;Reset&lt;/b&gt; a Virtual machine on a local host machine.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_TurnedOff || vm.State == VMVMState.vmVMState_Saved)&lt;br&gt;                {&lt;br&gt;                        VMTask vt = vm.Startup();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;g. &lt;b&gt;Shut down&lt;/b&gt; a virtual machine on a local host machine.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_TurnedOff || vm.State == VMVMState.vmVMState_Saved)&lt;br&gt;                {&lt;br&gt;                        VMTask vt = vm.Startup();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;h. &lt;b&gt;Enumerate&lt;/b&gt; all the Virtual machines running on the local host machine.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_TurnedOff || vm.State == VMVMState.vmVMState_Saved)&lt;br&gt;                {&lt;br&gt;                        VMTask vt = vm.Startup();&lt;br&gt;                        &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vt != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;br&gt;                            vt.WaitForCompletion(-1);&lt;br&gt;                }&lt;br&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;i. Check various properties exposed through the COM API.&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;VMVirtualServerClass vs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; VMVirtualServerClass();&lt;br&gt;&lt;br&gt;VMVirtualMachine vm = vs.FindVirtualMachine(VM_name);&lt;br&gt;&lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; _VMName = vm.Name;&lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; _guestOS = String.Empty;&lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (vm.State == VMVMState.vmVMState_Running)&lt;br&gt;                    _guestOS = vm.GuestOS.OSName;&lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;br&gt;                    _guestOS = &lt;span style="color: rgb(0, 96, 128);"&gt;"OS: n/a"&lt;/span&gt;; &lt;br&gt;                &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; _memory = vm.Memory.ToString();&lt;br&gt;                .......&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;j. At times if you want to manage VMs hosted on a remote machine and not on the local machine, here is what you need to do besides all the steps already mentioned above. &lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; VMVirtualServerClass connectToRemoteHost(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; remoteHost)&lt;br&gt;    {&lt;br&gt;        VMVirtualServerClass virtualServerCOM = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;br&gt;        Type VMVirtualServerClassType = &lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;(VMVirtualServerClass);&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;br&gt;        {&lt;br&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// create remote type from class identifier&lt;/span&gt;&lt;br&gt;            Type DCOMType = Type.GetTypeFromCLSID(VMVirtualServerClassType.GUID, remoteHost, &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;);&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; DCOMObject = Activator.CreateInstance(DCOMType);&lt;br&gt;            &lt;span style="color: rgb(0, 128, 0);"&gt;// create local object from remote object&lt;/span&gt;&lt;br&gt;            virtualServerCOM = (VMVirtualServerClass)Marshal.CreateWrapperOfType(DCOMObject, VMVirtualServerClassType);&lt;br&gt;            TextBox1.Text = String.Empty;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; virtualServerCOM;&lt;br&gt;        }&lt;br&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt;&lt;br&gt;        {&lt;br&gt;            TextBox1.Text =&lt;span style="color: rgb(0, 96, 128);"&gt;"There was an error while connecting to the remote host. Make sure that we have the necessary permissions/settings to access the remote host"&lt;/span&gt;;&lt;br&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;    }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (Courtesy this MSDN &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163935.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc163935.aspx" target="_blank"&gt;magazine&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;I have not included error handling in the code snippets above. Please do so when you build the actual application. Also there are many other activities that can be performed besides the ones discussed above like setting up a VM from the beginning with various components like differencing, memory, network adapter etc., changing the disk configuration of an existing machine etc. etc.&lt;/p&gt;
&lt;p&gt;The more you explore the more you get to control through the code using the API mentioned above.&lt;/p&gt;
&lt;p&gt;Here are some useful links related to the topic.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163935.aspx" title="http://msdn.microsoft.com/en-us/magazine/cc163935.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc163935.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/cc163935.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://dotnet.sys-con.com/node/47338" title="http://dotnet.sys-con.com/node/47338" mce_href="http://dotnet.sys-con.com/node/47338"&gt;http://dotnet.sys-con.com/node/47338&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/david.wang/archive/2006/04/17/HOWTO-Perform-VHD-Maintenance-Automatically.aspx" title="http://blogs.msdn.com/david.wang/archive/2006/04/17/HOWTO-Perform-VHD-Maintenance-Automatically.aspx" mce_href="http://blogs.msdn.com/david.wang/archive/2006/04/17/HOWTO-Perform-VHD-Maintenance-Automatically.aspx"&gt;http://blogs.msdn.com/david.wang/archive/2006/04/17/HOWTO-Perform-VHD-Maintenance-Automatically.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.anildesai.net/?p=220" title="http://blog.anildesai.net/?p=220" mce_href="http://blog.anildesai.net/?p=220"&gt;http://blog.anildesai.net/?p=220&lt;/a&gt;, &lt;a href="http://blog.anildesai.net/?p=214" title="http://blog.anildesai.net/?p=214" mce_href="http://blog.anildesai.net/?p=214"&gt;http://blog.anildesai.net/?p=214&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Attached is a sample ASP.Net 2.0 web application to try the above commands if interested.&lt;/p&gt;
&lt;p&gt;Till next time our paths cross.&lt;/p&gt;
&lt;p&gt;Bye!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9015523" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/saurabh_singh/attachment/9015523.ashx" length="28538" type="application/octet-stream" /><category domain="http://blogs.msdn.com/saurabh_singh/archive/tags/ASP.Net/default.aspx">ASP.Net</category><category domain="http://blogs.msdn.com/saurabh_singh/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/saurabh_singh/archive/tags/.Net/default.aspx">.Net</category><category domain="http://blogs.msdn.com/saurabh_singh/archive/tags/Code+Sample/default.aspx">Code Sample</category><category domain="http://blogs.msdn.com/saurabh_singh/archive/tags/Virtual+Server/default.aspx">Virtual Server</category></item></channel></rss>