CAB file - run EXE file automatically during installation

Hi All,

I need your help.

I generated a CAB file which contains a project output of an EXE file. However, when I installed the CAB file, I need to run the EXE file seperately. This EXE file which I created suppose to be able to run in the background as "SMS listener".

Is there a way so that during CAB file installation, the EXE file would be run automatically during the installation, so that I do not need to run the EXE file manually?

Many thanks in advance.

Regards,

Matteoathen

[578 byte] By [matteoathen] at [2008-1-8]
# 1

You can do it from setup DLL in your CAB. That DLL has to be written in C++. There's an example of setup DLL in WM 5.0/6.0 SDK.

IlyaTumanov at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 2

Hi Ilya,

Thanks for your reply. If it is possible, could you give me the link of the sample setup DLL.

Many thanks in advance.

Regards,

Matteoathen

matteoathen at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 3

Hi Matteoathen,

matteoathen wrote:
Thanks for your reply. If it is possible, could you give me the link of the sample setup DLL.

The sample IIlya was mentioning is described in MSDN. The sample is called "Setup in a CAB" and can be found at http://msdn2.microsoft.com/en-us/library/ms880684.aspx. You will find a file called setup.cpp within this sample which contains a function called Install_Exit. With slight modification you could use this to launch your application (you wouldn't want to wait for it to exit before continuing the installation).

You may also like to take a look at my reply (http://www.christec.co.nz/blog/archives/61#comment-118) to your comment on my blog.

If your "SMS listener" process is using the MessageInterceptor class to intercept SMS messages, you may like to research the EnableApplicationLauncher method as an alternative approach. See the thread "Intercept SMS and start application" - http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1653331&SiteID=1 for further details.

One problem with starting a process during the setup process, is that you will also need to take care of re-starting it after a soft reset, or (if you're wanting a totally robust solution) after it potentially crashes due to an unforseen situation.

Hope this helps,

Christopher Fairbairn

ChristopherFairbairn at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 4

Sample is included with WM 5.0 SDK and located here:

%Program Files%\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Samples\CPP\Win32\Setupdll

IlyaTumanov at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 5

Hi Ilya,

Thanks for your reply

Regards,

Matteoathen

matteoathen at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 6

Hi Chist,

Thanks for your reply.

The sample code was helpful. However, how can I modify it such that I could able to run the application that I desired automatically during installation.

Many thanks in advance.

Regards,

Matteoathen

matteoathen at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 7

Hi,

matteoathen wrote:
The sample code was helpful. However, how can I modify it such that I could able to run the application that I desired automatically during installation.

I have uploaded a small sample project which hopefully will get you going. It can be downloaded from http://www.christec.co.nz/blog/wp-content/uploads/2007/08/runapplicationduringinstall.zip

The solution is based upon the code sample IIya mentioned, and contains three projects:

  • TestApplication - The compact framework application to run during the installation process
  • SetupDLL - The DLL (written in C++) which the CAB installation process will run during installation.
  • SetupDLLCab - The CAB file project which packages everything up as required.

This is a brief description of how it works:

  • During installation of the CAB file the device detects that the CAB file has a setup dll associated with it.
  • At various points within the installation process, the OS will call functions within the dll to allow it to perform any custom actions it needs to perform.
  • One of these points is after the OS has extracted all the files within the CAB file. In this sample this is the point at which we launch the TestApplication.exe executable.

If you would like to view the code which launches TestApplication.exe you should open the setup.cpp file within the SetupDLL project. In particular the following code within the Install_Exit() method:

Code Snippet

// We are provided with the installation folder the

// user has installed the application into. So prepend

// the name of the application we want to launch.

TCHAR szPath[MAX_PATH];

_tcscpy(szPath, pszInstallDir);

_tcscat(szPath, _T("\\"));

_tcscat(szPath, _T("TestApplication.exe"));

MessageBox(GetForegroundWindow(), szPath, L"status", MB_OK);

// Start the application, and don't wait for it to exit

if (!CreateProcess(szPath, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, &pi))

{

MessageBox(GetForegroundWindow(), szPath, L"failed", MB_OK);

cie = codeINSTALL_EXIT_UNINSTALL;

}

You will notice this code sample hardcodes the name of the executable to launch (TestApplication.exe). It does however cope with users deciding to install the application to an SD Card etc.

If you wanted to make a totally flexiable setup.dll you could look for the name of the executable to launch within a registry key your CAB file writes to etc.

Hope this helps,

Christopher Fairbairn

ChristopherFairbairn at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...
# 8

Hi Christ,

YES, your sample code is very helpful. Thanks a lot for the great help .

Regards,

Matteoathen

matteoathen at 2007-10-2 > top of Msdn Tech,Smart Device Development,Smart Devices VB and C# Projects...