Encoding VBScript via NoteTab20 Jul 2008
Because NoteTab is my favorite text editor and it can be ‘programmed’ using the inbuilt clipping language I thought I’d share some aspects around one of my NoteTab clipbooks used for working with VBS files; Microsoft’s Visual Basic scripting still gives me a quick and easy way to implement automations and NoteTab simply helps me do that even faster.
The first clip in the library (see below) simply allows you to quickly run a VBS file that is being edited. This may need editing if you have modified the default action on VBS files, but the “Run” option will simply try and execute the current file open in NoteTab. This could be modified to save the file first, but sometimes I don’t want to run it with the very last change I made … but it’s very easy to add in a save instruction.
H="Run" ^!Shell "^$GetDocName$" ^!Goto END
The next clips we’ll look at are ones that are used to store settings in an INI file. This will be useful for some additional clips I’ll run through in later posts, and one other clip in this one.
The “OnOpen” clip sets the INI file for the clib library to be “vbslib.ini” but can be set to whatever you like. The “Open Settings” clip simply opens this file in NoteTab so it can be edited.
H=";Configuration" H="Open Settings" ^!Open ^$GetIniFile$ H="_OnOpen" ^!SetIniFile vbslib.ini
The one setting we need in this file for now is for encrypting the VBS file, but first of all we need something to encrypt it with Microsoft’s Script Encoder. So the first thing to do is to download the script encoder.
When you download and run the program install the encoder somewhere appropriate. I would recommend (and the rest of the paths used in this post assume you do) directing it to the scripts folder for your installation of NoteTab and creating a new folder called VBS just to hold these sorts of utilities and another folder to hold just this. The path might therefore be something like:
Once installed we can then set the option in the INI file to find the script encoder executable:
The clip to encode the file I have as a single line, but in order to display it here and make it easier to follow I’ve split it up a little. The DOS command will automatically create the encoded file with the same name in the same folder as the original. The only difference in name will be the VBE extension rather than the VBS extension.
H="Encode" ^!Set %EncoderPath%=^$GetScriptPath$^$GetValue("X-VBS:Encoder")$ ^!Set %EncPath%=^$StrReplace(".vbs";".vbe";"^$GetDocName$";false;true)$ ^!Dos "^%EncoderPath" "^$GetDocName$" "^%EncPath%"
That’s it. This will keep prying eyes from your scripts. At least for a little while. In a later post I’ll run through how we can reverse this encryption … just in case you need to take someomne else’s encrypted script apart.