Script to call file from dynamic path

Home Forums Scripting General Scripting Script to call file from dynamic path

This topic contains 1 reply, has 2 voices, and was last updated by Rems Rems 12 years, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • CaTBuS

    Rems has been helping me behind the scene and I wanted to post his work as I think it might help others. Also, this will allow others to chime in with additional ideas.

    My question. How does one create a script to call a file (exe or msi) from a dynamic path. For example, I will be pushing out an application via sms. The sms package will consist of a folder containing 1 script and 1 msi. The problem is that the location of the package may differ therefore a static path such as (c:windowssms) will not suffice as the folder may exist in random locations.

    Rems provide the below information. I have not yet tested it. I will report back later today with my results.

    Rems says: this example below and the links might get you started;


    strPath = Wscript.ScriptFullName
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objFile = objFSO.GetFile(strPath)

    strFolder = objFSO.GetParentFolderName(objFile) & “”
    strExeFile = “file.exe /parameters”

    strCommand = chr(34) & strFolder & strExeFile & chr(34)

    Set objShell = CreateObject(“Wscript.Shell”)
    objShell.Run “%comspec% /c ” & strCommand, 1, False

    Please feel free to add comments or alternate suggestions.
    I want to thank Rems again for coming through with a solution. I am actually learning a lot from this help. Hopefully I will be able to return the favor at some point. Cheers.


    Re: Script to call file from dynamic path

    By copying the quote, the links are not correct any more:

    Install MSI-files by Command-Line

    A quick way to determine the script Path

    strScriptFullName = WScript.ScriptFullName
    strScriptName = WScript.ScriptName

    sLength = InStrRev(strScriptFullName,strScriptName) -2
    ‘ -=OR=-
    sLength = Len(strScriptFullName)-Len(strScriptName) -1
    ‘ -=OR=-
    sLength = InStrRev(strScriptFullName,””) -1

    scriptPath = Left(strScriptFullName, sLength )
    wscript.echo “Path of the script file: ” , scriptPath


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.