Hi André,<br><br>Looks like we don't have many users virtualizing windows machines.<br>Maybe this kind of questions can be better helped in a windows  support list...<br><br>Since you took the time to create and share the contextualization scripts, if you come up with a working procedure and want to contribute a guide or how-to, we'd be glad to have it in the community wiki [1].<br>

<br>Regards.<br><br>[1] <a href="http://opennebula.org/documentation:community:index">http://opennebula.org/documentation:community:index</a><br><span style="border-collapse:collapse;color:rgb(136, 136, 136);font-family:arial, sans-serif;font-size:13px">--<br>

Carlos Martín, MSc<br>Project Major Contributor<br><span style="background-color:rgb(255, 255, 204);color:rgb(34, 34, 34);background-repeat:initial initial">OpenNebula</span> - The Open Source Toolkit for Cloud Computing<br>

<a href="http://www.opennebula.org/" style="color:rgb(42, 93, 176)" target="_blank">www.<span style="background-color:rgb(255, 255, 204);color:rgb(34, 34, 34);background-repeat:initial initial">OpenNebula</span>.org</a> | <a href="mailto:cmartin@opennebula.org" style="color:rgb(42, 93, 176)" target="_blank">cmartin@<span style="background-color:rgb(255, 255, 204);color:rgb(34, 34, 34);background-repeat:initial initial">opennebula</span>.org</a></span><br>


<br><br><div class="gmail_quote">2011/8/5 André Monteiro <span dir="ltr"><<a href="mailto:andremonteiro@ua.pt">andremonteiro@ua.pt</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div> Hello,</div><div> </div><div>I've been working in a windows script to contextualize VMs.<a href="http://www.pastie.org/2324611By" target="_blank"></a></div><a href="http://www.pastie.org/2324611By" target="_blank"></a><div>

 By your experience, what's the best way to run the script automatically when creating a new instance? I can create it manually as a CD-ROM and run the windows7.one with the drive attached, but is there an automatic way?</div>



<div> </div><div>################### Windows context configuring script ###################</div><div>########### Created by <a href="mailto:andremonteiro@ua.pt" target="_blank">andremonteiro@ua.pt</a> and <a href="mailto:tsbatista@ua.pt" target="_blank">tsbatista@ua.pt</a> ###########</div>




<div> </div><div>[string]$computerName = "$env:computername"<br>[string]$ConnectionString = "WinNT://$computerName"<br>[string]$ipaddress = ""</div><div>function getContext($file) {<br> $context = @{}<br>




 switch -regex -file $file {<br>  '(.+)="(.+)"' {<br>   $name,$value = $matches[1..2]<br>   $context[$name] = $value<br>  }<br> }<br> return $context<br>}</div><div>function addLocalUser($context) {</div>




<div>    # Create new user<br> $username =  $context["username"]<br> $ADSI = [adsi]$ConnectionString<br> $user = $ADSI.Create("user",$userName)<br> $user.setPassword($context["user_password"])<br>




 $user.SetInfo()<br>    <br>    # Add user to local Administrators    <br>    $groups = "Administrators", "Administradores"<br> <br>    foreach ($grp in $groups) {<br>    if([ADSI]::Exists("WinNT://$computerName/$grp,group")) {  <br>




  $group = [ADSI] "WinNT://$computerName/$grp,group"<br>   $group.Add("WinNT://$computerName/$username")<br>  }<br> }<br>}</div><div>function getIp($mac) {<br>    $octet = $mac.Split(":")<br>




    [String] $ip = ""<br>    $ip += [convert]::toint32($octet[2],16)<br>    $ip += "."+[convert]::toint32($octet[3],16)<br>    $ip += "."+[convert]::toint32($octet[4],16)<br>    $ip += "."+[convert]::toint32($octet[5],16)<br>




    $ipaddress = $ip<br>    return $ip<br>}</div><div>function getGateway($mac) {<br>    $octet = $mac.Split(":")<br>    [String] $ip = ""<br>    $ip += [convert]::toint32($octet[2],16)<br>    $ip += "."+[convert]::toint32($octet[3],16)<br>




    $ip += "."+[convert]::toint32($octet[4],16)<br>    $ip += ".1"<br>    return $ip<br>}</div><div>function configureNetwork($context) {<br>    $Nics = Get-WMIObject Win32_NetworkAdapterConfiguration | where {$_.IPEnabled -eq "TRUE" -and ($_.MACAddress)} <br>




    foreach ($nic in $Nics) {<br>        [String]$mac = $nic.MACAddress<br>        [String]$ip = getIp($mac)<br>        [String]$gw = getGateway($mac)<br>        $nic.ReleaseDHCPLease()<br>        $nic.EnableStatic($ip , "255.255.255.0")<br>




        $nic.SetGateways($gw)<br>        $nic.SetDNSServerSearchOrder($gw)<br>        $nic.SetDynamicDNSRegistration("FALSE")<br>    }<br>}</div><div>function renameComputer($context) {<br>    $ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem  <br>




    $ComputerInfo.rename($context["HOSTNAME"]+$ipaddress.Split(".")[3])<br>}</div><div>function enableRemoteDesktop()<br>{<br>    #Get RDP parameters<br>    #(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices).AllowTsConnections<br>




    #Set RDP state<br>    #(Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices).SetAllowTsConnections(1)<br>    #Get RDP Required Authentication <br>    #(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").UserAuthenticationRequired<br>




    #Set RDP Required Authentication <br>    #(Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(1)</div>




<div>    $Terminal = (Get-WmiObject -Class "Win32_TerminalServiceSetting" -Namespace root\cimv2\terminalservices).SetAllowTsConnections(1)<br>    return $Terminal<br>}</div><div># Create folder Context if unexistant<br>




if( -not(Test-Path "c:\context\")) {<br> New-Item "c:\context\" -type directory<br>}</div><div><br># Execute the script<br>if( -not(Test-Path "c:\context\contextualized") -and(Test-Path "D:\context.sh")) {<br>




    $context = @{} <br>    $context = getContext('D:\context.sh')<br>    Set-ExecutionPolicy unrestricted -force # not needed if already done once on the VM<br>    addLocalUser($context)<br>    configureNetwork($context)<br>




    renameComputer($context)<br>    enableRemoteDesktop()<br>    echo "contextualized" |Out-File ("c:\context\contextualized")<br>    restart-computer<br>}</div><div># remember to disable password complexity requirements in computer<br>




# management while rpeparing the cloud image!</div><div># Remember to run "Set-ExecutionPolicy bypass -force" before this!<br clear="all"><br>--<br>André Monteiro<br><br><br>
<b>Carlos Martín Sánchez</b> <a title="[one-users] How config Windows vm template?" href="mailto:users%40lists.opennebula.org?Subject=Re%3A%20%5Bone-users%5D%20How%20config%20Windows%20vm%20template%3F&In-Reply-To=%3CBANLkTimxR8Z3MbY_PJjPNqGNafegwYs4wQ%40mail.gmail.com%3E" target="_blank">cmartin 
at opennebula.org </a><br><i>Thu May 12 02:22:09 PDT 2011</i> 
</div><p>
</p><ul>
<li>Previous message: <a href="http://lists.opennebula.org/pipermail/users-opennebula.org/2011-May/005192.html" target="_blank">[one-users] How config Windows vm 
template? </a>
</li><li>Next message: <a href="http://lists.opennebula.org/pipermail/users-opennebula.org/2011-May/005193.html" target="_blank">[one-users] having a problem when shut 
down a VM </a>
</li><li><b>Messages sorted by:</b> <a href="http://lists.opennebula.org/pipermail/users-opennebula.org/2011-May/date.html#5282" target="_blank">[ date ]</a> <a href="http://lists.opennebula.org/pipermail/users-opennebula.org/2011-May/thread.html#5282" target="_blank">[ thread ]</a> <a href="http://lists.opennebula.org/pipermail/users-opennebula.org/2011-May/subject.html#5282" target="_blank">[ subject 
]</a> <a href="http://lists.opennebula.org/pipermail/users-opennebula.org/2011-May/author.html#5282" target="_blank">[ author ]</a> </li></ul>
<hr>
<pre>Hi there,

The contextualization offered by OpenNebula is creating that cdrom and
context.sh script, but it's up to the guest OS to read that file and
configure itself.

We only provide linux scripts; you would have to create similar ones. I'm
not sure how difficult that can be since I don't have experience with
Windows scripting.


If you only need to configure the right IP for your VM, then you can try to
configure a DHCP server in your network (it can be placed in a VM in the
same VNet). This has been discussed in the list, hopefully these threads
will help:

[1] <a href="http://www.mail-archive.com/users@lists.opennebula.org/msg01143.html" target="_blank">http://www.mail-archive.com/users@lists.opennebula.org/msg01143.html</a>
[2] <a href="http://www.mail-archive.com/users@lists.opennebula.org/msg01395.html" target="_blank">http://www.mail-archive.com/users@lists.opennebula.org/msg01395.html</a>

Regards

--
Carlos Martín, MSc
Project Major Contributor
OpenNebula - The Open Source Toolkit for Cloud Computing
<a href="http://www.OpenNebula.org" target="_blank">www.OpenNebula.org</a> <<a href="http://www.opennebula.org/" target="_blank">http://www.opennebula.org/</a>> | <a href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org" target="_blank">cmartin at opennebula.org</a>


2011/5/6 ddd <<a href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org" target="_blank">xrchina2008 at 163.com</a>>

><i>  hi,all
</i>><i>        now,my winxp vm is running.but,config's ip and hostname is not
</i>><i> right.
</i>><i>        now,windows vm's cd-rom is existing context.sh.
</i>><i>        This is my vm config file:
</i>><i>                 NAME=WinVista
</i>><i>                 CPU=1
</i>><i>                 MEMORY=1024
</i>><i>                 OS=[boot=hd]
</i>><i>                 DISK =[source="/root/images/winxp_test.img", clone=yes,
</i>><i> target=hda, readonly=no]
</i>><i>                 NIC=[network ="Small network"]
</i>><i>                 CONTEXT=[
</i>><i>                        hostname   = "$NAME$VMID",
</i>><i>                        ip_public  = "$NIC[IP, NETWORK=\"Small network\"]",
</i>><i>                        target     ="hdb"
</i>><i>                 ]
</i>><i>                 GRAPHICS =[type ="vnc",listen ="127.0.0.1", port = "1"]
</i>><i>        windows template  need config?how?
</i>><i>        Please help me.
</i>><i>                                                             ---Rong  Xiong
</i>><i>
</i>><i>
</i>><i>
</i>><i>
</i>><i>
</i>><i>
</i>><i>
</i>><i>
</i>><i>
</i>><i> _______________________________________________
</i>><i> Users mailing list
</i>><i> <a href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org" target="_blank">Users at lists.opennebula.org</a>
</i>><i> <a href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org" target="_blank">http://lists.opennebula.org/listinfo.cgi/users-opennebula.org</a>
</i>><i>
</i>><i>
</i></pre><p></p>
<p></p>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.opennebula.org">Users@lists.opennebula.org</a><br>
<a href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org" target="_blank">http://lists.opennebula.org/listinfo.cgi/users-opennebula.org</a><br>
<br></blockquote></div><br>