# Windows server context

**URL:** <https://forum.opennebula.io/t/windows-server-context/4807>\
**Category:** Product Support\
**Created:** [August 24, 2017, 6:10am UTC](https://forum.opennebula.io/t/windows-server-context/4807 "2017-08-24T06:10:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 24, 2017, 6:10am UTC](https://forum.opennebula.io/t/windows-server-context/4807/1 "2017-08-24T06:10:53Z")

</div>

I’ve followed the doc [https://docs.opennebula.org/5.4/operation/vm\_setup/vcenter.html#vcenter-one-context](https://docs.opennebula.org/5.4/operation/vm_setup/vcenter.html#vcenter-one-context) to make a VM template for Windows Server 2016. Is the order really correct? It says:

1. Start a VM with OS  
2-3. Download and install the one-context-5.4.0.msi and run sysprep
2. Install VMtools…

Shouldn’t the sysprep be runned at the last step with generalize and shutdown? Otherwise the VM is not generalized after step 4.

Also I’m wondering if the sysprep would be run with a unattend file so that regional settings and the initial admin password is set, even if that can be set to something else through the context part/attribute?

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 24, 2017, 7:57am UTC](https://forum.opennebula.io/t/windows-server-context/4807/2 "2017-08-24T07:57:29Z")

</div>

![image](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/c/c37892a59e67bffb3399978cde4626852935f615.jpg)

This is the error I get if I start a new VM.  
Update: If I run the script manually in PS it says “No Context CDROM found”

---

<div class="post-metadata">

**Author:** ![jfontan](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jfontan/32/18_2.png) [@jfontan](https://forum.opennebula.io/u/jfontan)\
**Post date:** [August 24, 2017, 3:12pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/3 "2017-08-24T15:12:35Z")

</div>

You are right, sysprep must be executed after VMware tools are installed. We will change the documentation accordingly.

You can add an `unattend.xml` file to automatically configure windows. For password this can be done using contextualization. You can find the list of options here:

[http://docs.opennebula.org/5.4/operation/references/template.html#context-section](http://docs.opennebula.org/5.4/operation/references/template.html#context-section)

There may be two problems there:

- VMware tools are not installed
- The VM does not have contextualization enabled

Check in the VM template, Context tab, that the checkbox “Add Network contextualization” is enabled

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 24, 2017, 3:21pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/4 "2017-08-24T15:21:49Z")

</div>

Thanks. The VM template has VM tools installed and OK. I’ve removed the NIC from the VM prior to converting it to a template (saw that in some forum thread). This is how the template looks like in OpenNebula. Hope that is correct?  
I’ve also added an unattend file to the sysprep command to hide eula and set input localization and such.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/2/27c852919a560be14f476531bbee2a022478e417.png)

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 28, 2017, 2:08pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/5 "2017-08-28T14:08:24Z")

</div>

Any other suggestions on what could cause this?

---

<div class="post-metadata">

**Author:** ![jfontan](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jfontan/32/18_2.png) [@jfontan](https://forum.opennebula.io/u/jfontan)\
**Post date:** [August 28, 2017, 2:55pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/6 "2017-08-28T14:55:51Z")

</div>

No. It’s the first time I see that problem. Maybe someone with more Windows scripting expertise can jump in.

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 28, 2017, 4:42pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/7 "2017-08-28T16:42:45Z")

</div>

Ok, but as far as you can see I’ve done what’s necessary to get it going? Is it some security setting in the OS that needs to be modified maybe?

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 28, 2017, 5:37pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/8 "2017-08-28T17:37:15Z")

</div>

Where is the context attributes put on the VM? Does it attach an cdrom image? I can, in some cases, get it to run OK when i manually start context.ps1. And if that runs OK there’s a [context.sh](http://context.sh) file created in the c: root with the attributes I’ve entered.  
I can’t figure out when it works and not though. But it always fail during automatic start (which is done from the opennebula service I think?)

---

<div class="post-metadata">

**Author:** ![vholer](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/vholer/32/4392_2.png) [@vholer](https://forum.opennebula.io/u/vholer)\
**Post date:** [August 29, 2017, 6:44pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/9 "2017-08-29T18:44:35Z")

</div>

On KVM, it’s taken from the ISO image named CONTEXT. On VMware, vmtools and channel between the hypervisor are used. Can you please try to start the service manually on booted system (so we know if it’s related to the boot process, e.g. a dependency issue, or problem with the service itself)

```auto
net stop onecontext
net start onecontext

```

and check the `c:\.opennebula-context.out`, if the failure is still there.

Unfortunately, I’m not able to reproduce the problem on clean W2k16.

 ![Screenshot at 2017-08-29 20-32-38](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/6/6e63490dfe2efbcc6cdef8cd1c7aa95867241d06.png)

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 30, 2017, 6:19am UTC](https://forum.opennebula.io/t/windows-server-context/4807/10 "2017-08-30T06:19:46Z")

</div>

This is the log when stop/start of service.

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/f/ff028dcf83ac51c113fb01c171c081308b9163c7.jpg)

One thing I noticed though. If I check the log after normal boot it looks like this:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/9/98e28d8f36cbc95c0e3797db979052050f4aaf7d.jpg)  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/9/93e70ddd7579f6aeebef7b9ea99135ec7d63af27.jpg)

Also I can’t delete the logfile because PS is still running (I’ve let it run for an extended time but it never stops).

But when I run the context.ps1 script manually it runs OK

---

<div class="post-metadata">

**Author:** ![vholer](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/vholer/32/4392_2.png) [@vholer](https://forum.opennebula.io/u/vholer)\
**Post date:** [August 30, 2017, 8:23am UTC](https://forum.opennebula.io/t/windows-server-context/4807/11 "2017-08-30T08:23:57Z")

</div>

> [@NiclasEriksson](#):
>
> This is the log when stop/start of service.  
> image.jpg763x507 181 KB

So it looks like it doesn’t work only during the boot process. I guess the WMI isn’t started yet, so I would try to add a service dependency on WMI. If you want, you can try [one-context-5.4.0.1.msi](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/3/3238a2d35d94b58521a9f80883033a0d38a50549.msi) to check if it behaves. The changes against [GitHub - OpenNebula/addon-context-windows: Windows VM Contextualization](https://github.com/OpenNebula/addon-context-windows) are following:

```auto
diff --git a/package.wxs b/package.wxs
index f9f13c0..4858d26 100644
--- a/package.wxs
+++ b/package.wxs
@@ -56,7 +56,10 @@
               Start="auto"
               Account="[SYSTEM]"
               Arguments="-s onecontext"
- ErrorControl="normal" />
+ ErrorControl="normal">
+
+ <ServiceDependency Id="winmgmt" />
+ </ServiceInstall>
 
             <ServiceControl Id="ocControl" Name="onecontext"
               Remove="both"

```

Thank you.

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 30, 2017, 9:35am UTC](https://forum.opennebula.io/t/windows-server-context/4807/12 "2017-08-30T09:35:36Z")

</div>

Unfortunally the same problem exist. I’ve also tested it on a Win2012R2 template but the same problem occurs. Again, if I run it manually in a PS shell it works as expected. Is there a “flag” that tells the service that it’s already runned once ?

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 30, 2017, 9:42am UTC](https://forum.opennebula.io/t/windows-server-context/4807/13 "2017-08-30T09:42:37Z")

</div>

I saw something interesting right now actually. I looked at the params of the context service and the path is:  
C:\Windows\SysWOW64\WindowsPowerShell\V1.0\powershell.exe " and the file context.ps1. If i run this in a cmd prompt it says “No context CDROM found”. If I run the ps1 file in PS shell it works.

---

<div class="post-metadata">

**Author:** ![vholer](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/vholer/32/4392_2.png) [@vholer](https://forum.opennebula.io/u/vholer)\
**Post date:** [August 30, 2017, 9:44am UTC](https://forum.opennebula.io/t/windows-server-context/4807/14 "2017-08-30T09:44:17Z")

</div>

We test the W2012r2 and it’s fine for us as well. Unfortunately, I still can’t reproduce the problem. The best would be if you can provide the image so I can look on it. If it’s possible, I’ll send you the Dropbox file request in private message.

> [@NiclasEriksson](#):
>
> Is there a “flag” that tells the service that it’s already runned once ?

Currently, the PS script is started with -noExit, so after contextualization is done, the whole service leaves in fake running state.

---

<div class="post-metadata">

**Author:** ![vholer](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/vholer/32/4392_2.png) [@vholer](https://forum.opennebula.io/u/vholer)\
**Post date:** [August 31, 2017, 5:55pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/15 "2017-08-31T17:55:41Z")

</div>

Two points:

1. The fact that you see WMI critical error and then another run without critical error is pretty normal on the very first run after sysprep. I can reproduce that as well, it doesn’t make any problem. Simply, the failing run is done during the Windows preparation phase.

2. But, you complain about no contextualization is done on run as a service. I found out that both environment variables in `${env:ProgramFiles}` and `${env:ProgramFiles(x86)}` used to detect the location of `vmtoolsd.exe` return same path `C:\Program Files (x86)`. That means, during the run as a service, VMware tools aren’t found in `C:\Program Files\VMware\VMware Tools\vmtoolsd.exe`. And that’s the problem. Also `${env:ProgramW6432}` needs to be checked.

I’ll prepare a fix tomorrow and provide MSI so you can validate a fix.

Thank you!

---

<div class="post-metadata">

**Author:** ![vholer](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/vholer/32/4392_2.png) [@vholer](https://forum.opennebula.io/u/vholer)\
**Post date:** [August 31, 2017, 5:59pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/16 "2017-08-31T17:59:22Z")

</div>

1. Reason why the .out file couldn’t be deleted is missing `Stop-Transcript` before exit. This is a bug, will be fixed.

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [August 31, 2017, 6:32pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/17 "2017-08-31T18:32:22Z")

</div>

Ok, sounds great. Thanks! Looking forward to try it out 🙂

---

<div class="post-metadata">

**Author:** ![vholer](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/vholer/32/4392_2.png) [@vholer](https://forum.opennebula.io/u/vholer)\
**Post date:** [September 1, 2017, 9:39am UTC](https://forum.opennebula.io/t/windows-server-context/4807/18 "2017-09-01T09:39:49Z")

</div>

This package should fix the problem with the service [one-context-5.4.0.4.msi](https://canada1.discourse-cdn.com/flex031/uploads/opennebula/original/2X/2/2f007e51e1ffafa3cf332636d6bbd60b30cf1d02.msi) (26 KB). I had some problem with upgrading the package, had to first uninstall the old one.

---

<div class="post-metadata">

**Author:** ![NiclasEriksson](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiclasEriksson](https://forum.opennebula.io/u/NiclasEriksson)\
**Post date:** [September 1, 2017, 2:32pm UTC](https://forum.opennebula.io/t/windows-server-context/4807/19 "2017-09-01T14:32:52Z")

</div>

Great, it works now! Thanks for input/fix.

---

<div class="post-metadata">

**Author:** ![shrekmaxi](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/shrekmaxi/32/5796_2.png) [@shrekmaxi](https://forum.opennebula.io/u/shrekmaxi)\
**Post date:** [October 26, 2018, 7:07am UTC](https://forum.opennebula.io/t/windows-server-context/4807/20 "2018-10-26T07:07:36Z")

</div>

My problem is:  
I did what you mentioned:(on Windows Server 2008R2)

net stop onecontext  
net start onecontext

and there is no such file `c:\.opennebula-context.out` in my vm. I checked the status of opennebula context service. it says it is on.

So any suggestions?
