Return value from VBScript to cmd file


  1.    13 Nov 2008 #1
    BrianB Guest

    Return value from VBScript to cmd file


    I'm modifying a Windows command script that needs to use a value from the
    Win32_OperatingSystem class. How can I call a VBScript from inside the cmd
    script and return a value to the cmd script?

    Brian Bygland


      My System SpecsSystem Spec

  2.    13 Nov 2008 #2
    Pegasus \(MVP\) Guest

    Re: Return value from VBScript to cmd file



    "BrianB" <brian@xxxxxx> wrote in message
    news:%23w0kMEVRJHA.4916@xxxxxx

    > I'm modifying a Windows command script that needs to use a value from the
    > Win32_OperatingSystem class. How can I call a VBScript from inside the cmd
    > script and return a value to the cmd script?
    >
    > Brian Bygland
    Your command script (=batch file) could look like so
    @echo off
    {Your code}
    cscript //nologo c:\Scripts\YourScript.vbs
    echo Return code = %ErrorLevel%
    {More of your own code}

    Your VB Script could terminate like so:
    wscript.quite 9


      My System SpecsSystem Spec

  3.    13 Nov 2008 #3
    Tom Lavedas Guest

    Re: Return value from VBScript to cmd file


    On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:

    > "BrianB" <br...@xxxxxx> wrote in message
    >
    > news:%23w0kMEVRJHA.4916@xxxxxx
    >

    > > I'm modifying a Windows command script that needs to use a value from the
    > > Win32_OperatingSystem class. How can I call a VBScript from inside the cmd
    > > script and return a value to the cmd script?
    >

    > > Brian Bygland
    >
    > Your command script (=batch file) could look like so
    > @echo off
    > {Your code}
    > cscript //nologo c:\Scripts\YourScript.vbs
    > echo Return code = %ErrorLevel%
    > {More of your own code}
    >
    > Your VB Script could terminate like so:
    > wscript.quite 9
    Typo in the last line (one that I'm prone to also). It should
    read ...

    wscript.quit 9

    While I'm here let me note that this approach can use a variable, as
    well, but that it can only return an integer between 0 and 255 to a
    batch procedure. For example, ...

    nNumber = 2 + 2
    wscript.quit nNumber

    If the result is/can be larger than 255, is real or a string then try
    something like this instead ...

    in script:

    Result = 123.456 ' for exaple
    wscript.echo Result

    then in batch ...

    @echo off
    :: {Your code}
    for /f "delims=" %%a in ('cscript //nologo c:\Scripts
    \YourScript.vbs') do (
    set ScriptOut=%%a)
    echo Script Result = %ScriptOut%

    Tom Lavedas
    ***********
    http://there.is.no.more/tglbatch/
      My System SpecsSystem Spec

  4.    13 Nov 2008 #4
    Pegasus \(MVP\) Guest

    Re: Return value from VBScript to cmd file



    "Tom Lavedas" <tglbatch@xxxxxx> wrote in message
    news:dced8ce7-e6ed-42bb-8758-945639141cac@xxxxxx
    On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:

    > "BrianB" <br...@xxxxxx> wrote in message
    >
    > news:%23w0kMEVRJHA.4916@xxxxxx
    >

    > > I'm modifying a Windows command script that needs to use a value from
    > > the
    > > Win32_OperatingSystem class. How can I call a VBScript from inside the
    > > cmd
    > > script and return a value to the cmd script?
    >

    > > Brian Bygland
    >
    > Your command script (=batch file) could look like so
    > @echo off
    > {Your code}
    > cscript //nologo c:\Scripts\YourScript.vbs
    > echo Return code = %ErrorLevel%
    > {More of your own code}
    >
    > Your VB Script could terminate like so:
    > wscript.quite 9
    Typo in the last line (one that I'm prone to also). It should
    read ...

    wscript.quit 9

    ============

    "Quite" so!


      My System SpecsSystem Spec

  5.    13 Nov 2008 #5
    BrianB Guest

    Re: Return value from VBScript to cmd file


    Thank you all. Your suggestions will save my day

    Brian

    "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
    news:OH$tYtZRJHA.3516@xxxxxx

    >
    > "Tom Lavedas" <tglbatch@xxxxxx> wrote in message
    > news:dced8ce7-e6ed-42bb-8758-945639141cac@xxxxxx
    > On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:

    >> "BrianB" <br...@xxxxxx> wrote in message
    >>
    >> news:%23w0kMEVRJHA.4916@xxxxxx
    >>

    >> > I'm modifying a Windows command script that needs to use a value from
    >> > the
    >> > Win32_OperatingSystem class. How can I call a VBScript from inside the
    >> > cmd
    >> > script and return a value to the cmd script?
    >>

    >> > Brian Bygland
    >>
    >> Your command script (=batch file) could look like so
    >> @echo off
    >> {Your code}
    >> cscript //nologo c:\Scripts\YourScript.vbs
    >> echo Return code = %ErrorLevel%
    >> {More of your own code}
    >>
    >> Your VB Script could terminate like so:
    >> wscript.quite 9
    >
    > Typo in the last line (one that I'm prone to also). It should
    > read ...
    >
    > wscript.quit 9
    >
    > ============
    >
    > "Quite" so!
    >

      My System SpecsSystem Spec

  6.    13 Nov 2008 #6
    Jim de Graff Guest

    Re: Return value from VBScript to cmd file


    Have you considered setting an environment variable in your script to the
    value (string) that you want returned?

    "BrianB" <brian@xxxxxx> wrote in message
    news:uam%23wWbRJHA.3628@xxxxxx

    > Thank you all. Your suggestions will save my day
    >
    > Brian
    >
    > "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
    > news:OH$tYtZRJHA.3516@xxxxxx

    >>
    >> "Tom Lavedas" <tglbatch@xxxxxx> wrote in message
    >> news:dced8ce7-e6ed-42bb-8758-945639141cac@xxxxxx
    >> On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:

    >>> "BrianB" <br...@xxxxxx> wrote in message
    >>>
    >>> news:%23w0kMEVRJHA.4916@xxxxxx
    >>>
    >>> > I'm modifying a Windows command script that needs to use a value from
    >>> > the
    >>> > Win32_OperatingSystem class. How can I call a VBScript from inside the
    >>> > cmd
    >>> > script and return a value to the cmd script?
    >>>
    >>> > Brian Bygland
    >>>
    >>> Your command script (=batch file) could look like so
    >>> @echo off
    >>> {Your code}
    >>> cscript //nologo c:\Scripts\YourScript.vbs
    >>> echo Return code = %ErrorLevel%
    >>> {More of your own code}
    >>>
    >>> Your VB Script could terminate like so:
    >>> wscript.quite 9
    >>
    >> Typo in the last line (one that I'm prone to also). It should
    >> read ...
    >>
    >> wscript.quit 9
    >>
    >> ============
    >>
    >> "Quite" so!
    >>
    >
    >

      My System SpecsSystem Spec

  7.    13 Nov 2008 #7
    Pegasus \(MVP\) Guest

    Re: Return value from VBScript to cmd file



    "Jim de Graff" <rjdegraff@xxxxxx> wrote in message
    news:eIDF7lbRJHA.1448@xxxxxx

    > Have you considered setting an environment variable in your script to the
    > value (string) that you want returned?
    How exactly would you set an environmental variable in a script so that it
    is available to the calling program?


      My System SpecsSystem Spec

  8.    13 Nov 2008 #8
    BrianB Guest

    Re: Return value from VBScript to cmd file


    "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
    news:eJn2ZsbRJHA.4608@xxxxxx

    >
    > "Jim de Graff" <rjdegraff@xxxxxx> wrote in message
    > news:eIDF7lbRJHA.1448@xxxxxx

    >> Have you considered setting an environment variable in your script to the
    >> value (string) that you want returned?
    >
    > How exactly would you set an environmental variable in a script so that it
    > is available to the calling program?
    That would be a much more elegant solution if it is possible.

    Brian


      My System SpecsSystem Spec

  9.    13 Nov 2008 #9
    BrianB Guest

    Re: Return value from VBScript to cmd file


    >"Tom Lavedas" <tglbatch@xxxxxx> wrote in message

    >news:dced8ce7-e6ed-42bb-8758->945639141cac@xxxxxx
    >On Nov 13, 1:58 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:

    >> "BrianB" <br...@xxxxxx> wrote in message
    >>
    >> news:%23w0kMEVRJHA.4916@xxxxxx
    >>

    >> > I'm modifying a Windows command script that needs to use a value from
    >> > the
    >> > Win32_OperatingSystem class. How can I call a VBScript from inside the
    >> > cmd
    >> > script and return a value to the cmd script?
    >>

    >> > Brian Bygland
    <snip>

    >If the result is/can be larger than 255, is real or a string then try
    >something like this instead ...
    >
    >in script:
    >
    > Result = 123.456 ' for exaple
    > wscript.echo Result
    >
    >then in batch ...
    >
    > @echo off
    >:: {Your code}
    > for /f "delims=" %%a in ('cscript //nologo c:\Scripts
    >\YourScript.vbs') do (
    > set ScriptOut=%%a)
    > echo Script Result = %ScriptOut%
    >
    >Tom Lavedas
    Tom, One question. If the script returns multiple lines of output, your
    example only catches the last line. How do I get it to capture the entire
    output. I tried:

    Set ScriptOut=
    for /f "delims=" %%Z in ('cscript //nologo c:\cc_trigs\jvbsout.vbs') do (
    Set BVBTemp=%%Z
    Set ScriptOut=%ScriptOut%%BVBTemp%
    )
    echo Script output: %BVBTemp%

    But this still just saves the last line.

    Brian


      My System SpecsSystem Spec

  10.    13 Nov 2008 #10
    Tom Lavedas Guest

    Re: Return value from VBScript to cmd file


    On Nov 13, 1:42 pm, "BrianB" <br...@xxxxxx> wrote:

    > "Pegasus (MVP)" <I....@xxxxxx> wrote in message
    >
    > news:eJn2ZsbRJHA.4608@xxxxxx
    >

    > > "Jim de Graff" <rjdegr...@xxxxxx> wrote in message
    > >news:eIDF7lbRJHA.1448@xxxxxx

    > >> Have you considered setting an environment variable in your script to the
    > >> value (string) that you want returned?
    >

    > > How exactly would you set an environmental variable in a script so thatit
    > > is available to the calling program?
    >
    > That would be a much more elegant solution if it is possible.
    >
    > Brian
    Unfortunately, it's not possible - at least achieving it would ruin
    its 'elegance' because of the 'hacks' needed to make it happen.

    The reason it's not possible (within reason) is that a 'child' process
    gets a *temporary COPY* of the environment. A script can modify this
    COPY, but since it is temporary, it is NOT available to the calling
    process once the script ends. Access to the non-volatile version of
    the environment requires access to the Windows API, which cannot be
    done easily in script. A supporting application could be called, but
    all in all it seems much messier to me than the use of the FOR
    statement.

    Tom Lavedas
    ***********
    http://there.is.no.more/tglbatch/
      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
Return value from VBScript to cmd file

Similar Threads
Thread Forum
return the file search feature that was so easy to use in XP Pro
I'm trying to learn Vista after many successful years using XP - and the thought process behind this software just doesn't make sense. If BMW came...
Vista file management
Return the next line of in a text file after matching the previous
Hi all, Could you please help me, I have a text log file which i pattern match using Powershell to return a line, however the line i am...
PowerShell
Return Value From VBScript In .NET
I am using an MSScriptControl in vb.net to do an evaluation of a text string: tempAnswer = MyScriptControl.Eval(MyScriptString) But how can I...
.NET General
Return Powershell Error to VBscript
I am calling a powershell script from within a vbscript to mail-enable a user in exchange. Is there a way to send an error back to the vbscript if...
PowerShell
Return to placeholder file
Is it possible to remove a file, but instead of having it deleted on all computers, simply remove it locally and have a placeholder take its place?
Live Folder Share
File Deletion - Gone but Return!
A weird problem. Copied a DVD to a directory on C, gave everyone full rights, then tried to delete the files after working with them. 3 remained...
Vista General
return only certain lines from large text file
I am trying to put together a scipt that will only return certain lines based on content in that line to an output file. The file we have is one...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 12:26.
    .