通过ap运行cab安装程序的方法及Sample Code
1. 第一部分:Sample Code
這部分轉自:http://blog.csdn.net/hhygcy/archive/2009/05/04/4147870.aspx
?
最近這個東西很多被問及,軟件動態升級的時候可能可以用到,在這里做一下記錄。
就知道的方法有2個, 一個是通過ShellExecuteEx直接運行對應的CAB文件。一個是調用CreateProcess用wceload來調用這個CAB。 兩個方法都可以,下面是寫的測試程序中的代碼:
view plaincopy to clipboardprint?
case ID_HELP_INSTALL1:??
??? {??
??????? // Specify an action for the application to perform, flags and other parameters???
??????? SHELLEXECUTEINFO info;??
??????? info.cbSize = sizeof(info);??
??????? info.fMask = SEE_MASK_FLAG_NO_UI;??
??????? info.hwnd = NULL;???
??????? info.lpVerb = _T("open");??
??????? info.lpFile = _T("//Program Files//RunCAB//SampleCAB1.CAB");??
??????? info.lpParameters = _T(""); info.lpDirectory = _T("");??
??????? info.nShow = SW_SHOW;??
??????? info.hInstApp = g_hInst;??
??????? // Call to perform an action??
??????? ShellExecuteEx(&info);??
??????? break;??
??? }??
case ID_HELP_INSTALL2:??
??? {?????
??????? LPTSTR szCmdline = _tcsdup(??
??????????? TEXT("/"//Program Files//RunCAB//SampleCAB2.CAB/""));??
??????? CreateProcess(_T("wceload.exe"),szCmdline,NULL,NULL,FALSE,INHERIT_CALLER_PRIORITY,NULL,NULL,NULL,NULL);??
??????? break;??
??? }?
????case ID_HELP_INSTALL1:
?????{
??????// Specify an action for the application to perform, flags and other parameters
??????SHELLEXECUTEINFO info;
??????info.cbSize = sizeof(info);
??????info.fMask = SEE_MASK_FLAG_NO_UI;
??????info.hwnd = NULL;
??????info.lpVerb = _T("open");
??????info.lpFile = _T("//Program Files//RunCAB//SampleCAB1.CAB");
??????info.lpParameters = _T(""); info.lpDirectory = _T("");
??????info.nShow = SW_SHOW;
??????info.hInstApp = g_hInst;
??????// Call to perform an action
??????ShellExecuteEx(&info);
??????break;
?????}
????case ID_HELP_INSTALL2:
?????{?
??????LPTSTR szCmdline = _tcsdup(
???????TEXT("/"//Program Files//RunCAB//SampleCAB2.CAB/""));
??????CreateProcess(_T("wceload.exe"),szCmdline,NULL,NULL,FALSE,INHERIT_CALLER_PRIORITY,NULL,NULL,NULL,NULL);
??????break;
?????}
這個測試程序用不同的menuitem做了不同的嘗試, 上述的兩個實現都是可以工作的。需要注意的事情是上面的CreateProcess需要把含有空格路徑參數用引號括起來。
2. 詳細的相關資料
http://msdn.microsoft.com/en-us/library/bb158700.aspx
The Wceload tool (Wceload.exe), which is an XML-based CAB installer application, runs on your target device. You typically use this tool to install a .cab or .cpf file to a location that you select on the target device. Most .cab files are configured to enable the user to select the destination volume where the .cab file will be installed, either /Device or /Storage Card. However, you can choose to suppress the destination volume selection prompt and install the .cab file to a default location, specified in the .inf file used to create the .cab file.
Typically, you do not directly call Wceload. Instead, Wceload is called programmatically by other programs to install .cab files. For example, if you use File Explorer to view and open a .cab file, Shell automatically invokes Wceload for installation of the .cab file.
For information about creating a .cab file, see CAB Files for Delivering Windows Mobile Applications.
Wceload implements security mechanisms and performs installation tasks for .cab and .cpf files on Windows Mobile powered devices.
Wceload installs .cab and .cpf files using the following process:
For information about creating cab files, see CAB Wizard.
?Syntax Copy Code wceload.exe [ /delete <number> | /noui ] [ /confignotify | /nodelete | /safe | /silent | /verifyconfig] <cab file location> ?Parameters /confignotify
Generates a configuration result notification that is placed in the Text Message store on the device.
Specifies that the .cab file is not removed after installation.
| If you do not specify /nodelete or /delete 0 when running Wceload, the .cab file is deleted even if the installation is not successful. |
Specifies how Wceload removes the cab file after installation.
| If you do not specify /nodelete or /delete 0 when running Wceload, the .cab file is deleted even if the installation is not successful. |
| 0 | Does not remove the .cab file after the contents are installed. |
| 1 | Removes the .cab file after the contents are installed. This is the default value. |
Specifies that the user will not be prompted for any input during the installation. By default, prompts are answered with 'Yes'.
However, if the .cab file is unsigned, any security-related prompts will default to 'No' for security reasons, and the installation might fail.
This is the same as /silent for legacy compatibility reasons.
Specifies that the .cab file cannot contain executable files. Also; if the .cab file is unsigned; it can only use restricted permissions, ensuring that it will not be able to write to protected files and registry keys.
Suppresses dialog boxes during the installation, and all Yes/No prompts default to 'Yes', unless the .cab file is not signed. However, if the .cab file is unsigned, any security-related prompts will default to 'No' for security reasons, and the installation might fail.
This is the same as /noui for legacy compatibility reasons.
Specifies that the Wceload tool must verify whether the file passed in is a .cpf file. If the file is not a .cpf file, the installation fails.
Specifies the location of the cab file to install or remove.
In Windows Mobile Version 5.0 and later, when using Wceload.exe to reinstall a .cab file, Wceload.exe uninstalls the previously installed version of the .cab file before installing the new version. During the uninstallation portion of this process, Wceload.exe closes any currently running executables that were installed on the target device using a .cab file, based on their filename. Wceload.exe also closes any executables that are the target of a file operation, such as a move or a copy. To close an executable, Wceload.exe sends WM_CLOSE to all top-level windows owned by the process. If the process does not exit in a timely manner after receiving the WM_CLOSE message, then Wceload.exe forcibly closes it by calling TerminateProcess. Wceload.exe does not attempt to close executables that are shipped in the run-time image on the target device.
If the .cab file is not signed, and you specify the /silent or /noui options when calling wceload, wceload may ignore these options.
The following code example shows how to call Wceload.exe to install a .cab file called MyCabFile.cab, while suppressing all dialog boxes during the installation. After installation, the .cab file is specifically not removed.
?Example wceload /nodelete /silent "/Temp/MyCabFile.cab"總結
以上是生活随笔為你收集整理的通过ap运行cab安装程序的方法及Sample Code的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VS2005与Device通过Activ
- 下一篇: 程序员们请别做下一个小贝