windows - Wix: Install MSMQ component -


i have .net project has 2 components communicate on msmq. i'm building installer using wix because microsoft has inexplicably ceased support installers in visual studio 2012. i'm quite happy process of creating instance of msmq in wix installer, , i'm quite happy process of detecting whether msmq installed on computer (by trying load mqrt.dll).

does know how use wix install msmq windows system component itself? there way wix instruct windows install system component?

it took long time, found elegant way this.

1) in visual studio create new wix c# custom action project

2) paste following on customaction.cs file:

using system; using system.collections.generic; using system.linq; using system.text; using microsoft.deployment.windowsinstaller; using system.runtime.interopservices; using system.diagnostics; using system.io;  namespace installmsmq {     public class customactions     {         [customaction]         public static actionresult customaction1(session session)         {             session.log("begin customaction1");              return actionresult.success;         }          [dllimport("kernel32")]         static extern intptr loadlibrary(string lpfilename);          [dllimport("kernel32.dll", setlasterror = true)]         static extern bool freelibrary(intptr hmodule);          [customaction]         public static actionresult installmsmq(session session)         {              actionresult result = actionresult.failure;             session.log("detecting msmq");             bool loaded;             createconfigfile();             createwindows8installerscript();              try             {                 intptr handle = loadlibrary("mqrt.dll");                 if (handle == intptr.zero || handle.toint32() == 0)                 {                     loaded = false;                 }                 else                 {                     loaded = true;                     session.log("msmq installed");                     result = actionresult.success;                     freelibrary(handle);                 }             }             catch             {                 loaded = false;             }              if (!loaded)             {                 session.log("installing msmq");                 try                 {                      version win8version = new version(6, 2, 9200, 0);                      if (environment.osversion.platform == platformid.win32nt && environment.osversion.version >= win8version)//windows 8 or higher                     {                         // win8 or higher.                          session.log("windows 8 or server 2012 detected");                          using (process p = new process())                         {                             session.log("installing msmq server");                             processstartinfo containerstart = new processstartinfo("msmqwindows8.bat");                             containerstart.verb = "runas";                             p.startinfo = containerstart;                                                         bool success = p.start();                             p.waitforexit();                         }                     }                     else if (environment.osversion.version.major < 6) // windows xp or earlier                     {                         session.log("windows xp or earlier detected");                         string filename = system.io.path.combine(environment.getfolderpath(environment.specialfolder.system), "msmqanswer.ans");                         using (system.io.streamwriter writer = new system.io.streamwriter(filename))                         {                             writer.writeline("[version]");                             writer.writeline("signature = \"$windows nt$\"");                             writer.writeline();                             writer.writeline("[global]");                             writer.writeline("freshmode = custom");                             writer.writeline("maintenancemode = removeall");                             writer.writeline("upgrademode = upgradeonly");                             writer.writeline();                             writer.writeline("[components]");                             writer.writeline("msmq_core = on");                             writer.writeline("msmq_localstorage = on");                         }                          using (process p = new process())                         {                             session.log("installing msmq container");                             processstartinfo start = new processstartinfo("sysocmgr.exe", "/i:sysoc.inf /u:\"" + filename + "\"");                             p.startinfo = start;                             p.start();                             p.waitforexit();                         }                     }                     else if (environment.osversion.version.major < 8) // vista or later                     {                         session.log("windows vista or windows 7 detected");                         using (process p = new process())                         {                             session.log("installing msmq container");                             processstartinfo containerstart = new processstartinfo("ocsetup.exe", "msmq-container /unattendfile:msmq.xml");                             containerstart.verb = "runas";                             p.startinfo = containerstart;                             p.start();                             p.waitforexit();                         }                         using (process p = new process())                         {                             session.log("installing msmq server");                             processstartinfo serverstart = new processstartinfo("ocsetup.exe", "msmq-server /unattendfile:msmq.xml");                             serverstart.verb = "runas";                             p.startinfo = serverstart;                             p.start();                             p.waitforexit();                         }                     }                     session.log("installation of msmq completed succesfully");                     result = actionresult.success;                 }                 catch (exception ex)                 {                     session.log("installation of msmq failed due " + ex.message);                 }             }             return result;         }          private static void createwindows8installerscript()         {             streamwriter configfile = new streamwriter("msmqwindows8.bat");             configfile.writeline("%windir%\\sysnative\\dism.exe /online /enable-feature /all /featurename:msmq-server");             configfile.close();         }         private static void createconfigfile()         {             streamwriter configfile = new streamwriter("msmq.xml");             configfile.writeline("<?xml version=\"1.0\"?>");             configfile.writeline("");             configfile.writeline("<unattend>");             configfile.writeline("");             configfile.writeline("  <servicing>");             configfile.writeline("");             configfile.writeline("    <package action=\"configure\">");             configfile.writeline("");             configfile.writeline("<assemblyidentity name=\"microsoft-windows-foundation-package\" version=\"6.0.6000.16386\" language=\"neutral\" processorarchitecture=\"amd64\" publickeytoken=\"31bf3856ad364e35\" versionscope=\"nonsxs\"/>");             configfile.writeline("");             configfile.writeline("      <selection name=\"msmq-container\" state=\"true\"/>");             configfile.writeline("");             configfile.writeline("<selection name=\"msmq-server\" state=\"true\"/>");             configfile.writeline("");             configfile.writeline("<selection name=\"msmq-triggers\" state=\"true\"/>");             configfile.writeline("");             configfile.writeline("<selection name=\"msmq-dcomproxy\" state=\"true\"/>");             configfile.writeline("");             configfile.writeline("<selection name=\"msmq-multicast\" state=\"true\"/>");             configfile.writeline("");             configfile.writeline("<selection name=\"msmq-adintegration\" state=\"true\"/>");             configfile.writeline("");             configfile.writeline("<selection name=\"msmq-http\" state=\"true\"/>");             configfile.writeline("");             configfile.writeline("    </package>");             configfile.writeline("");             configfile.writeline("  </servicing>");             configfile.writeline("");             configfile.writeline("</unattend>");             configfile.close();         }     } } 

3) compile custom action

4) add following wix setup.wxs file:

<binary sourcefile="[path custom action project]\bin\[debug or release]\[custom action project name].ca.dll" id="[custom action project name]step" /> <customaction id="[custom action project name]customaction" binarykey="[custom action project name]step" dllentry="[custom action project name]" execute="deferred" impersonate="no"/> <installexecutesequence>   <custom action="[custom action project name]customaction" before="installfiles"/> </installexecutesequence>  

5) custom action can configured run @ 1 of number of points during installation process (detailed here: http://wixtoolset.org/documentation/manual/v3/xsd/wix/installexecutesequence.html). above example runs custom action before installing files detailed in .wxs file.

6) test - if goes should have setup file installs msmq part of installation sequence!


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -