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
Thanks in Advance
0 Comments
[ + ] Show comments
Answers (9)
Please log in to answer
Posted by:
WiseUser
19 years ago
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.
If so, heres one way to do it...
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
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
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
Posted by:
terranceallen
19 years ago
Posted by:
babric
19 years ago
Posted by:
craig16229
19 years ago
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 --<>.
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
Posted by:
craig16229
19 years ago
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 --<>.
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
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.
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.
so that the conversation will remain readable.