« Previous Next »

Thread: parameter substitution in vbscript

Last post 10-02-2009 3:28 AM by pilmart. 1 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (2 items)

Sort Posts:

  • 10-01-2009, 7:03 AM

    • pilmart
    • Not Ranked
    • Joined on 07-06-2009, 11:48 AM
    • Posts 4

    parameter substitution in vbscript

    Hi there my query is this, when using logparser at the command-line it's possible to pass DOS variables into template files so that those output variables are 'copied in' to the final output file.

    For instance if I set server=server1, I create a variable called server with the value server1 Then in my template file I reference it as %server%.

    So when the template file is rendered the value "server1" is substituted Now what I would like to know is can this be replicated when calling logparser using VBScript and if so how ???

    Many Thanks

  • 10-02-2009, 3:28 AM In reply to

    • pilmart
    • Not Ranked
    • Joined on 07-06-2009, 11:48 AM
    • Posts 4

    Re: parameter substitution in vbscript

    This might have been obvious to all you established logparser users but maybe I'm just stupid, anyway I fathomed it out so if anyone's remotely interested this is what you do.

    Within your vbscript you will have to write a small function to enable the setting of environment variables, you will do this by using the windows shell, and environment as follows:

     Dim objShell
     Dim objEnv

     Set objShell = WScript.CreateObject("WScript.Shell")
     Set objEnv = objShell.Environment("Process")
     
     objEnv(key) = val
     
     Set objShell = Nothing
     Set objEnv = Nothing

    Now you can just reference the environment variable(s) in your template(s) as normal, hope this helps someone out.

    Oh btw to unset the variable you would set up the shell & environment as per the function abaove and call objEnv.Remove(key) instead

Page 1 of 1 (2 items)
Microsoft Communities