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");
    }
    }
    }
    }
  • 相关阅读:
    包含min函数的栈
    栈的应用
    给定金额m和红包数量n
    顺时针打印矩阵
    二叉树的镜像
    elementUI table表头错位问题
    金额格式化
    ajax跨域问题全解
    JavaScript 的 this 原理
    vue技术分享-你可能不知道的7个秘密
  • 原文地址:https://www.cnblogs.com/chusiping/p/2254036.html
Copyright © 2011-2022 走看看