Jump to content

Create a logging function for a WSF?


Recommended Posts

Logging is a pretty big part of any script, and I'm trying to standardize this for a whole slew of WSF files run in an environment. I'm trying to move all of the logging functions out of the main script and into a .vbs or .js that I can then just <include> in the WSF itself, but creating something that persists like a log file in an include seems almost impossible. Anyone have any ideas? Logging of course is easy to do in the body of the main script (and does work fine), but I'm trying to move repetitive things out of the bodies of my main WSF files and into included JS or VBS files for two reasons - one, script re-use and standardization is nice, and two, it saves time if I can simply call a function to create a log file or write a line to an open file. Given the way includes work in WSF files, however, I'm not sure how feasible this is. I can create a log file without issue, but going back and simply writing to it has been the chore.

Soooo.... any ideas?

Link to comment
Share on other sites


That's always been a sore spot when it comes to the WSH. The include system is t3h suck (and the WSF format too, to some extent). You'd think they'd have worked on that a bit in the last few years. Code blocks from different includes just don't see each other so the only way to do it would be the whole open the file+write the text+close the file thing for every line you have to write, and that often means a lot of unnecessary round-trips across the network (slow). That pretty much forced me to do the logging "in-script" all the time. So my own code reuse/standardization strategy has been mostly using standard templates as a starting point for scripts (it's a time saver anyway).

The only real alternative I can think of the moment would be a custom COM component for logging but that sucks in other ways (like having to be installed/registered on every PC), or perhaps not using VBScript/JScript anymore (e.g. powershell).

Then again, there's nothing perfect...

  • batch files are the worst thing out there in just about every possible way I can think of (yuck) save for the utmost and absolute simplest jobs but it just won't go away
  • WSH isn't really being improved much... although the techs it uses like WMI are so it's still improving somehow
  • vbscript has the ugly (IMO) VB syntax and craptastic error handling, but it's within the reach of pretty much anyone
  • jscript has a better syntax (again, IMO) and decent error handling, but very few admin types are into that (being the only one writing jscript in a shop sucks)
  • powershell is great and groundbreaking in a lot ways, but some parts of it suck too, like for instance some formatting methods that truncate columns
  • using a "standard" programming language for scripting tasks gives you the most power and flexibility but it just takes way too long, it has to be compiled, sometimes security policies get in the way, etc so while this finally gives you the control you want, it just brings in a lot of unnecessary grief with it
  • other scripting languages (like for instance autoit, activeperl, etc) which need 3rd party components installed (licensed and deployed), where you can't necessarily rely on their support, that most admin types don't know, etc so it's often not the best idea

... I'm still waiting for the perfect solution but I'm definitely not holding my breath.

Sorry for being of no help at all.

Link to comment
Share on other sites

No worries, I ended up going with a COM module - it's not great, but it was pretty easy to do. I have to use WSF because the admins at the site who will be maintaining it are not high-level and this is about as much "code" as they can handle, so it must be easily template-able and easy to understand for folks coming from an all-W2K network (powershell is out - they just glazed over when I started to talk about it, so I knew WSF was the way to go with these guys).

The COM object is kinda nice though, as I can call it from any script, anywhere (including PS). If I get it to where it's not such a hack job, I'll throw it up in the code repository.

Link to comment
Share on other sites

No worries, I ended up going with a COM module - it's not great, but it was pretty easy to do

It seemed like the only real option indeed. And yeah, it's not really hard to do but it kinda sucks having to deploy it. Not that I currently have a use for it but the source would be great to have for sure.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...