trying to add line in vbs from bat

Discussion in 'Scripting' started by The_Guardian, Sep 24, 2012.

  1. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,054
    6,803
    90
    #1 The_Guardian, Sep 24, 2012
    Last edited: Sep 24, 2012
    I am trying to add this line in the bat file....
    >> "%systemdrive%\oops.vbs" echo objWSS.Run cRUN & Chr(34) & cWAV & Chr(34),0,True

    Update: Solution....>> "%systemdrive%\oops.vbs" echo objWSS.Run cRUN ^& Chr(34) ^& cWAV ^& Chr(34),0,True

    By the way....thanks Tito for trying for me but searchengine doesnt allow ppl to pm him so I dont know how to reach him unfortuantly.

    Glad my neighbor (John) is a geek. lol Thanks alot to him for his help on this. Here is solution that works...

    Set wmp = CreateObject("WMPlayer.OCX")
    wmp.settings.autoStart = True
    wmp.URL = "C:\oops.wav"

    while wmp.Playstate <> 1
    WSH.Sleep 100
    wend

    But I would like to now use %systemdrive% in place of C:\ but the script wont take it. Is there a way of making it take %systemdrive% instead of full path for I have OS on D:\ on one machine and C:\ on another. Would like it to be versatile so I dont have to make one for each computer. My neighbor doesnt know so I thought I would ask here. Thanks
     
  2. searchengine

    searchengine Guest

    #2 searchengine, Sep 25, 2012
    Last edited by a moderator: Apr 20, 2017
    not entirely sure what you are trying do, but .vbs cannot execute %systemdrive% directly, but the following edited example of above uses 'ExpandEnvironmentStrings()' to identify '%systemdrive%'

    RED = added or changed (also added 'volume = 50%')

    save as 'oops.vbs'
    Code:
    Set wshell = CreateObject("WScript.Shell")
    sysdrive = wshell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
    Set wmp = CreateObject("WMPlayer.OCX")
    wmp.settings.autoStart = True
    wmp.settings.volume = 50
    wmp.URL = (sysdrive + "\oops.wav")
    
    while wmp.Playstate <> 1
    WSH.Sleep 100
    wend
    BTW: if you want to write this 'oops.vbs' from .cmd file, the .cmd file would look like this...

    save as 'oops.cmd'
    Code:
    @echo off
    
    (echo Set wshell = CreateObject^("WScript.Shell"^)
    echo sysdrive = wshell.ExpandEnvironmentStrings^("%%SYSTEMDRIVE%%"^)
    echo Set wmp = CreateObject^("WMPlayer.OCX"^)
    echo wmp.settings.autoStart = True
    echo wmp.settings.volume = 50
    echo wmp.URL = ^(sysdrive + "\oops.wav"^)
    echo.
    echo while wmp.Playstate ^<^> 1
    echo WSH.Sleep 100
    echo wend) >%systemdrive%\oops.vbs
     
  3. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,054
    6,803
    90
    You are too freakin smart. lol Thanks alot searchengine, works great now. Your "The Man". :biggrin:
     
  4. quantahis

    quantahis MDL Novice

    Jul 26, 2012
    21
    2
    0
    #4 quantahis, Oct 15, 2012
    Last edited by a moderator: Apr 20, 2017
    Yes I agree with you.
     
  5. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    Line 1
    Char 1
    Error: Invalid character