It contains lots on Business Intelligence scenarios and solutions along with real problems regarding Microsoft Excel, SQL Server Reporting Services, SQL Server Integration & Analysis Services and various databases and also may contain other popular posts.

Saturday, 19 April 2014

Run batch file during installation

I got new experience on my recent window based application. A requirement came to create windows task scheduler using batch file and also run that batch file along with installation of the application. Follow the below steps to perform same - 1. Create windows task scheduler using command prompt -As per requirement, to create a windows task scheduler which will repeat after every three days. Task scheduler through command prompt-

2. Copy and paste required command into notepad file and create abatch file and save it into desktop. (ie. TestScheduler.bat)

3. Include batch file into setup file of window based applicatoin/WPF setup.

Follow the below steps -

In the setup folder of windows application, right click and select view - [File system]

Go to application folder and add cmd.exe (C:\Windows\System32\cmd.exe) and also batch file which you have created above(TestScheduler.bat).

Once file is added to the application folder, again go back to application setup folder then right click and Go to view - [Custom actions]

Requirement was to Create windows task in scheduler during installation and remove windows task during application un-install. So for that we created two batch file for create and delete task respectively.

Replace /commit by /c "[TARGETDIR]\AutoExtraction.bat" in the argument section.

Rebuild the solution and create new setup and install the application, windows task should be created under windows task library. In the same manner if you uninstall application then same windows task should be removed from windows task library. To apply the same follow the below steps -

Step 1 - In the same custom action block add one more custom action under Uninstall - (Find the below screen shot for reference)

Step 2 - Go to application folder and add cmd.exe.

(Find the below screen shot for reference)

Step 3 - Right click on cmd.exe and select Property Window and make changes as per below screen shot -

where RemoveAutoExtraction.bat is the batch file which contains delete command of same task scheduler.

Conclusion: In this post i tried to explain how to create and delete a windows task scheduler using a batch file during install and uninstall of WPF application setup.

I hope this will help, Please feel free to post if there are more methods.