另外,为了使软件隐蔽运行,在窗体Load函数中,填写询问对话框代码,并根据用户选择进行指定操作,不过最终都要退出软件,为了能使得软件运行正常,可以出现提示对话框,再销毁窗体。
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace ManagerCenter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// /// 窗体载入响应函数 ///
/// 事件源
/// 事件
private void Form1_Load(object sender, EventArgs e)
{
try
{
//对话框
string message = "是否要启动智能终端管理软件,确定请按“是”,否则按“否”";
string caption = "启动程序";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show(message, caption, buttons, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
//启动软件
Process por = new Process();
por.StartInfo.FileName = "cmd";
por.StartInfo.UseShellExecute = false;
por.StartInfo.RedirectStandardInput = true;
por.StartInfo.RedirectStandardOutput = true;
por.StartInfo.RedirectStandardError = true;
por.StartInfo.CreateNoWindow = true;
por.Start();
por.StandardInput.WriteLine(Properties.Settings.Default.主目录);
por.StandardInput.WriteLine("cd " + Properties.Settings.Default.路径);
por.StandardInput.WriteLine(Properties.Settings.Default.软件名称);
por.StandardInput.WriteLine("Exit");
MessageBox.Show("启动成功,请登陆!", "提示信息");
}
}
catch (System.Exception ex)
{
MessageBox.Show("异常信息:" + ex.Message, "提示信息");
}
finally
{
//关闭窗体
this.Close();
Environment.Exit(0);
}
}
}
}
结果
注:在配置文件中可以配置相关参数,如下所示。
部署使用时需要放置到C:\\\\DF1500\\\\BIN文件夹。