/******************************
* 说明:执行Win32程序
* 创建人:龚宇超
* 创建日期:2017-08-21
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Lskj.Util
{
///
/// 执行Win32程序
///
public sealed class WinHelper
{
///
/// 说明:运行exe程序
/// 创建人:龚宇超
/// 创建日期:2017-08-21
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// Name of the executable.
/// Type of the oper.
/// System.Int32.
[DllImport("kernel32.dll")]
public static extern int WinExec(string exeName, int operType = 0);
///
/// 说明:发送windows消息
/// 创建人:龚宇超
/// 创建日期:2018-01-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The h WND.
/// The MSG.
/// The w parameter.
/// The l parameter.
/// IntPtr.
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
///
/// 说明:检查是否为windows窗体
/// 创建人:龚宇超
/// 创建日期:2018-01-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The h WND.
/// true if the specified h WND is window; otherwise, false.
[DllImport("user32.dll")]
protected static extern bool IsWindow(IntPtr hWnd);
///
/// 说明:
/// 创建人:龚宇超
/// 创建日期:2018-01-22
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The h WND.
/// The MSG.
/// The w parameter.
/// The l parameter.
/// IntPtr.
[DllImport("user32.dll", EntryPoint = "SendMessage")]
protected static extern IntPtr SendCopyData(IntPtr hWnd, int msg, IntPtr wParam, ref CopyDataStruct lParam);
///
/// 说明:
/// 创建人:龚宇超
/// 创建日期:2019-08-06
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The filename.
/// The arguments.
/// true if XXXX, false otherwise.
public static bool StartProcess(string filename, string[] args)
{
try
{
string s = "";
foreach (string arg in args)
{
s = s + arg + " ";
}
s = s.Trim();
Process myprocess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(filename, s);
myprocess.StartInfo = startInfo;
myprocess.StartInfo.UseShellExecute = false;
myprocess.Start();
return true;
}
catch (Exception)
{
throw;
}
}
}
[StructLayout(LayoutKind.Sequential)]
public struct CopyDataStruct
{
public IntPtr Data;
public int CBData;
[MarshalAs(UnmanagedType.LPStr)]
public string LPData;
}
}