基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
/******************************
|
||||
* 说明:执行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
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行Win32程序
|
||||
/// </summary>
|
||||
public sealed class WinHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>说明:运行exe程序</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-21 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="exeName">Name of the executable.</param>
|
||||
/// <param name="operType">Type of the oper.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern int WinExec(string exeName, int operType = 0);
|
||||
/// <summary>
|
||||
/// <para>说明:发送windows消息</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-01-22 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="hWnd">The h WND.</param>
|
||||
/// <param name="msg">The MSG.</param>
|
||||
/// <param name="wParam">The w parameter.</param>
|
||||
/// <param name="lParam">The l parameter.</param>
|
||||
/// <returns>IntPtr.</returns>
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
/// <summary>
|
||||
/// <para>说明:检查是否为windows窗体</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-01-22 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="hWnd">The h WND.</param>
|
||||
/// <returns><c>true</c> if the specified h WND is window; otherwise, <c>false</c>.</returns>
|
||||
[DllImport("user32.dll")]
|
||||
protected static extern bool IsWindow(IntPtr hWnd);
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-01-22 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="hWnd">The h WND.</param>
|
||||
/// <param name="msg">The MSG.</param>
|
||||
/// <param name="wParam">The w parameter.</param>
|
||||
/// <param name="lParam">The l parameter.</param>
|
||||
/// <returns>IntPtr.</returns>
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessage")]
|
||||
protected static extern IntPtr SendCopyData(IntPtr hWnd, int msg, IntPtr wParam, ref CopyDataStruct lParam);
|
||||
/// <summary>
|
||||
/// <para>说明:</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2019-08-06 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <param name="args">The arguments.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user