473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

setfocus with send keys

Hello Everyone,

I am not sure what am I doing wrong here. I spend almost whole day working
on this. I am trying to set focus on the process that I started by
Process.start. Below is my code
Process process;
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = @"C:\Program Files\test.exe";
process.StartInfo.WorkingDirectory = @"C:\Program Files\";
process.Start();

IntPtr hWnd =
System.Diagnostics.Process.GetProcessById(process. Id).MainWindowHandle;
if (!hWnd.Equals(IntPtr.Zero))
{

if (IsIconic(hWnd))
{

ShowWindow(hWnd, SW_RESTORE);
}

SetForegroundWindow(hWnd);

}

if (process.Responding)
{

SendKeys.SendWait("{ENTER}");
}
else
{
process.Kill();
}

[DllImport("user32.dll")]
private static extern bool IsIconic(IntPtr hWnd);

[DllImport("user32.dll")]
private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("user32.dll")]
private static extern int SetForegroundWindow (IntPtr hWnd);
while debugging my code never goes inside this if
(!hWnd.Equals(IntPtr.Zero)) statement. I tried to rewrite the code after
reading lot of articles on internet, but it didn't work. Can anyone please
help me on this. I am trying to setfocus on the "test" program so that I can
press enter key, but since there is no focus on the test program, the enter
key is useless. I can start the program successfully, but I cannot put the
focus on that program so that enter key will work.

Any help will be greatly appreciated

Apr 11 '07 #1
0 1073

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Etienne Charland | last post by:
Hi, there is an application running on a remote desktop (under Citrix ICA, but the same problem applies for RDC or PC Anywhere). Now, I want to send keys to the remote application from a local app....
0
by: nil | last post by:
hi..suppose there is only one textbox in the form and one command button... can anyone tell me how can i setfocus of textbox when page is load? should i do that by java script?please send me...
0
by: srinivasarao yarru | last post by:
hi sir, in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse...
6
by: Whizzo | last post by:
Hi folks; I spent a little while some time ago building a touchscreen data entry interface into an Access 2003 form. I'm not too experienced in VBA at all so I was quite happy when I came up with a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.