none
VBScript to run commands RRS feed

  • Question

  • Hello ,

    I am using third application called Streamserve , there is one customized command of Streamserve which can be run from command prompt in following way ,

    ----------------------------------------------------------------------------------------------------------------------

    C:\Users\Mukund Sawant\Desktop\VBScript>C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.\bin\ss_scm.exe -user Administrator -pass XYZ -cert "C:\ManagementGateway\CERT.crt" -servicename app1 -action stop

    Above command can be run manually from command successfully . I want to run this command from vbscript and for that I have used the following lines of code ,

    ----------------------------------------------------------------------------------------------------------------------

    command = "C:\\Program Files\\OpenText\\StreamServe\\Platform\\Core\\1.5.2\\bin\\ss_scm.exe -user " + userid + " -pass " + passwd + " -cert " + cert + " -servicename " + strs_svc + " -action stop"        
        set WshShell = CreateObject("wscript.shell")
        'set ReturnCode =
     WshShell.Run command , 0, true

    I also tried below scenario which doesn't generate any error but it doesn't fire the command in background ,

    WScript.Echo "Application "  & er & " will be stopped "
    command = "cmd /c C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\ss_scm.exe -user " + userid + " -pass " + passwd + " -cert " + cert + " -servicename " + strs_svc + " -action stop"        
        set WshShell = CreateObject("wscript.shell")
        'set ReturnCode =
     WshShell.Run command , 0, true

    I would like to know the way of running any third party application's  command in non-interactive way form cmd and it should also generate a log.

    Thank you in advance.

    Regards,

    Mukund

    Thursday, March 12, 2015 3:31 PM

Answers

  • As I noted, any command-line argument that contains spaces needs to be quoted.


    command = "cmd /c ""C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\ss_scm.exe"" -user " & userid & " -pass " & passwd & " -cert """ & cert & """ -servicename " & strs_svc & " -action stop > logfile.log"

    Take note of the part I underlined in the above.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by musawant Saturday, March 14, 2015 6:00 PM
    Thursday, March 12, 2015 3:59 PM
    Moderator
  • Finally my code works after adding /c parameter instead of /k ,

    command= "cmd /c ss_scm.exe -user " & userid & " -pass " & passwd & " -cert """ & cert & """ -servicename " & strs_svc & " -action stop > logfile.txt"

    Thanks,

    Mukund

    • Marked as answer by musawant Saturday, March 14, 2015 5:59 PM
    Saturday, March 14, 2015 5:59 PM

All replies

  • You have too many syntax errors. Try it this way:


    command = "cmd /c ""C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\ss_scm.exe"" -user " & userid & " -pass " & passwd & " -cert " & cert & " -servicename " & strs_svc & " -action stop > logfile.log"
    Set WshShell = CreateObject("WScript.Shell")
    ReturnCode = WshShell.Run(command, 0, True)
    

    Any command-line parameters that contain spaces need to be quoted for cmd.exe.

    VBscript uses "" inside a string to mean a single ".

    You are correct that you have to run the command using cmd.exe, because output redirection (> at end of line) is a cmd.exe feature.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by musawant Saturday, March 14, 2015 5:59 PM
    • Unmarked as answer by musawant Saturday, March 14, 2015 6:00 PM
    Thursday, March 12, 2015 3:41 PM
    Moderator
  • Hi Bill ,

    Thanks for the help.

    I modified the script but now I am getting different kind of error ,

    Unknown argument: Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\security\certificatestore\trusted\authorities\demo.crt

    I have CERT variable which contains

    CERT     = "C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\security\certificatestore\trusted\authorities\demo.crt"

    Does it due to space in " Program files " string ?

    Regards,

    Mukund


    • Edited by musawant Thursday, March 12, 2015 3:51 PM
    Thursday, March 12, 2015 3:51 PM
  • As I noted, any command-line argument that contains spaces needs to be quoted.


    command = "cmd /c ""C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\ss_scm.exe"" -user " & userid & " -pass " & passwd & " -cert """ & cert & """ -servicename " & strs_svc & " -action stop > logfile.log"

    Take note of the part I underlined in the above.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by musawant Saturday, March 14, 2015 6:00 PM
    Thursday, March 12, 2015 3:59 PM
    Moderator
  • Hi ,

    Now , Log file doesn't show anything , it's of 0 kb and command has not been fired.

    Below is the modified command ,

    sub Stopapp(user ,pass,cert,strs_svc)
    WScript.Echo "Application "  & er & " will be stopped "
    command = "cmd /c ""C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\ss_scm.exe"" -user " & userid & " -pass " & passwd & " -cert """ & cert & """ -servicename " & strs_svc & " -action stop > logfile.log"
        set WshShell = CreateObject("wscript.shell")
        'set ReturnCode =
        ReturnCode = WshShell.Run(command, 0, True)

    Regards,

    Mukund


    • Edited by musawant Thursday, March 12, 2015 4:09 PM
    Thursday, March 12, 2015 4:05 PM
  • The command line looks correct syntax-wise, but I can't comment on specifics because I don't have ss_scm.exe.

    You can debug by placing the following command:


    WScript.Echo Command
    

    This will show the actual command line being passed to the Run method.

    If it does not work, you will need to ask for assistance using the ss_scm.exe program.

    This is not a support forum for that program.


    -- Bill Stewart [Bill_Stewart]

    Thursday, March 12, 2015 4:16 PM
    Moderator
  • Hi Bill , I could run the commands with your help but now script gets stuck after execution ,

    it automatically doesn't stop. Manual running of script automatically terminates itself

    from command prompt.

    For example,

    ---------------------------------------------------------- For j=LBound(arrTestArray) to UBound(arrTestArray) er=arrTestArray(j) Stopapp USERID,PASSWD,CERT,er Next Sub Stopapp(user ,pass,cert,strs_svc) WScript.Echo "Application " & er & " will be stopped " 'command= "cmd /c ""C:\Program Files\OpenText\StreamServe\Platform\Core\1.5.2\bin\ss_scm.exe"" -user " & userid & " -pass " & passwd & " -cert """ & cert & """ -servicename " & strs_svc & " -action stop > logfile.log" command= "cmd /K ss_scm.exe -user " & userid & " -pass " & passwd & " -cert """ & cert & """ -servicename " & strs_svc & " -action stop" set WshShell = CreateObject("WScript.shell") Wscript.echo command 'set ReturnCode = ReturnCode = WshShell.Run command, 0, true Wscript.echo "Command executed" end sub

    Below is the output of above command and I also want to log the standard output/error of the script output,


    C:\Users\sawanmuk\Desktop>Cscript Debug_script2.vbs
    Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation. All rights reserved.

    Value  of i is0
    Value  of i is1
    Value  of i is2
    Application Testphase1 will be stopped
    cmd /K ss_scm.exe -user Administrator -pass XYZ -cert "C:\Program Files\Op
    enText\StreamServe\Platform\Core\1.5.2\bin\security\certificatestore\trusted\aut
    horities\demo.crt" -servicename Testphase1 -action stop

    Thanks.

    Regards,

    Mukund


    • Edited by musawant Friday, March 13, 2015 9:57 AM
    Friday, March 13, 2015 9:56 AM
  • The purpose of your array and loop is not clear to me, nor why you are using a global variable in your Sub procedure.

    It would help if you would explain what you want to do, rather than how you think you need to do it.


    -- Bill Stewart [Bill_Stewart]

    Friday, March 13, 2015 1:46 PM
    Moderator
  • I want to write a script which can stop the applications which are mentioned in text file , so I have read the text file line by line and then stored the read lines from text file  in array .

    After that  I have read the array values one by one with the help of loop and called the sub to pass the read values from array to stop the applications .This is an idea.

    Regards,

    Mukund

    Saturday, March 14, 2015 4:08 PM
  • If you insist on using VBScript, then I would start with a VBScript tutorial.

    I would suggest starting with the VBScript Primer section in the Windows 2000 Scripting Guide.

    Guessing and asking incremental questions in a forum is a very inefficient way to learn how to write VBScript code.


    -- Bill Stewart [Bill_Stewart]

    Saturday, March 14, 2015 4:25 PM
    Moderator
  • Finally my code works after adding /c parameter instead of /k ,

    command= "cmd /c ss_scm.exe -user " & userid & " -pass " & passwd & " -cert """ & cert & """ -servicename " & strs_svc & " -action stop > logfile.txt"

    Thanks,

    Mukund

    • Marked as answer by musawant Saturday, March 14, 2015 5:59 PM
    Saturday, March 14, 2015 5:59 PM