No announcement yet.

Script to call file from dynamic path

  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to call file from dynamic path

    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:\windows\sms) 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.

  • #2
    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
    Last edited by Rems; 26th October 2007, 10:56.

    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts