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:
- Wceload receives a .cab or .cpf file through one of the delivery mechanisms. While ActiveSync can send multiple .cab or .cpf files in one batch, each file is processed in turn.
- If the file is signed, Wceload attempts to verify the included certificate against certificates placed in the SPC Store.
- If the .cab file is unsigned, the security role to be used for the installation is determined by the SECPOLICY_UNSIGNEDCABS and SECPOLICY_UNSIGNEDPROMPT security policies.
- After the certificate verification process occurs, Wceload opens the .cab file for allowed installations and extracts the included _setup.xml file, which is passed to the Configuration Manager for processing.
For information about creating cab files, see CAB Wizard.
wceload.exe [ /delete <number> | /noui ] [ /confignotify | /nodelete | /safe | /silent | /verifyconfig] <cab file location>
- /confignotify
-
Generates a configuration result notification that is placed in the Text Message store on the device.
- /nodelete
-
Specifies that the .cab file is not removed after installation.
Note: If you do not specify /nodelete or /delete 0 when running Wceload, the .cab file is deleted even if the installation is not successful.
- /delete <number>
-
Specifies how Wceload removes the cab file after installation.
Note: If you do not specify /nodelete or /delete 0 when running Wceload, the .cab file is deleted even if the installation is not successful. Value Description 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.
- /noui
-
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.
- /safe
-
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.
- /silent
-
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.
- /verifyconfig
-
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.
- cab file location
-
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.
wceload /nodelete /silent "/Temp/MyCabFile.cab"