After upgrading the OS Machine Tools, kmssetup.cmd runs twice at startup

After upgrading the OS Machine Tools, kmssetup.cmd runs twice at startup

book

Article ID: CTX238316

calendar_today

Updated On:

Description

When you create a Gold VM to import as your first OS Layer version, you need to install the OS Machine Tools, to install our startup scripts and get them set to run as startup scripts.  Later, you add a version to your OS layer and want to upgrade the scripts to the ones from the latest version.  So you correctly download and run the OS Machine Tools self-extractor.  It unpacks and overwrites your scripts, but you then notice that our startup script, kmssetup.cmd, is running twice at the same time on a published machine.

You can see this in C:\Windows\Setup\Scripts\kmsdir\kmssetup.log, where you might see a pair like this when editing an app or platform layer:

Tue 09/18/2018- 9:58:28.04-kmssetup.cmd:OSLayerEdit Not Found in Registry 
Tue 09/18/2018- 9:58:28.04-kmssetup.cmd:OSLayerEdit Not Found in Registry 


Or you might see this in a published image:

Mon 09/17/2018-10:55:17.87-kmssetup.cmd:BootVolumeIsAnImage [0x1] Found in Registry 
Mon 09/17/2018-10:55:17.87-kmssetup.cmd:BootVolumeIsAnImage [0x1] Found in Registry 
Mon 09/17/2018-10:55:18.02-kmssetup.cmd:Adding old process complete flag files because this is a fresh install
Mon 09/17/2018-10:55:18.02-kmssetup.cmd:Adding old process complete flag files because this is a fresh install
Mon 09/17/2018-10:55:18.06-kmssetup.cmd:------------Configure Powershell-----------
Mon 09/17/2018-10:55:18.09-kmssetup.cmd:------------Configure Powershell-----------


There is no immediate danger to running kmssetup.cmd twice in parallel, since it contains interlock mechanisms to make sure some important functions don't run twice.  But it still makes troubleshooting unnecessarily difficult.

Resolution

You will need to manually delete the second instance of kmssetup.cmd as a startup script from the registry.  Unfortunately, if you look at gpedit.msc, Computer Configuration, Windows Configuration, Scripts, Startup, you will still only see one instance of kmssetup.cmd.  But in the registry, there are clearly two copies of it.  The right place to fix this is the OS layer, where the original damage was done.


Add Version to your OS Layer.  When it comes up, run RegEdit, and browse down to this key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Startup\0]

Under the "0" key, there should normally be exactly one additional "0" key, which contains this:

"Script"="C:\Windows\Setup\Scripts\kmsdir\kmssetup.cmd"

When you have hit this issue, you will see an additional key named "1" which also contains a reference to kmssetup,cmd.  Delete the entire "1" key.  If your situation doesn't exactly match, you will need to look through the  various keys under Group Policy\Startup\Scripts to understand where the original and the duplicated kmssetup.cmd references are, and delete all but one of them.

Then reboot, check kmssetup.log and verify that you only see a single instance of "Edit of and OS Layer [0x1] Found in Registry", and finalize.  You do not need to fix any additional layers.  Edit your Image Template to include the new OS version and republish.