c# 4.0 - Need a way to get the version # used by the msi installer at run time in c#, without knowing the location of the msi file used to install -
i'm developing scheme automatically update program central point. assist me in need way version # of msi file used install progarm @ runtime, can compare installed version latest version on server (already solved part) , decide whether or not update. clear, have way of opening msi files using msi.dll , getting version # out. problem 1 of bootstrapping. if user installs program first time, how can program know find msi file (on client)?
the solution can simple msi creating text file version # in when runs. i'd avoid querying registry if can.
if can't figure out i'm going have take special care keep version #'s same in gui project , msi installer, , thought annoys me.
any thoughts?
i assume want productversion property of msi.
you can using com.
add com reference "microsoft windows installer object library" c# project.
then try following program:
namespace testcs { using system; using windowsinstaller; internal class test { private static void main(string[] args) { if (args.length < 1) { return; } console.writeline(getmsiversion(args[0])); } private static string getmsiversion(string installerpath) { type t = type.gettypefromprogid("windowsinstaller.installer"); installer inst = (installer)activator.createinstance(t); database d = inst.opendatabase( installerpath, msiopendatabasemode.msiopendatabasemodereadonly); view v = d.openview( "select * property property = 'productversion'"); v.execute(null); record r = v.fetch(); string result = r.get_stringdata(2); return result; } } }
Comments
Post a Comment