zoukankan      html  css  js  c++  java
  • 【转】调用 开始 运行 直接执行命令

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Diagnostics;

    namespace fasta2011
    {
    public class Cmd
    {
    private const byte VK_LWIN = (byte)Keys.LWin;
    private const byte VK_R = (byte)Keys.R;
    private const int KEYEVENTF_KEYUP = 0x02;
    private const int WM_SETTEXT = 0x000C;
    private const int WM_CLICK = 0x00F5;

    [DllImport("user32")]
    public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    [DllImport("user32.dll")]
    static extern int FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll")]
    public static extern int FindWindowEx(int parentHandle, int childAfter, string className, string windowTitle);

    [DllImport("user32.dll")]
    static extern IntPtr SendMessage(int hWnd, uint Msg, int wParam, string lParam);


    public static void Run(string CmdText)
    {
    keybd_event(VK_LWIN, 0, 0, 0);
    keybd_event(VK_R, 0, 0, 0);
    keybd_event(VK_R, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);

    System.Threading.Thread.Sleep(50);

    int h1 = 0, h2 = 0, h3;
    h1 = FindWindow(null, "运行"); //这要修改为窗口标题
    if (h1 != 0)
    {
    h2 = FindWindowEx(h1, 0, "ComboBox", null);
    if (h2 != 0)
    {
    SendMessage(h2, WM_SETTEXT, 0, CmdText);
    System.Threading.Thread.Sleep(10);

    h3 = FindWindowEx(h1, 0, null, "确定"); //这要修改为按钮文本
    if (h3 != 0)
    {
    SendMessage(h3, WM_CLICK, 0, null);
    }
    else
    {
    MessageBox.Show("h3==0");
    }
    }
    else
    {
    MessageBox.Show("h2==0");
    }
    }
    else
    {
    MessageBox.Show("h1==0");
    }
    }
    }
    }
  • 相关阅读:
    Android_SQLite标准版
    AutoMapper
    ext.net实例
    Winform Ribbon开发
    数据仓库建设之《元数据管理》
    数据仓库建设之维度建模
    数据仓库建设之总方案
    一点感想
    详细探秘Linux 和 Window 双系统访问Windows 磁盘需要输入密码问题解决过程分析
    如何把数据放到C#的心里之 DB2实例
  • 原文地址:https://www.cnblogs.com/chusiping/p/2254036.html
Copyright © 2011-2022 走看看