Thanks for the reply Baldy. This is exactly what I thought and did a small test. I have a simple ASP .NET web application with one label, one class library project which has an overrides method Install (creates a batch file and executes it), wand a WebSetup project which actually installs and during installation it will execute the Install method from class library project. Here's the code -
1) ClassLibrary Project - MyCustomAction
<RunInstaller(True)> _
Public Class SetupAction
Inherits Installer
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
Try
My.Computer.FileSystem.WriteAllText("E:\SetupTest.txt", Environment.NewLine + "File created from MyCustomAction project", True)
'Shell("SQLCMD -S Dev1 -d Prac -i ""E:\Copy of CreateTable1.sql""", AppWinStyle.MinimizedFocus, True, 5000)
File.WriteAllText("E:\Test.bat", "SQLCMD -S Dev1 -d Prac -i ""E:\CreateTable1.sql""")
Process.Start("E:\Test.bat")
Catch ex As Exception
My.Computer.FileSystem.WriteAllText("E:\ErrorLog.txt", Environment.NewLine + "Exception: " + ex.Message, True)
Finally
End Try
End Sub
End Class
2) ASP .NET Project - MyApplication
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Current Time: " + Now.ToString
End Sub
End Class
3) WebSetup Project - MyApplicationSetup
- I have added the project output from the above projects to it
- I have added a new "Tnstall" CustomAction referencing it to the output of MyCustomAction class library project
- When I build the msi installer and install the Web Setup application it intalls (copies the output files), and also creates SetupTest.txt, Test.bat files but it neither executes the Shell command line statement nor Process.Start() successfully.
- Once the bat file is created, if I manually double click it does execute the sql Script file.
As a side note, if I run CustomAction code in a separate Windows App, it executes perfectly fine. So, looks like while installation, its not able to execute the command line commands (though I do see cmd.exe / SQLCMD.exe in the task manager). I am not sure if this would be a permission issue, but I am in the admin group and have necessary permissions.
It may not be appropriate to write these comments in "My Answer" section, but wanted to give a detailed explanation of the situation. I am really stuck with this and would be very helpful if anyone can throw pointers on improving / alternate methods. Thanks in advance and really appreciate the help.