我的经理询问了自动播放CD有PDF文件并检查用户个人电脑上是否安装了adobe acrobat如果它安装了消息apear从cd安装此程序我有windows应用程序来检查adob reader或acrobat是否安装在PC上我做得很好但是我想如果这个程序没有安装acrobat reader安装程序apear从cd和用户安装这个程序。
public Form1()
{
RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe");
if (adobe != null)
{
RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader");
if (acroRead != null)
{
string[] acroReadVersions = acroRead.GetSubKeyNames();
MessageBox.Show("The following version(s) of Acrobat Reader are installed: ");
foreach (string versionNumber in acroReadVersions)
{
MessageBox.Show(versionNumber);
}
}
}
else
{
MessageBox.Show("The following version(s) of Acrobat Reader arenot installed: ");
}
答案 0 :(得分:0)
您需要调用安装程序进程。像这样的东西。
Process myProcess = new Process();
myProcess.StartInfo.FileName = "path to acrobat installer";
myProcess.Start();
更好的方法是在您的应用程序设置中添加自定义操作。
答案 1 :(得分:0)
有几种方法可以检查这一点。
1 /检查已安装的应用程序(win installer)
每个Windows安装程序项目(MSI)都有一个updgrade代码和一个产品代码。 简而言之,产品代码定义了已安装应用程序的版本及其依赖性。对于不同版本,updgrade代码保持不变。 您可以搜索acrobat reader的产品代码,并使用Windows安装程序DLL检查它是否已安装。 codeproject上有一些代码(搜索MsiInterop),它将包含所有必需的dllimports。
2 /保持简单。
为什么不检查是否存在与具有PDF扩展名的文件关联的应用程序? 如果有相关的应用程序(可能是Acrobat Reader以外的其他应用程序,例如foxit),则假设一切正常。 否则,启动指向http://get.adobe.com/reader/
的浏览器这样,您的应用程序就不会对用户选择的PDF阅读器承担责任。
答案 2 :(得分:0)
使用C#访问Windows安装程序:
public enum InstallState
{
NotUsed = -7,
BadConfig = -6,
Incomplete = -5,
SourceAbsent = -4,
MoreData = -3,
InvalidArg = -2,
Unknown = -1,
Broken = 0,
Advertised = 1,
Removed = 1,
Absent = 2,
Local = 3,
Source = 4,
Default = 5
}
[System.Runtime.InteropServices.DllImport("msi.dll", CharSet = CharSet.Unicode)]
internal static extern InstallState MsiQueryProductState(string szProduct);
如果您知道Adobe Acrobat的产品代码,则可以查询其安装状态:
bool acrobatInstalled = allAcrobatReaderProductCodes.Any(guid =>
{
var productCode = "{" + guid.ToString().ToUpper() + "}";
var msiState = MsiQueryProductState(productCode);
return msiState == InstallState.Local || msiState == InstallState.Default);
});
其中allAcrobatReaderCodes是所有acrobat reader产品代码的IEnumerable。