none
Incorporate a cmd command line into a VBscript RRS feed

  • Question

  • "%~dp0AutoInstallWarning.exe" "SalesForce Outlook connector" "Outlook and Lync need to be closed for Salesforce to update successfully. Outlook and Lync will close in 60 seconds. Click OK to close both applications now." 60

    2nd: After time runs out or the executalble finishes, it goes can calls the vbs:

     

    '===============================================================

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _   
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery _   
     ("SELECT * FROM Win32_Process WHERE Name = 'excel.exe'")
    For Each objProcess in colProcessList   
    objProcess.Terminate()

    Next

    '======================================================

     

    the problem is that a cmd window pops up and if its closed, it wont do the vbs.

     

    How can I combine the cmd into the vbs? so it won't show a cmd window?

     

    Thanks in advance for any input

    Friday, June 15, 2012 10:59 PM

Answers

  • HEllo

    first of all, thnx for using our tool.

    P.S. Version 2 is on its way, and actually has vbs scripts built in (and does not need to be installed on the system).

    Scr1ptWizardøs example look great.

    ýou shouild place the script where autoinstallwarning is installed, or copy the files from the installation path to the path of the script.

    Only "problem" i see, is that you cannot always count on the currentdirectory to be the one where the script is loaded.

    I always use Wscript.ScreiptFullName to get the location instead.

    like this (this is actually the script from version 2.0 portable version)::

    intTimeout = 30
    strTitle = "Coretech SCCM Manager Upgrade"
    strMessage = "Internal IT is upgrading Coretech SCCM Manager. Click OK to dismiss this message" 
    Dim objShell
    Set objShell = WScript.CreateObject("Wscript.Shell")
    strScriptLocation = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
    cmd = """"&  strScriptLocation & "AutoInstallWarning.exe"" """ & strTitle & """ """& strMessage & """ """& intTimeout 
    objShell.Run cmd


    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript

    • Marked as answer by Leo T Monday, June 18, 2012 2:50 PM
    Monday, June 18, 2012 8:35 AM
    Moderator

All replies

  • I don't think anyone can figure out what your question is.

    We have no idea what you are running and where you are getting this script or the messages.  Please try to be clear and provide useful information.


    ¯\_(ツ)_/¯

    Friday, June 15, 2012 11:02 PM
  • Sorry about that. I'll try to clear up what I'm trying to do:

    I'm trying to distribute a software via SCCM. The software requires to have some applications closed.

    AutoInstallWarning.exe will provide a custom message to the user that will allow them to close the required applications in order to continue with the isntallation.

    Currently AutoInstallWarning.exe and its switches can be launched in a cmd file, the only problem is that it shows a cmd box to the end user.

    the notification.cmd looks like this:

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

    "%~dp0AutoInstallWarning.exe" "SalesForce Outlook connector" "Outlook and Lync need to be closed for Salesforce to update successfully. Outlook and Lync will close in 60 seconds. Click OK to close both applications now." 60

    "closeoutlook.vbs"

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

    and then a vbs runs to close the required process.

    I was wondering if I can vbscript the "notification.cmd"

    note: if anyone wonders what is "auto install warning", pls take a quick look at this page: http://blog.coretech.dk/jgs/coretech-auto-install-warning-freeware/

    Thanks in Advance

    Monday, June 18, 2012 12:58 AM
  • I assume you wrote the .cmd script that launches the executable. What mechanism causes the batch script to run? If this is configurable, you might be able to get a vbscript to run instead, but you'd have to explicitly run wscript.exe and pass the name of the vbscript.

    I also assume that the executable does its notification by popping up windows dialogs. If it wrote to stdout, it would probably open its own cmd prompt-like window.

    As to what you would put in the vbscript so that it basically does what the .cmd script does, well, that kind of depends on what the .cmd script looks like. But anything you can do in batch can be done in vbscript...


    Al Dunbar

    Monday, June 18, 2012 2:15 AM
  • Add the following to the beginning of your .vbs file:

    Dim oShell, AppPath, cmd
    Set oShell = CreateObject("WScript.Shell")
    AppPath=replace(oShell.ExpandEnvironmentStrings(oShell.CurrentDirectory)+"\","\\","\")
    cmd = AppPath & "AutoInstallWarning.exe ""SalesForce Outlook connector"" ""Outlook and Lync need to be closed for Salesforce to update successfully. Outlook and Lync will close in 60 seconds. Click OK to close both applications now."" 60"
    oShell.Run "%COMSPEC% /c " & cmd, 0, True

    This assumes that the "AutoInstallWarning.exe" and supporting files are located in the same directory as the .vbs file.

    Monday, June 18, 2012 8:29 AM
  • HEllo

    first of all, thnx for using our tool.

    P.S. Version 2 is on its way, and actually has vbs scripts built in (and does not need to be installed on the system).

    Scr1ptWizardøs example look great.

    ýou shouild place the script where autoinstallwarning is installed, or copy the files from the installation path to the path of the script.

    Only "problem" i see, is that you cannot always count on the currentdirectory to be the one where the script is loaded.

    I always use Wscript.ScreiptFullName to get the location instead.

    like this (this is actually the script from version 2.0 portable version)::

    intTimeout = 30
    strTitle = "Coretech SCCM Manager Upgrade"
    strMessage = "Internal IT is upgrading Coretech SCCM Manager. Click OK to dismiss this message" 
    Dim objShell
    Set objShell = WScript.CreateObject("Wscript.Shell")
    strScriptLocation = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
    cmd = """"&  strScriptLocation & "AutoInstallWarning.exe"" """ & strTitle & """ """& strMessage & """ """& intTimeout 
    objShell.Run cmd


    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript

    • Marked as answer by Leo T Monday, June 18, 2012 2:50 PM
    Monday, June 18, 2012 8:35 AM
    Moderator
  • Thanks Scr1ptW1zard, but I could not get that to work with the executable (all is in the same folder)

    Jakob Svendsen: thanks for your reply, I was really happy when I found your tool.
    With the version 1.0.3.0 I just copy the executable, .config file and the image.jpg to the package and it works in all machines that is deployed. I haven't found a need to install it yet.

    I just copy your and it works.
    Final Script looks like this:

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

    '===================================================================================================
    'Launches the Notification
    intTimeout = 60
    strTitle = "SalesForce Outlook connector"
    strMessage = "Outlook and Lync need to be closed for Salesforce to update successfully. Outlook and Lync will close in 60

    seconds. Click OK to close both applications now"
    Dim objShell
    Set objShell = WScript.CreateObject("Wscript.Shell")
    strScriptLocation = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
    cmd = """"&  strScriptLocation & "AutoInstallWarning.exe"" """ & strTitle & """ """& strMessage & """ """& intTimeout
    objShell.Run cmd, 1, True

    '====================================================================================================
    'Close process prior app installation


    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _   
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery _   
     ("SELECT * FROM Win32_Process WHERE Name = 'excel.exe'")
    For Each objProcess in colProcessList   
    objProcess.Terminate()

    Next

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _   
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery _   
     ("SELECT * FROM Win32_Process WHERE Name = 'WINWORD.exe'")
    For Each objProcess in colProcessList   
    objProcess.Terminate()

    Next

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _   
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery _   
     ("SELECT * FROM Win32_Process WHERE Name = 'communicator.exe'")
    For Each objProcess in colProcessList   
    objProcess.Terminate()

    Next

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

    I'll be testing it on a test collection. Thanks everyone for your input.



    • Edited by Leo T Monday, June 18, 2012 5:01 PM
    Monday, June 18, 2012 2:50 PM
  • thnx for feedback :)

    sorry about missing the ", ,True" on the ObjShell.Run ;)


    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript Mastering System Center Orchestrator 2012 - 3 day workshop - worldwide traning click here

    Wednesday, June 20, 2012 10:17 AM
    Moderator