安装流程:
运行e:\tm2006preview.exe --->下一步(快捷键Alt+N)-->我同意(快捷键Alt+I)-->下一步(快捷键Alt+N)-->安装(快捷键Alt+I)--等待几分钟--->完成(快捷键Alt+F)c#代码:
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;System.Diagnostics.ProcessStartInfo Info= new System.Diagnostics.ProcessStartInfo();
Info.FileName = "e:\\tm2006preview.exe";
System.Diagnostics.Process Proc ;
Proc = System.Diagnostics.Process.Start(Info);
SendKeys.Send("%(N)"); //这一步没有被执行。
SendKeys.Send("%(I)");
SendKeys.Send("%(N)");
SendKeys.Send("%(I)");
System.Threading.Thread.Sleep(10000);
SendKeys.Send("%(F)");
请问高手以上代码为什么不行?请指点,谢谢。
运行e:\tm2006preview.exe --->下一步(快捷键Alt+N)-->我同意(快捷键Alt+I)-->下一步(快捷键Alt+N)-->安装(快捷键Alt+I)--等待几分钟--->完成(快捷键Alt+F)c#代码:
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;System.Diagnostics.ProcessStartInfo Info= new System.Diagnostics.ProcessStartInfo();
Info.FileName = "e:\\tm2006preview.exe";
System.Diagnostics.Process Proc ;
Proc = System.Diagnostics.Process.Start(Info);
SendKeys.Send("%(N)"); //这一步没有被执行。
SendKeys.Send("%(I)");
SendKeys.Send("%(N)");
SendKeys.Send("%(I)");
System.Threading.Thread.Sleep(10000);
SendKeys.Send("%(F)");
请问高手以上代码为什么不行?请指点,谢谢。
解决方案 »
- Adobe SDK 修改已有PDF文档的页眉页脚
- 请问这个提示是什么意思,我使用的是VS2008SP1专业版.
- 帮我看一个msdn这个错误到底怎么解决的?
- 求GridView自动更新数据的例子
- 郁闷了好几天了. listview填充问题-----在线等,急!急!急!急!急!急!急!急!急!急!急!
- .net 第一次作业,如何整蛊老师?感兴趣的高手教下,谢谢啦
- 为什么我主线程会自己等待子线程啊?
- 当一个网站有多个二级域名需要绑定不同的文件夹,怎样管理Bin文件,一定要每个文件夹里都有一个吗?
- 【C#菜鸟求助大神】初学C#,有些疑问,望大神解疑!
- 搜索了一下,没有好的解决办法,一个窗体调用另外一个窗体中函数的问题
- 关于ListView控件中IndexFromPoint方法
- postback!!!高手帮我!
要自己做安装程序?新建一个基于Installer的DLL,然后添加自定义安装
*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
SendKeys.Send("%(N)"); //这一步没有被执行。
SendKeys.Send("%(I)");
SendKeys.Send("%(N)");
SendKeys.Send("%(I)");
System.Threading.Thread.Sleep(10000);
SendKeys.Send("%(F)");
无效,正是因为你发送的消息是发送到本程序,而不是你用start打开的程序。
private static extern IntPtr FindWindow(string lpClassName,
string lpWindowName); [DllImport("user32.dll",EntryPoint="FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent,
IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("User32.dll",EntryPoint="SendMessage")]
private static extern int SendMessage(IntPtr hWnd,
int Msg, IntPtr wParam, string lParam); const int WM_GETTEXT = 0x000D;
const int WM_SETTEXT = 0x000C;
const int WM_CLICK = 0x00F5;
private void button1_Click(object sender, System.EventArgs e)
{
System.Diagnostics.ProcessStartInfo Info= new System.Diagnostics.ProcessStartInfo();
Info.FileName = "e:\\TM2006Spring.exe";
// Info.WindowStyle=ProcessWindowStyle.Hidden; System.Diagnostics.Process Proc ;
try
{
//
//启动外部程序
//
Proc = System.Diagnostics.Process.Start(Info); //下面的这些参数都可以用Spy++查到
string lpszParentClass = "#32770"; //整个窗口的类名
string lpszParentWindow = "TM2006新春版 安装"; //窗口标题
string lpszClass_Submit = "Button"; //需要查找的Button的类名
string lpszName_Submit = "下一步(&N) >"; //需要查找的Button的标题
IntPtr ParenthWnd = new IntPtr(0);
IntPtr EdithWnd = new IntPtr(0);
ParenthWnd = FindWindow(lpszParentClass,lpszParentWindow);
if (!ParenthWnd.Equals(IntPtr.Zero))
{
EdithWnd = FindWindowEx(ParenthWnd,
EdithWnd,lpszClass_Submit,lpszName_Submit);
if (!EdithWnd.Equals(IntPtr.Zero))
{
SendMessage(EdithWnd,WM_CLICK,(IntPtr)0,"");
} } }
catch(System.ComponentModel.Win32Exception e1)
{
// Console.WriteLine("系统找不到指定的程序文件。\r{0}", e1);
return;
}
}
上面写的不能用,请高手指点。