14 Replies Latest reply on Apr 14, 2016 9:30 AM by cwinning

    Pushing and launching a batch script file

    saltwater Rookie

      I've got a batch script that I deploy using "Custom Action" from the deployment template. I can see the batch file being copied over  via Operations Monitor and have confirmed that the batch file is on the target machine's "C:\Windows\ProPatches\Installation\InstallationSandbox#2015-11-25-T-18-26-40" folder.. But, for some reason the batch file is not launching.

       

      On my custom action deployment template, I have, "Push File". I pushes the batch script to the target machine. Does it matter if the file is with a *.cmd or *.bat extension? The second custom action, in "Step 3: Before and Patches" and on Step 4: call %PATHTOFIXES%test-script.bat.

       

      What am I missing? I've tried following online document "Deployment Template: Custom Actions Tab" but still not working.

       

      TIA

        • 1. Re: Pushing and launching a batch script file
          cwinning CommunityTeam

          Hello,

           

          What version of Protect are you running?

           

          Thanks,

          Charles

          • 2. Re: Pushing and launching a batch script file
            saltwater Rookie

            Hi Charles, I'm using version 9.2.0 Build 4988.

            • 3. Re: Pushing and launching a batch script file
              cwinning CommunityTeam

              Hello,

               

              Custom Actions work with .bat and cmd files and your syntax looks good.  What happens when you run the test-script.bat by hand?  Does it run?  If it does, you should also attempt to run it as the System account since all of our deployments run as that account.

               

              To Run a Command Prompt as Local system use the following steps:

              1. Download Psexec.exe

              2. Open a new CMD Window.

              3. Change directories to the one holding psexec.exe

              4. run the command:

                psexec.exe -i -s cmd.exe

              5. A new command prompt will pop up and this is CMD.exe running as Local System.

              6. Attempt to run the same batch job to verify it runs using the System account.

               

              Thanks,

              Charles

              • 4. Re: Pushing and launching a batch script file
                saltwater Rookie

                Yes, the script works by manually launching the script file with run the command as admin and with command using the psexec.exe -i -s cmd.exe. Any other I can try?

                • 5. Re: Pushing and launching a batch script file
                  cwinning CommunityTeam

                  Hello,

                   

                  I can't think of anything off the top of my head, running it with the psexec.exe -i -s cmd.exe is a key test.  You could take a look in the C:\Windows\ProPatches\Logs for any obvious errors.


                  One other thought, try running it under the 32bit CMD to see if it fails, I believe all jobs run under the 32bit CMD in Protect 9.2.


                  To Run a Command Prompt as Local system use the following steps:

                  1. Download Psexec.exe

                  2. Open a new CMD Window from C:\Windows\SysWOW64

                  3. Change directories to the one holding psexec.exe

                  4. Run the command:  psexec.exe -i -s cmd.exe

                  5. A new command prompt will pop up and this is CMD.exe running as Local System.

                  6. Attempt to run the same batch job to verify it runs using the System account.


                  I might be able to give you more information if I knew what the .bat  was trying to do.  That may require a case with support if the .bat contains sensitive information.


                  Thanks,

                  Charles



                  • 6. Re: Pushing and launching a batch script file
                    saltwater Rookie

                    do you know if there are any other documentations besides the F1 on the custom action tab in version 9.2? Or, this video instructions, How To: Perform a Custom Action Complete Tutorial with Custom Actions, this one, I believe, is for 9.1 or older.

                    • 7. Re: Pushing and launching a batch script file
                      cwinning CommunityTeam

                      Hello,

                       

                      Configuration-wire, Custom Actions in Protect 9.2 are 99% exactly like Custom Actions in Protect 9.1/9.0.  The only changes were to the %pathtofixes% pathing which have been updated in the Help Files. 

                       

                      Protect 9.2: %PATHTOFIXES%test-script.bat

                      Protect 9.1/9.0: %PATHTOFIXES%Install\test-script.bat

                       

                      Was the test with the 32bit CMD successful?

                      Was this Custom Action something that was working in previous versions and not working in Protect 9.2?

                       

                      It's possible what you are attempting to do from the batch file isn't compatible with the Custom Action feature.

                       

                      Thanks,

                      Charles

                      • 8. Re: Pushing and launching a batch script file
                        saltwater Rookie

                        Yeah, that what I figured when hitting F1 on the custom action about the "%PATHTOFIXES%" syntax. No luck on running the script on 32bit.

                         

                        Here's a question, can i use this syntax in querying a service and stopping it with the script?

                        SC QUERY | FIND "SERVICE_NAME: Some_Service"

                        IF %ERRORLEVEL% EQU 0 NET STOP "Some_Service"

                         

                        This syntax works manually but, it looks like its not working when scheduled by Shavlik propatch.

                         

                        Also, can I execute a "msiexec /i "application"" with silent mode syntax? Again, this works on my batch script when launching manually on the target machine.

                        • 9. Re: Pushing and launching a batch script file
                          cwinning CommunityTeam

                          Hello,

                           

                          "No luck on running the script on 32bit"  Speaking with a developer, we now exclusively use the 32bit version of the CMD.exe for Custom Actions now. (this change was made to correct many issues we have seen over the years with Custom Actions)


                          Try this on the #4 step in the Custom Action configuration:

                           

                          Edit, correct command:

                          if /i %PROCESSOR_ARCHITECTURE% EQU AMD64 ("%pathtofixes%yourbatchfile.bat") else (if defined PROCESSOR_ARCHITEW6432 (%SystemRoot%\sysnative\cmd.exe /C "%pathtofixes%yourbatchfile.bat") else ("%pathtofixes%yourbatchfile.bat"))


                          Be sure to change the yourbatchfile.bat to the correct batch file name. This should, in theory elevate to the 64bit CMD.exe when the Custom Action is initiated.


                          Thanks,

                          Charles

                          • 10. Re: Pushing and launching a batch script file
                            saltwater Rookie

                            Sorry for taking a while to test this and getting back. Thank you for checking with the developer - if /i %PROCESSOR_ARCHITECTURE% EQU AMD64 ("%pathtofixes%yourbatchfile.bat") else (if defined PROCESSOR_ARCHITEW6432 (%SystemRoot%\sysnative\cmd.exe /C "%pathtofixes%yourbatchfile.bat") else ("%pathtofixes%yourbatchfile.bat")) - This worked.

                             

                            Another question pop-up while testing the custom action. When I push I file, *.exe, "Step 4: Specify the file to push.", my assumption that it would get to be pushed to "C:\Windows\ProPatches\Patches" folder and let my script look in that directory. I was wrong. It got pushed to "C:\Windows\ProPatches\Installation\InstallationSandbox#2016-04-12-T-13-37-54". How do I specify that the push file gets pushed to "C:\Windows\ProPatches\Patches" folder? Is this even possible? If not, Is there a way to configure my script to look for "C:\Windows\ProPatches\Installation\InstallationSandbox#2016-04-12-T-13-37-54" - assuming that "InstallationSandbox#2016-04-12-T-13-37-54" name is ever changing on the date and time variable?

                             

                            Thanks

                            • 11. Re: Pushing and launching a batch script file
                              cwinning CommunityTeam

                              Hello,

                               

                              If you are using a batch file, you would use %pathtofixes%filename.exe to point to the file.  Otherwise the path is code generated for each deployment so pointing to a specific path is impossible.

                               

                              Charles

                              • 12. Re: Pushing and launching a batch script file
                                saltwater Rookie

                                So, what you're saying is, for example, on the batch script, I would use:

                                 

                                copy %pathtofixes%FileExec.exe to "C:\FolderName\FileExec.exe"?

                                • 13. Re: Pushing and launching a batch script file
                                  saltwater Rookie

                                  My syntax is incorrect. I meant:

                                  copy %pathtofixes%FileExec.exe "C:\FolderName\FileExec.exe"

                                  • 14. Re: Pushing and launching a batch script file
                                    cwinning CommunityTeam

                                    Hello,

                                     

                                    Need to add the /Y and need to add more quotes like this:

                                     

                                    copy ""%pathtofixes%FileExec.exe" C:\FolderName\FileExec.exe" /Y

                                     

                                    Thanks,

                                    Charles

                                    1 of 1 people found this helpful