我的经理询问有PDF文件的自动播放光盘,并检查用户pc上是否安装了adobe acrobat,如果它没有安装消息apear从cd安装此程序我有windows应用程序检查是否在pc上安装了adob阅读器或acrobat我做得很好,但我想知道如果此程序没有安装acrobat阅读器安装程序从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: ");
} 发布于 2011-02-21 17:30:39
需要调用installer进程。就像这样。
Process myProcess = new Process();
myProcess.StartInfo.FileName = "path to acrobat installer";
myProcess.Start();更好的方法是在您的应用程序设置中为此添加一个自定义操作。
发布于 2011-02-21 17:43:31
有几种方法可以检查这一点。
1/检查已安装的应用程序(win安装程序)
每个Windows installer项目(MSI)都有一个升级代码和一个产品代码。简单地说,产品代码定义了已安装应用程序的版本及其依赖关系。升级的代码在不同的版本上保持不变。您可以搜索acrobat阅读器的产品代码,并使用windows installer dll检查是否已安装。有一些关于代码项目(搜索MsiInterop)的代码,它将包含所有需要的dllimport。
2/保持简单。
为什么不直接检查是否存在与具有PDF扩展名的文件相关联的应用程序?
如果有关联的应用程序(可能是Acrobat Reader以外的应用程序,例如foxit),则假定一切正常。否则,启动指向http://get.adobe.com/reader/的浏览器
这样,您的应用程序就不会对用户选择的PDF阅读器负责。
发布于 2011-02-21 22:39:53
在C#中访问windows installer:
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。
https://stackoverflow.com/questions/5064026
复制相似问题