Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using the hyper v role of windows server 2008 R2. I want to install OS in the virtual machine through C# code.

Also if there is an existing VHD of other VM can I able to link that VHD to a new VM with C# code. Waiting for your help.

share|improve this question

2 Answers 2

Ah. No. You can not never ever install an OS from C# code, you know. How would you do that on a physical server?

There are some ways to autoamte the setup process. They are windows integrated (unattended install) and a prepared image could possibly use a .NET program to pull an answer file automatically, but that is something different than you asked for.

can I able to link that VHD to a new VM with C# code

All the configuration you can easily do from any windows integrated language (which includes any .net language). Hyper-v, being a windows system feature, is fully exposed through WMI.

http://blogs.technet.com/b/benp/archive/2008/08/11/scripting-hyper-v-with-wmi-and-powershell-part-1-introduction-querying-state.aspx

has some starts for using PowerShell, the same principles apply for any WMI capable language.

share|improve this answer

C# is just a language, and much like any other. The question you're asking has little to do with language.

If you're asking if you can programmatically manipulate a VM under Hyper-V, the answer is yes. Hyper-V is entirely managed through WMI interfaces, as defined here:

http://msdn.microsoft.com/en-us/library/cc136992(VS.85).aspx

You can interact with that in C#, using the .Net WMI classes, or you can (probably more easily) drive PowerShell cmdlets with your C# code. Whichever you're more comfortable with, they'll be more similar than different, as they both resolve down to .Net classes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.