MDT Post OSD Batch File

Posted on 2014-11-12
Last Modified: 2014-11-14
I am in the process of incorporating a token based activation script into the OS Deplyoment process.

Our image contains a provision to look for and run a file called "custom.bat" if present.  It provides us with an option to customize and install software after the OS is installed.

I am currently able to run the script to activate the OS, which works fine.

The deployment share contains a scripts folder, which is where I have added the Leaf Certificate and Digital License for Windows 7 Enterprise.

I have created a subfolder called "Office2010Activation" and placed all of the necessary files in it.

My question is how to properly call the batch file within it.  I tried to use relative paths and it cannot find the path specified.

The batch file to activate Office 2010 must be called with this syntax:  %windir%\SYSWOW64\cmd.exe /c
Question by:Resonetics
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
LVL 22

Expert Comment

by:Adam Leinss
ID: 40437359
Is this folder on the C: drive?  All you should have to do is add a custom action in the task sequence and just put the path to the batch file there.

Author Comment

ID: 40437378
The folder is part of the deployment share, and lives in the "Deploy\Scripts" folder.

Custom.bat lives in "Deploy/Scripts.

The office 2010 Activation script lives in "Deploy\Scripts\Office2010Activation"

The custom.bat file is the easiet way as it's already setup and doesn't require modifying the task sequence.

Is it possible to call the script by using the following:

"cscript.exe %SCRIPTROOT%\Office2010Activation\activate_Office2010.bat"
LVL 22

Expert Comment

by:Adam Leinss
ID: 40437403
I believe you can just use %SCRIPTROOT%\Office2010Activation\custom.bat.  Put the word "pause" in the batch file and you should see it running as part of the deployment.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 40438051
I tried this:

%windir%\SYSWOW64\cmd.exe /c %SCRIPTROOT%\Office2010Activation\activate_Office2010.bat  

And it found the path to the script and ran it.  However, the script doesn't see the digital license file and Leaf certificate located in "Deploy\Scripts\Office2010Activation"

The error is ospp.vbs:  cannot find <leaf certificate name>
LVL 22

Accepted Solution

Adam Leinss earned 500 total points
ID: 40438218
It's probably setting the working directory to the C: drive, you will probably have to modify the batch file as well to include the path %SCRIPTROOT%\Office2010Activation\
LVL 18

Expert Comment

by:Mike T
ID: 40439559

I have to chip in as a number of things are wrong here not least this: "cscript.exe %SCRIPTROOT%\Office2010Activation\activate_Office2010.bat". This is so wrong. Cscript.exe is a script engine. You use it to run vbscript files. You do not use it to run batch files ever.

Second thing: running batch files in a deployment is a bad idea. Why? Because you have no control and ConfigMgr will get no return code to know if it worked or not.

Third: Installing Office with a BAT file is not good either anyway.

The supported way is to either create an XML or a MSP:
The Office Customization Tool (OCT) is used to create a Setup customization file (.msp file). Setup applies this file when Office is installed on the computers.

It is also possible to use the Config.xml file to configure a silent installation of Office Professional Plus 2010. For more information about how to use Config.xml, see Configure a silent installation of Office 2010.


or this walkthrough for 2012:

This way avoids any issues with BAT files, paths etc.

As for *activation* the same applies. Do not use BAT files. There are two ways:
1) use KMS
2) use the internet

KMS way
Create an MSP file and configure it to use a KMS server and then make sure you have installed the Microsoft Office 2010 KMS Host License Pack
Downloaded it from
(as per Kent Agerlund)

Non-KMS way
Use the Office Customisation Tool and just add the property name "AUTO_ACTIVATE" with a value "1" to the "modify setup properties".

Either way, you do NOT need a script to activate Office.

For ConfigMgr please avoid BAT files. Yes, you have it already written and it works, but it works outside of ConfigMgr which behaves (does it's thing) in different way to normal. BAT files quickly get messy and you can spend more time troubleshooting than if you just converted to VBS or PowerShell. If you don't know those, then learn them. Which would you rather do - learn more skills or sit scratching your head wondering why ConfigMgr is not obeying your BAT file?


Author Comment

ID: 40440110
Mike...I believe you either misunderstand what I am trying to do, or don't know what token based activation is.  These are CLOSED area computers that do not connect to the internet, ever.

The scripts were provided by Microsoft, and I worked with them during the process.

We are not installing Office with  a .bat file, but we are ACTIVATING it with a .bat file.
LVL 18

Expert Comment

by:Mike T
ID: 40440501

It is the latter - I confess I don't know what token based activation is, however, having said that I have found BAT files to be a major pain in the you-know-what.

I know you're also not installing Office, but I was covering all the bases as it just sounded like you are not using an XML or an MSP. That was a guess on my part. Apologies if I put 2 and 2 together and got 43. I have just looked and yes activation is allowed by a third way: token and it's only available on bended knee to Microsoft so I've learnt something :).

With regards the BAT file, can you post the actual contents? It's hard to troubleshoot a blind script. I do know that adding paths to the path field generally doesn't do what you think so again best avoided.


Author Closing Comment

ID: 40440940
Your tip allowed me to figure out the remainder of the script.  It is now working as expected.

I would post the script, but it contains sensitive information.

Author Comment

ID: 40442440
Well....I thought I was home free.

The last line of the Office Activation Script failed.

cscript.exe %officehome%\ospp.vbs /tokact:9956B2EB8E96CBF2B64456C170033630FFC15097

The %OFFICEHOME% variable is defined based on architecture earlier in the script.  Everything works perfect if run manually.
LVL 22

Expert Comment

by:Adam Leinss
ID: 40442449
Do you have a screenshot of the error?

Author Comment

ID: 40442614
I figured it out.  It was the way I was calling the Activate_Office2010.bat script.

I had been using:

%windir%\SYSWOW64\cmd.exe /c %SCRIPTROOT%\Office2010Activation\activate_Office2010.bat

I dropped the first part completely
So it'sjust %SCRIPTROOT%\Office2010Activation\activate_Office2010.bat

And that works.

Thanks again.
LVL 22

Expert Comment

by:Adam Leinss
ID: 40442714
Ah...I'm guessing %SCRIPTROOT% is defined in the first command environment, but when you start cmd a 2nd time you get another set of environmental variables.  You could test this theory by using the commands set and pause.  SET should show you the variables defined and pause allows you to see the command output before closing.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Update Services 1 105
SSAS,SSIS scaleout 3 58
Altiris v7.5 and Microsoft Hyper-V Software Patching 2 89
No More local names in the certificate starting November 2015 4 134
Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question