vs自定义安装包的制作
vs自定義安裝包的制作
1 選中項(xiàng)目-右鍵- 視圖- 文件系統(tǒng),
然后選中左邊列表上的應(yīng)用程序文件夾-右鍵-添加-項(xiàng)目輸出-主輸出-確定
2? 選中項(xiàng)目-右鍵- 視圖-自定義操作,
然后選中主輸出來自clsInstall(活動(dòng))-右鍵-屬性
在CustomActionData欄 中填入:?????? /targetdir="[TARGETDIR]/"
3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;
using System.Diagnostics;
namespace clsInstall
{
??? [RunInstaller(true)]
??? public partial class YqsInstaller : Installer
??? {
??
??????? const String cntS_SoftCaption = "********軟件";
??????? public YqsInstaller()
??????? {
??????????? InitializeComponent();
??????????? //安裝之前
??????????? this.BeforeInstall += new InstallEventHandler(InstallerTest_BeforeInstall);
??????????? //安裝之后
??????????? this.AfterInstall += new InstallEventHandler(InstallerTest_AfterInstall);
??????????? //卸載之前
??????????? this.BeforeUninstall += new InstallEventHandler(InstallerTest_BeforeUninstall);
??????? }
?????????
??????? /// <summary>
??????? /// 卸載之前
??????? /// </summary>
??????? /// <param name="sender"></param>
??????? /// <param name="e"></param>
??????? void InstallerTest_BeforeUninstall(object sender, InstallEventArgs e)
???????????? {
???????????????? string strMsg = "the string variable is used storage error message";
???????????????? string strDir = "";
???????????????? string strCmd = "MySQLServer5.0//bin//mysqld.exe/" -remove mysql/"";
???????????????? strDir = this.Context.Parameters["targetdir"];
???????????????? //停止mysql服務(wù)
???????????????? if (!ExecCmd(strDir, "net stop mysql", ref strMsg))
???????????????????? MessageBox.Show(strMsg, cntS_SoftCaption);
???????
????????????????? //安裝Mysql服務(wù)
???????????????? if (!ExecCmd(strDir, "/"" + strDir + strCmd, ref strMsg))
???????????????????? MessageBox.Show(strMsg, cntS_SoftCaption);
?????????????????????????
???????????? }
??????? //安裝之前
??????? void InstallerTest_BeforeInstall(object sender, InstallEventArgs e)
??????? {
??????????? //???? MessageBox.Show("安裝之前" + this.Context.Parameters["targetdir"] );
??????????? string strMsg = "the string variable is used storage error message";
??????????? string strDir = "";
??????????? string strCmd = "YqsMySQLServer5.0//bin//mysqld.exe/" --install yqsmysql --defaults-file=/"my.ini/"";
??????????? strDir = this.Context.Parameters["targetdir"];
???????
??????????? //安裝Mysql服務(wù)
??????????? String strPath="";
??????????? strPath =? "/"" + strDir + strCmd ;
??????????? MessageBox.Show(strPath, "按");
??????????? if (!ExecCmd(strDir,strPath, ref strMsg))
??????????????? MessageBox.Show("安裝mysql" + strMsg, cntS_SoftCaption);
??????
??????????? //啟動(dòng)mysql服務(wù)
??????????? if (!ExecCmd(strDir, "net start yqsmysql", ref strMsg))
??????????????? MessageBox.Show(strMsg, cntS_SoftCaption);
??????????? /*
??????????? //添加快捷方式
?????????? //獲得桌面文件夾路徑
?????????? string strDestopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
?????????? IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();
?????????? IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.
?????????????????? CreateShortcut(@strDestopPath + "//搖錢樹網(wǎng)吧管理軟件.lnk");
?????????? //shortcut =(IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut();
?????????? shortcut.TargetPath =this.Context.Parameters["targetdir"] + "YQS.exe";
?????????? shortcut.Save();
??????????? */
??????? }
??????? /// <summary>
??????? /// 安裝之后
??????? /// </summary>
??????? /// <param name="sender"></param>
??????? /// <param name="e"></param>
??????? void InstallerTest_AfterInstall(object sender, InstallEventArgs e)
??????? {
??????????? //? MessageBox.Show("安裝之后");
??????????? string strDir = "";
??????????? strDir = this.Context.Parameters["targetdir"];
??????????? System.Diagnostics.ProcessStartInfo psiConfig = new System.Diagnostics.ProcessStartInfo(strDir + "qeroxz.exe");//path即是安裝的目錄
??????????? System.Diagnostics.Process pConfig = System.Diagnostics.Process.Start(psiConfig);
??????? }
??????? /// <summary>
??????? /// 執(zhí)行應(yīng)用程序
??????? /// </summary>
??????? /// <param name="workingDirectory">工作目錄</param>
??????? /// <param name="exePath">應(yīng)用程序路徑</param>
??????? /// <param name="strArg">參數(shù)</param>
??????? /// <param name="strErr"></param>
??????? /// <returns></returns>
??????? public static bool ExecExe(string workingDirectory, string exePath, string strArguments, ref string strErr)
??????? {
??????????? System.Diagnostics.Process p = new System.Diagnostics.Process();
??????????? p.StartInfo.FileName = exePath;
??????????? p.StartInfo.Arguments = strArguments;
??????????? p.StartInfo.UseShellExecute = false;
??????????? p.StartInfo.RedirectStandardError = true;
??????????? p.StartInfo.RedirectStandardOutput = true;
??????????? p.Start();
??????????? p.WaitForExit(); //組件無限期的等待關(guān)聯(lián)進(jìn)程退出
??????????? String strOut;
??????????? strOut = null;
??????????? strOut = p.StandardOutput.ReadToEnd();
??????????? strErr = p.StandardError.ReadToEnd();
??????????? if (0 != p.ExitCode)
??????????? {
??????????????? strErr = "ExitCode:" + p.ExitCode;
??????????????? return false;
??????????? }
??????????? if ((strOut.Length != 0) || (strErr.Length != 0))
??????????? {
??????????????? strErr = "";
??????????????? Console.WriteLine(strOut);
??????????????? return false;
??????????? }
??????????? else
??????????? {
??????????????? Console.WriteLine(strOut);
??????????????? return true;
??????????? }
??????? }
??????? /// <summary>
??????? /// 使用cmd執(zhí)行命令行程序
??????? /// </summary>
??????? /// <param name="workingDirectory">工作目錄</param>
??????? /// <param name="command">命令行</param>
??????? /// <returns>命令執(zhí)行錯(cuò)誤,返回false;命令執(zhí)行成功,返回true.命令行
??????? /// 的內(nèi)容輸入錯(cuò)誤會(huì)導(dǎo)致命令執(zhí)行失敗</returns>
??????? public static bool ExecCmd(string workingDirectory, string command, ref string strErr)
??????? {
??????????? System.Diagnostics.Process p = new System.Diagnostics.Process();
??????????? p.StartInfo.FileName = "cmd.exe";
??????????? p.StartInfo.WorkingDirectory = workingDirectory;
??????????? p.StartInfo.UseShellExecute = false;? //同步
??????????? p.StartInfo.RedirectStandardInput = true; //重定向輸入
??????????? p.StartInfo.RedirectStandardOutput = true; //重定向輸出
??????????? p.StartInfo.RedirectStandardError = true; //重定義錯(cuò)誤輸出
??????????? p.StartInfo.CreateNoWindow = true;
??????????? p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //隱藏窗口
??????????? p.Start();
??????????? p.StandardInput.WriteLine(command);
??????????? p.StandardInput.WriteLine("exit");
??????????? //退出cmd
??????????? //獲得輸出信息
?????????? // strErr = p.StandardOutput.ReadToEnd();
??????????? strErr = p.StandardError.ReadToEnd();
????
??????????? //輸出為空表示出錯(cuò)了
??????????? if ("" == strErr)
??????????? {
??????????????? return true;
??????????? }
??????????? else
??????????? {
??????????????? return false;
??????????? }
??????? }
??? }
}
?
?
二 卸載 在應(yīng)用程序與文件夾里添加 ?msiexec.exe(xp下載windows目錄下)
然后選中 msiexec.exe ,屬性 - 參數(shù) - "-unistall {你的productCode}"
總結(jié)
以上是生活随笔為你收集整理的vs自定义安装包的制作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 获得Google搜索字符串中的关键字
- 下一篇: vb.net播放avi动画