Announcement

Collapse
No announcement yet.

Post Patch questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Post Patch questions

    Hi all,

    I'm experimenting with the trial version of Visual Patch 3. One of the key things I need to do with my patch is run a .vbs script after the patch to open a port in Windows Firewall.

    Here is my attempt at a one line post patch script to call my VBS script (cfg_firewall.vbs):

    result = File.Run("%SystemRoot%\System32\cscript.exe", "//nologo cfg_firewall.vbs //GroupName:\"LaurelCreek\" //RuleName:\"PrecisionTileMulticast\" //ExePath:\"#PROGRAMFILESDIR#\\pt_pro.exe\" //Command:install", "", SW_SHOWNORMAL, true);


    What I'm not sure about is how the paths will work out. Does #PROGRAMFILESDIR# expand to the program directory for the program being patched on my user's machine?

    Can I reference my cfg_firewall.vbs on my PC even though it is not one of the files in the patch? I do not want this file installed on my user's computer but it would have to be included in the patch in order to run it post-install. Is it automatically bundled inside the patch?

    Will %SystemRoot% expand to the windows system root on my user's system?

    Thanks!
    Phil

    PS. Why is the project file so large? It's bigger than the patch it generates!pro_patch_2_0_4_to_2_0_12.vp2

  • #2
    Three errors I see initially:
    1. You must escape backslashes properly. See this in the Scripting Guide for details.
    2. %SystemRoot% already is the path to the "System32" folder - you shouldn't concatenate "\System32" again.
    3. You need to expand any Session Variable - File.Run() expects a valid path, so you need to code the script as
      Code:
      result = File.Run([highlight]SessionVar.Expand([/highlight]"%SystemRoot%[highlight]\\[/highlight]cscript.exe"[highlight])[/highlight], ...)
      See this old this FAQ post and read it entirely.

    (There may be additional issues in code you didn't show here - I didn't check the project - it is late and I'll have a look tomorrow.)

    Ulrich

    Comment


    • #3
      Hi Ulrich,

      I simplified things by using a batch file to run my vbs script and then I call the batch file from the Post script

      Code:
      result = File.Run("install_firewall.bat", SessionVar.Expand("#PROGRAMFILESDIR#\\pt_pro.exe"), "", SW_SHOWNORMAL, true);
      That seems to work except that the vbs script is not incuded in the patch so the batch file can't find it. Is there a way to add a dependency on a file?

      Thanks,
      Phil

      Comment


      • #4
        It appears as you didn't read the topic I asked you to. "#PROGRAMFILESDIR#" is a Design-time Constant, not a Session Variable. These constants have their contents replaced at build time, while the variables have contents only at runtime - big difference. There is usually no need to expand a constant.
        1. I checked your project, and couldn't find the code you showed in your post - the On Post Patch event script is empty.

        2. You asked why the project is so large - it is because your project has a lot of files. Perhaps you don't need to include every file you install in the project, unless they really all may need to be updated at some date.
          You could also use some folder references instead of listing each file in sub folders individually.

        3. You should use batch files only as the last resort. If the objective is to open the firewall so your application is allowed through, you can execute netsh with the proper arguments directly via Lua script.


          For Windows XP and older, use
          Code:
          netsh firewall set allowedprogram program="path-to-executable"
          and for Windows Vista and anything newer
          Code:
          netsh advfirewall firewall add rule program="path-to-executable" dir=in name="description" enable=yes action=allow
        4. If you want to include a companion file in your patch, add it to the Primer Files.


        Ulrich

        Comment


        • #5
          I'm trying your netsh suggestion but it appears that the backslashes in #PROGRAMFILESDIR# are not escaped so they get removed.

          Code:
          fw_cmd = 'advfirewall firewall add rule name=\"Precision Tile Pro\" dir=in action=allow program=\"#PROGRAMFILESDIR#\\pt_pro.exe\" description=\"Traffic allowed for all protocols on all ports when coming from my app\"';
          	result = Shell.Execute("netsh.exe", "open", fw_cmd, SessionVar.Expand("%SystemFolder%"), SW_HIDE, true);
          Any suggestions?

          Comment


          • #6
            I believe that "#PROGRAMFILESDIR#\pt_pro.exe" is not the path to your application, is it? Is it really installed in the root of the ProgramFiles folder on your computer? You shouldn't assume that the user has the application installed at the same location as on YOUR computer. He might as well have chosen a different folder name when he installed the application, used a different drive (or even a network location), so hard coding an executable's path is a terrible idea.

            Instead, you should use the Session Variable named %AppFolder% pointing to the folder where most likely the application was found when Visual Patch searched for it. If this is not the location, perhaps you retrieved the path in other ways, like searching the registry etc., but under no circumstance you should use a build constant. Build constants are fixed strings when the patch is run, while Session Variables hold the values which are appropriate for the target computer. Please check the links I provided for both in my previous message - you need to understand the difference between a constant and a variable.

            Ulrich
            Last edited by Ulrich; 10-30-2013, 08:56 PM.

            Comment


            • #7
              %AppFolder% sounds like the variable I need but will it have the same problem with the backslashes not being escaped?

              Comment


              • #8
                If you are having troubles with backslashes, these may be caused by a different problem. %AppFolder% is known to be set properly, unless you modified the provided scripts and introduced an error.

                Ulrich

                Comment

                Working...
                X