/build/static/layout/Breadcrumb_cap_w.png

How do I create a custom action to call a batch file?

I have an .exe that calls a batch file. I want to create a custom action to call it what do I do?

Thanks in Advance

0 Comments   [ + ] Show comments

Answers (9)

Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
You want to call a batch file from an MSI CA?

If so, heres one way to do it...

Action:TestAction
Type:34
Source:SystemFolder
Target:cmd.exe /c "[#<cmdfilekey>]"

Replace "<cmdfilekey>" with the appropriate name of your batch file from the "File" column of the "File" table (case-sensitive).

Schedule the action just after "InstallFinalize" - it will run at the end of the installation.
Posted by: viv_bhatt1 19 years ago
Senior Purple Belt
0
Create a vbscript custom action :

Following is a code which I had used to run a bat file silently through a custom action :

Follwing are the main points in the script :
1) I am using a wrapper bat file which runs the main bat file and when the main bat file returns it creates a temp file (finished.txt) in INSTALLDIR to indicate it has finished the execution of bat file .
2) This custm action runs a vbscript which I am installing to the INSTALLDIR which takes argument to the wrapper.bat file
3) This script has a sleep function the script checks the existence of finished.txt in a while loop and goes into sleep , once the finished.txt is created it breaks the loop , assuming the main bat file has run and deletes the finished.txt file and quites the custom action .

You can strip this custom action according to your requirements .

Dim fso, arg1, arg2
Set wshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
sInstallDir = Session.Property("INSTALLDIR")

If Right(sInstallDir , 1) = "\" Then sInstallDir = Left(sInstallDir , Len(sInstallDir) - 1)

arg1=sInstallDir & "\wrapper.bat"
arg2=sInstallDir & "\finished.txt"

' Write the code to run the wrapper.bat
command = """c:\windows\system32\wscript.exe""" & " " & "" & sInstallDir & "\IS_Silent.vbs" & " " & arg1

scriptExec = wshShell.run(command ,1,true)

i = 0

while i = 0
if fso.fileexists(arg2) then
i = 1
else
sleep(2)
end if
wend


fso.Deletefile arg2 , True

set fso = nothing
set wshShell = Nothing

Function Sleep(sleepTime)

Dim Sec0, Sec1
Sec1= Second(Now)
Sec0 = Second(Now)

while (Sec0 >55)

Sec0 = Second(Now)

Wend

Sec1= Second(Now)
Sec0 = Second(Now)

While (Sec1 <> Sec0+sleepTime)

Sec1= Second(Now)

Wend

End Function


Hope this helps .

Cheers ,
V
Posted by: babric 19 years ago
Senior Purple Belt
0
Could you precise what you exactly want :

The bat file is installed with your product ?
The bat file is a setup file ?
Do you need a deferred ( :-) ) or an immediate CA ?
Posted by: terranceallen 19 years ago
Orange Belt
0
I need the CA to run after the app has been installed. The .exe is conditioned to execute the batch file from the C:\winnt\temp location.
Posted by: babric 19 years ago
Senior Purple Belt
0
I need the CA to run after the app has been installed. The .exe is conditioned to execute the batch file from the C:\winnt\temp location

Sorry, but I don't understand the importance of the .exe file. Do you need a CA to launch a BAT file or an EXE file ?
Posted by: craig16229 19 years ago
Third Degree Brown Belt
0
WiseUser -

I came across this thread while trying to decide the best way to append to the %System%\System32\drivers\etc\SERVICES file.

Shouldn't the CA run just before "InstallFinalize" and not after? This is the way I have always run my CA's for editing perms, and when I tried to place it after "InstallFinalize" for this append, I received error "2762". From my verbose logging:

Error 2762: Unable to schedule operation. The action must be scheduled between InstallInitialize and InstallFinalize.


Craig --<>.
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
What's in the "type" column of your "CustomAction" table?

Are you running it "immediately" or "deferred"?

Besides, you aren't installing the "services" file in your package (just editing it) - the timing of your action is therefore less important.
Posted by: craig16229 19 years ago
Third Degree Brown Belt
0
WiseUser,

Thanks for reply. I think you have far more experience with CA's than I, and that's why I asked the question.

I have always run my CA's "deferred", but I have not used them for much else beyond editing ACL's.

If the CA is just for an append, could it / should it be run immediately?


Craig --<>.
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
Hi Craig.

The scheduling of a custom action depends on a number of things.

In the case you described (editing the services file) there are few restrictions. Whether you run it "immediately" or "deferred" would depend on the security context of your MSI... If the user who launches the MSI has permissions to do what the custom action is doing you can run it where you like. If you're using group policy or the "AlwaysInstallElevated" policy, you should run the action deferred.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ