Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping VBScript Organized

I maintain a good number of vbscripts for performing various startup scripts on my network and have a handful of functions that I use in almost all of them.

Short of copy and paste, does anyone have suggestions for how I can go about creating libraries of reusable vbscript code. I'm not averse to using a code generator for doing so as long as it isn't more of a headache than copy and paste is. But any recommendations would be appreciated.

Thanks

like image 965
Allain Lalonde Avatar asked Jul 13 '26 16:07

Allain Lalonde


1 Answers

VBScript has the Execute statement, so if you don't want to go the WSF route Tester101 proposes, you can do an include like this:

Set fso = CreateObject("Scripting.FileSystemObject")
file = "your_library.vbs"

Execute fso.OpenTextFile(file, 1).ReadAll

Set foo = New FooClass
MsgBox foo.GetBar()

Assuming "your_library.vbs" would contain a class definition for FooClass.

Be sure to call Execute in global context, or you will get into scoping issues.

Of course be sure to have all your files under tight control to prevent malicious usage.

like image 121
Tomalak Avatar answered Jul 21 '26 13:07

Tomalak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!