private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = ConnectLan();
}
public string ConnectLan()
{
Process p;
p = new Process();
p.StartInfo.FileName = "cmd.exe";
// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true; p.Start();
p.StandardInput.WriteLine("net use \\\\miss\\rising$\\rav aaa /user:aaa");// 向cmd.exe输入command
p.StandardInput.WriteLine("exit");
p.WaitForExit();
string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
p.Close();
return s; } [DllImport("User32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2); [DllImport("User32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
public static extern IntPtr EnableWindow(IntPtr hwnd, bool fEnable);
private void button2_Click(object sender, EventArgs e)
{
try
{
ProcessStartInfo p = null;
Process Proc;
p = new ProcessStartInfo("Setup.exe", "-update");
p.WorkingDirectory = @"d:\\Program Files\rising\rav\Update";
Proc = Process.Start(p);
IntPtr h1 =new IntPtr(0);
IntPtr h2 =new IntPtr(0);
bool bEnable = true;
h1 = FindWindow(null, "瑞星杀毒软件");
if (h1 != IntPtr.Zero)
{
h2 = FindWindowEx(h1, IntPtr.Zero, "Button", "取消(&C)");
if (h2 != IntPtr.Zero)
{
EnableWindow(h2, false);
MessageBox.Show(h2.ToString());
}
else
{
MessageBox.Show("h2==0");
}
}
else
{
MessageBox.Show("h1==0");
}
}
catch (Exception err)
{
MessageBox.Show("启动更新程序出错\n\r" + err.ToString(), "RavUp提示");
}
}输出结果是“h2==0”
为什么获取不到H2的句柄,请个为高手帮帮忙。
补充:setup.exe是瑞星2008安装程序
{
textBox1.Text = ConnectLan();
}
public string ConnectLan()
{
Process p;
p = new Process();
p.StartInfo.FileName = "cmd.exe";
// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true; p.Start();
p.StandardInput.WriteLine("net use \\\\miss\\rising$\\rav aaa /user:aaa");// 向cmd.exe输入command
p.StandardInput.WriteLine("exit");
p.WaitForExit();
string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
p.Close();
return s; } [DllImport("User32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2); [DllImport("User32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
public static extern IntPtr EnableWindow(IntPtr hwnd, bool fEnable);
private void button2_Click(object sender, EventArgs e)
{
try
{
ProcessStartInfo p = null;
Process Proc;
p = new ProcessStartInfo("Setup.exe", "-update");
p.WorkingDirectory = @"d:\\Program Files\rising\rav\Update";
Proc = Process.Start(p);
IntPtr h1 =new IntPtr(0);
IntPtr h2 =new IntPtr(0);
bool bEnable = true;
h1 = FindWindow(null, "瑞星杀毒软件");
if (h1 != IntPtr.Zero)
{
h2 = FindWindowEx(h1, IntPtr.Zero, "Button", "取消(&C)");
if (h2 != IntPtr.Zero)
{
EnableWindow(h2, false);
MessageBox.Show(h2.ToString());
}
else
{
MessageBox.Show("h2==0");
}
}
else
{
MessageBox.Show("h1==0");
}
}
catch (Exception err)
{
MessageBox.Show("启动更新程序出错\n\r" + err.ToString(), "RavUp提示");
}
}输出结果是“h2==0”
为什么获取不到H2的句柄,请个为高手帮帮忙。
补充:setup.exe是瑞星2008安装程序
如果不行,只能使用EnumWindows