MDT Post OSD Batch File

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Adam LeinssServer SpecialistCommented:
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.
ResoneticsAuthor Commented:
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"
Adam LeinssServer SpecialistCommented:
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.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ResoneticsAuthor Commented:
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>
Adam LeinssServer SpecialistCommented:
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\

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TLeading EngineerCommented:

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?

ResoneticsAuthor Commented:
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.
Mike TLeading EngineerCommented:

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.

ResoneticsAuthor Commented:
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.
ResoneticsAuthor Commented:
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.
Adam LeinssServer SpecialistCommented:
Do you have a screenshot of the error?
ResoneticsAuthor Commented:
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.
Adam LeinssServer SpecialistCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.