Launching an Application
有很多原因使你要从一个桌面程序启动设备上的一个应用程序。在下面情况下,你可以使用这个技术:
·                     安装一个新版本的应用程序。简单地拷贝CAB文件到设备上,然后在设备上运行CAB安装程序来提供安装。这项技术被经常用在你想自动发布和安装应用程序更新的情况下。
注意 另一个相似的发法是自动话桌面端的安装过程,使用ActiveSync内置的功能。
·                     在安装了新版本应用程序后重起你的移动应用程序。
·                     开始一个设备应用程序处理新更新的数据,在更新了文本或者XML文件后。
RAPI示例程序如图4。
Figure 4. The Launch Application tab of the RAPI demo program
OpenNETCF.Desktop.Communication命名空间RAPI类提供CreateProcess方法来启动一个设备文件。你希望启动的设备应用程序作为该方法的第一个参数。你可以传递一个命令行给应用程序,作为第二个参数。
btnLaunchPerform按钮的点击事件演示了CreateProcess方法。
[VC#.NET]
private void btnLaunchPerform_Click(object sender, System.EventArgs e)
{
            
// Perform the launch.
  try
  {
    if (txtLaunchFile.Text == "")
    {
      MessageBox.Show("You must provide a file to launch.",
        "No File Provided");
    }
    else    {      myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text);      MessageBox.Show("Your file has been launched.", "Launch Success");    }  }    // Handle any errors that might occur.  catch (Exception ex)  {    MessageBox.Show("The following error occurred while launching the 
file -" +      ex.Message, "Launch Error");  }      }[VB.NET]Private Sub btnLaunchPerform_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnLaunchPerform.Click ' Perform the launch.  Try    If (txtLaunchFile.Text = "") ThenMessageBox.Show("You must provide a file to launch.", _        "No File Provided");    }    else         "No File Provided");    }    else    {      myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text);      MessageBox.Show("Your file has been launched.", "Launch Success");    }  }    // Handle any errors that might occur.  catch (Exception ex)  {    MessageBox.Show("The following error occurred while launching the 
file -" +      ex.Message, "Launch Error");  }      }[VB.NET]Private Sub btnLaunchPerform_Click(ByVal sender As System.Object, ByVal 
e As System.EventArgs) Handles btnLaunchPerform.Click ' Perform the launch.  Try    If (txtLaunchFile.Text = "") Then      MessageBox.Show("You must provide a file to launch.", _        "No File Provided")      Exit Sub    End If     myrapi.CreateProcess(txtLaunchFile.Text, txtLaunchCommand.Text)     MessageBox.Show("Your file has been launched.", "Launch Success") ' Handle any errors that might occur.  Catch ex As Exception    MessageBox.Show("The following error occurred while launching the file
 -" & ex.Message, _      "Launch Error")  End Try End Sub接下来我们将进入最后一个RAPI有关的主题:获得系统信息。在下面的部分你将看到,RAPI类提供了一些方法用来得到连接设备的详细信息。Retrieving System Information得到指定的设备系统信息使你的程序能够在下面几个方面交付内容或改变功能:·                     连接设备上使用的处理器,当应用程序上传一个包含指定处理器的文件的CAB文件到设备上时。注意 这项技术最常用的环境是当你发布应用程序到早期版本的Pocket PC设备上,例如基于ARM处理器的Windows Mobile设备。·                     运行在连接设备上的操作系统版本,根据处理器类型使用相应文件进行更新。·                     连接设备的电源状态,经常用于在使用者进入区域前,警告他们的设备运行于低电量状态下。·                     连接设备的内存状态,用于检测数据是否可以下载,如果用户下载了未被授权的应用程序或者其他内存相关函数,或者判断你是否有足够的空间安装应用程序的更新。这部分操作的演示界面见图5。Figure 5. The Device Information tab of the RAPI demo programRAPI类提供了四个方法来得到这些信息,GetDeviceSystemInfo (处理器类型), GetDeviceVersion (操作系统版本), GetDeviceSystemPowerStatus (电源状态) 和 GetDeviceMemoryStatus (内存).BtnInfoRetrieve按钮的点击事件示范了这些方法。[VC#.NET]private void btnInfoRetrieve_Click(object sender, System.EventArgs e){  string info;  MEMORYSTATUS ms;  SYSTEM_INFO si;  SYSTEM_POWER_STATUS_EX sps;  OSVERSIONINFO vi; // Retrieve the system information.  myrapi.Ge