Run VBScript or Batch file as a "Pre-Installation"


I am attempting to simply run a VBScript or batch file from the “Files” folder using the AppDeployToolkit. The “Files” folder also contains my installation files (MSI or EXE). I would like to call a VBScript or batch file within my toolkit be either using the cscript.exe or cmd.exe commands respectively. Unfortunately I am not having much luck accomplishing this. Any help would be greatly appreciated!


If it’s simple, why wouldn’t you use PowerShell. What’s the PSAPDT command you are using?

try something like this…

<code>#Run VBS
	Execute-Process -FilePath &quot;$env:systemroot\system32\cscript.exe&quot; -Arguments &quot;&lt;code&gt;&amp;quot;$dirFiles\DUMMY.vbs&lt;/code&gt;&quot;&quot; -WindowStyle Hidden</code>

Hi Brian,

This VBScript code is a prerequisite provided by Microsoft to install Internet Explorer 11. I am not a scripting expert which is why I have turned to the community for assistance. I do not know how to convert the script to PowerShell. I am hoping there is an easy way to “call” a vbs file and once complete continue on with the AppDeployToolkit.



Hi Daniel,

Thank you! I will give this a try and provide an update shortly. Your help is much appreciated!



Hi Daniel,

The PowerShell AppDeployToolkit will not run when adding the line of code you provided. I updated the code with the name of the vbs file for which I am running.


Hi again,

I have tried using something similar to call the VBScript file but still not working. Any ideas?

Execute-Process -Path “$envSystemRoot\System32\cscript.exe” -Parameters “$dirFiles\updatecheck.vbs”

$envSystemRoot is probably C:. I would use $envWINDIR.

Hi Brian,

I tried the following without any luck:

Execute-Process -FilePath “$envWinDir\System32\cscript.exe” -Parameters “$dirFiles\updatecheck.vbs”

I see a post with another user experiencing a similar issue which seems to have been resolved but it still doesn’t work for me. I keep getting “Installation Failed”. This is the only command running in my “Deploy-Application.ps1” script.

Check the log file under C:\Windows\Logs\Software

<![LOG[[Pre-Installation] :: Working Directory is [C:\WINDOWS\system32].]LOG]!><time=“15:19:26.638-300” date=“02-08-2016” component=“Execute-Process” context=“TH\p_jhamelin” type=“1” thread=“4164” file=“Deploy-Application.ps1”>
<![LOG[[Pre-Installation] :: Executing [C:\WINDOWS\system32\cscript.exe C:\Users\p_jhamelin\Desktop\CitrixReceiver 4.3\Files\SetConfig.vbs]…]LOG]!><time=“15:19:26.644-300” date=“02-08-2016” component=“Execute-Process” context=“TH\p_jhamelin” type=“1” thread=“4164” file=“Deploy-Application.ps1”>
<![LOG[[Pre-Installation] :: Execution failed with exit code [1].]LOG]!><time=“15:19:26.687-300” date=“02-08-2016” component=“Execute-Process” context=“TH\p_jhamelin” type=“3” thread=“4164” file=“Deploy-Application.ps1”>

Hi Brian,

It looks like it is attempting to execute but is failing:

[Pre-Installation] :: [cscript.exe] successfully resolved to fully qualified path [C:\WINDOWS\system32\cscript.exe]. Execute-Process 08/02/2016 7:18:15 PM 3856 (0x0F10)
[Pre-Installation] :: Working Directory is [C:\WINDOWS\system32]. Execute-Process 08/02/2016 7:18:15 PM 3856 (0x0F10)
[Pre-Installation] :: Executing [C:\WINDOWS\system32\cscript.exe C:\Users\jhamelin\Desktop\Internet Explorer 11\Files\updatecheck.vbs]… Execute-Process 08/02/2016 7:18:15 PM 3856 (0x0F10)
[Pre-Installation] :: Execution failed with exit code [1]. Execute-Process 08/02/2016 7:18:15 PM 3856 (0x0F10)
[Pre-Installation] :: Microsoft_InternetExplorer_11_EN_01 Installation completed with exit code [1]. Exit-Script 08/02/2016 7:18:15 PM 3856 (0x0F10)
[Pre-Installation] :: Display balloon tip notification with message [Installation failed.]. Show-BalloonTip 08/02/2016 7:18:15 PM 3856 (0x0F10)

All I can see from the log file is execution failed with exit code 1.

I believe there needs to be explicit quotes around the script path.try this:

Execute-Process -FilePath “$envWinDir\System32\cscript.exe” -Parameters “”"$dirFiles\updatecheck.vbs"""

Hi Aman,

It looks like I am getting closer. I can see that in the logs it does explicitly show the quotations around the path for the VBS file however installation is still failing.

[Installation] :: [C:\WINDOWS\System32\cscript.exe] is a valid fully qualified path, continue. Execute-Process 09/02/2016 8:50:18 AM 2032 (0x07F0)
[Installation] :: Working Directory is [C:\WINDOWS\System32]. Execute-Process 09/02/2016 8:50:19 AM 2032 (0x07F0)
[Installation] :: Executing [C:\WINDOWS\System32\cscript.exe ”C:\Users\jhamelin\Desktop\Internet Explorer 11\Files\updatecheck.vbs”]… Execute-Process 09/02/2016 8:50:19 AM 2032 (0x07F0)
[Installation] :: Execution failed with exit code [1]. Execute-Process 09/02/2016 8:50:19 AM 2032 (0x07F0)

Any ideas what might be causing this? I have seen some people use the -Arguments parameter instead of the -Parameters parameter. Both don’t seem to work for me.

Hi Justin,
Three things to consider.

  1. do not copy and paste the code out of here directly into your script. There may be odd characters hidden in what you copy. Type it out fresh in your deployment script.

  2. Look at the examples folder that comes with the toolkit. Look at the office2013 example. In there, you’ll see examples that call vbscripts. Search for .vbs in there to find a good example.

  3. The script you’re trying to execute may have issues itself. It may require access to HKCU which will not be available if run under the system context. It may simply have errors in it.

Hi Aman,

  1. I was copying the text directly from the site which does change the formatting in NotePad++.
  2. Using the Office2013 example provided the exact formatting that was required for calling the VBS file.
  3. When testing I was running the “Deploy-Application.exe” locally using an Administrator account and not SYSTEM.

You have been a great help and I highly appreciate your assistance pointing me in the right direction! I wish I took a look those examples to begin with.



Guys, I think the problem is that you are passing the $dirfiles variable to cscript.exe or cmd.exe. Those executables do not understand the $dirfiles variable, so they choke. $dirfiles is only known to the PSADT script. If it was “execute-process -path $dirfiles\blahblah.exe” it’s all good. But when you try to pass it as a parameter string to CMD or CSCRIPT, it has no clue. So what you might want to do is copy the file to a temp directory earlier on in the script, then call it from that temp directory. You also could try —> execute-process “cmd.exe” -parameters $dirfiles"\script.bat" But I do not know if that will work.

Whether CMD or CSCRIPT get $DirFiles or <the value of $DirFiles> depends on the quotes you use.

# single quote will not expand $DirFiles

# double quotes will expand $DirFiles

As for how should you type your command:

Execute-Process -FilePath "$envWinDir\System32\cscript.exe" -Parameters "`"$dirFiles\updatecheck.vbs`""

There is also a $envSystem32Directory variable so this will work too:

Execute-Process -FilePath "$envSystem32Directory\cscript.exe" -Parameters "`"$dirFiles\updatecheck.vbs`""

Pro Tip: use the </> button to post code to avoid getting those slanted quotes that break everything

good luck