473,378 Members | 1,138 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,378 software developers and data experts.

How to set timeout in CreateProcess in vc++

Hi,

I started one process using CreateProcess() in vc++. Now I want to set wait time out for that created process. Let consider, I am starting notepad using the above function, then I asked to handle that process. In this situation, the Notepad does not return any value. so this handling function still holds. I want to set the wait time, If the time exceed then that handled object should release, I have tried with WaitForSingleObject and set my time, the timeout function is encounted but the Handle resource doesnot release, here code snippet....


STARTUPINFO sInfo;
ZeroMemory(&sInfo,sizeof(sInfo));
PROCESS_INFORMATION pInfo;
ZeroMemory(&pInfo,sizeof(pInfo));
sInfo.cb=sizeof(sInfo);
sInfo.dwFlags=STARTF_USESTDHANDLES;
sInfo.hStdInput=NULL;
sInfo.hStdOutput=wPipe;
sInfo.hStdError=wPipe;

char command[1024]; strcpy(command,
csExecute.GetBuffer(csExecute.GetLength()));

//Create the process here.
if(CreateProcess(0, command,0,0,TRUE,NORMAL_PRIORITY_CLASS|CREATE_NO_W INDOW,0,0,&sInfo,&pInfo))
{
DWORD retVal = WaitForSingleObject(pInfo.hProcess,IE_MAXWAIT);
if(retVal == WAIT_TIMEOUT)
{
MessageBox(NULL,"TimeOut","Output",MB_OK|MB_ICONEX CLAMATION);
CloseHandle(pInfo.hThread);
CloseHandle(pInfo.hProcess);
}
}
Jan 21 '10 #1
1 6050
Banfa
9,065 Expert Mod 8TB
What do you mean by "Handle resource doesnot release"?

The code you have looks OK, it creates a process and then waits for it to finish. If it timeut then it deisplays a message.

The only error is that the process and thread handles are closed only if the wait times out. You always need to close the process and thread handles otherwise you program is leaking resources.
Jan 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Achim Domma | last post by:
Hi, I try to start a process on windows using win32process.CreateProcess and want to to redirect the output. I set the STARTF_USESTDHANDLES flag in the STARTUPINFO structure. But I can not...
0
by: ByteSize | last post by:
Would be grateful of advice please. I have code in VB6 working as follows: lngReply = CreateProcess(sNull, txtStart, ByVal 0&, ByVal 0&, 1&, _ NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo,...
1
by: DOT NET JIM | last post by:
in VB6 the api declares the createprocess lbEnv var as any. When converted to ..NET is change the type any to Object. The problem is, what kind of object. I can not get the env variables set when...
2
by: Steffen | last post by:
Hello! I'm excanging data with an microcontroller (Atmel) via the serial port. My C++ programm is written in Microsoft Visual Studio .net (7) I have the following problem: If I disconnect...
5
by: Stefano Camaiani | last post by:
Hello, please someone have the working code on how to call the CreateProcess API in Vb.Net? I need to call the CreateProcess API directly and i should not use the Vb.Net Process functions like dim...
2
by: Paul Schenk | last post by:
Hi All :) Would be grateful of advice please. I have code in VB6 working as follows: lngReply = CreateProcess(sNull, txtStart, ByVal 0&, ByVal 0&, 1&, _ NORMAL_PRIORITY_CLASS, ByVal 0&,...
2
by: iapain | last post by:
Hello, I am trying to build and infinite loop handler in python 2.4 on windows platform. The problem is that i want to create a process and forcely kill/timeout after 2 sec to handle infinite loop...
1
by: Jai | last post by:
Please provide sample code for using Createprocess in VB.NET. The code I am using is given below. But I get "Error 91: Object referrence not set to an instance of the object" at CreateProcess...
6
by: ss.teo | last post by:
I want to fork a new process and my executable binary is stored inside somewhere. Is there any possible way to fork a process using CreateProcess API without writing to the disk first? Like let's...
2
by: Robin Becker | last post by:
While messing about with some deliberate socket timeout code I got an unexpected timeout after 20 seconds when my code was doing socket.setdefaulttimeout(120). Closer inspection revealed that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.