Creating a VBScript file Within a VSAE Project

1 minute read

Not sure if this issue has been blogged before. Yesterday, while I was working on a management pack project, I noticed that if I created a new VBScript file within VSAE (In Visual Studio), the script will not run when I test it in command prompt.

To replicate this issue again, I firstly created a brand new VBScript file inside the project:

image

Then added one line to the script and saved it:

image

Now, when tried to run it via the command prompt, I got a error saying there’s an invalid character at position (1,1) – which is the beginning of the script:

image

This error normally means the encoding for the .vbs file is not set as ANSI, which is exactly the problem in this case. When I opened the VBScript using NotePad++, looks like the script is encoded in UTF-8

image

To fix this issue, I simply changed the encoding to ANSI and saved the VBScript

image

Now it runs perfectly:

image

However, once the VBScript gets updated and saved again within Visual Studio, the encoding will revert back to UTF-8.

I don’t think this issue impacts the finishing piece of the management pack, but will impact developers when testing the script while still writing the MP. The alternative is to create the blank file outside of the Visual Studio and import it in by adding an existing item. I noticed if the file was initially created outside of Visual Studio and later got updated in Visual Studio, the encoding remains as ANSI.

Because of this reason, from now on, I’ll always create the VBScript file outside of Visual Studio when using VSAE.

Leave a comment