[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SYNCHRONIZE Access

Posted on 2001-07-09
4
Medium Priority
?
613 Views
Last Modified: 2013-12-03
I have an executable created in Visual Studio as a FORTRAN console application. I am starting this application from within another application with the CreateProcess API. I would like to then use the WaitForSingleObject API to detect when it ends. To do this it appears that Windows NT requires at least 'SYNCHRONIZE' access (see SDK notes on the WaitForSingleObject API). Any thoughts on what can be done in Fortran source code at compile time to insure that I can have 'SYNCHRONIZE' access?
I think the solution to this is may be setting the access privileges (by using other API calls) within the FORTRAN source.
An API source example in C++ or any other language would be OK.
0
Comment
Question by:jdwarren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 800 total points
ID: 6265647
There is nothing that needs to be changed in your FORTRAN app.  Since you are starting from within your app with CreateProcess, you already have all the rights you need.  All you need to use WaitForSingleObject is the handle to the new process.  I'd suggest a function like this one:

BOOL DoProcess(const TCHAR *lpszCommand, const TCHAR *lpszDirectory, BOOL bWait)
{
     STARTUPINFO si;
     memset(&si, 0, sizeof(STARTUPINFO));

     si.cb = sizeof(STARTUPINFO);
     si.lpReserved = NULL;
     si.lpDesktop = _T("WinSta0\\Default");
     si.lpTitle = NULL;

     PROCESS_INFORMATION pi;

     if(CreateProcess(
          NULL,
          (TCHAR *)lpszCommand,
          NULL,
          NULL,
          FALSE,
          0,
          NULL,
          (_tcslen(lpszDirectory) == 0 ? NULL : lpszDirectory),
          &si,
          &pi
          )){

          // Close the hThread handle, not needed here
          CloseHandle(pi.hThread);

          if(bWait){
               WaitForSingleObject(pi.hProcess, INFINITE);
          }

          // The process is either done or we don't care about it finishing
          CloseHandle(pi.hProcess);

          return TRUE;
     }
     
     return FALSE;
}
0
 

Author Comment

by:jdwarren
ID: 6266255
jhance,
I had actually used the same arguments to CreateProcess that you had suggested and it looked like a good value was returned to pi.hProcess.
Your comment that nothing needs to be done in FORTRAN seems valid so the points go to you as I can reproduce good results when using another type compiler.
It will remain a mystery to me as to why the WaitForSingleObject fails when Visual Basic is the compiler. Other VB attempts using Shell and then OpenProcess also fail at OpenProcess with a GetLastError of ERROR_ACCESS_DENIED. This is what lead me to believe that I did not have 'SYNCHRONIZE' access.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6266556
Three questions:

1) Where did Visual Basic come from in this situation?  You didn't even mention it in passing before.

2) Why did you accept this if it didn't solve your problem?

3) Where did we start talking about OpenProcess()??  You asked about CreateProcess and WaitForSingleObject.  Neither of which have anything to do with OpenProcess().  You are correct that OpenProcess needs privilege to succeed but that has nothing to do with the process you are opening and everything to do with the privilege of the process calling OpenProcess.


I guess it's no wonder that my answer didn't match up with your "real" question since you seem to have asked about one thing when there was really a different question involved...
0
 

Author Comment

by:jdwarren
ID: 6269320
jhance,
Your informing me that nothing needed to be done in the Fortran Application was a reasonable answer.

I neglected to give details what compilers and other failed attempts occurred because I erroneously drew a conclusion that I needed to set something in the Fortran source code to make it work. Once you indicated that it was not necessary, I then proved it to myself by using a different type compiler.

My follow-up comment only was put there to indicate that I had actually tried more than one approach in VB to get it to work but everything had failed.

For the purpose of addressing this now as a new VB question, I would be willing to add another question to experts-exchange if you think you have a VB solution to the problem. Right now I have something working but it would be nice to know how to do it in VB since I spent so much time there in the first place.

Would you like to answer another (more specific) Widows API question relating to VB?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question