tags:

views:

29

answers:

1

Ihave a C function which blockes exe applications from being Executed, and i like to do the same with window form .net2. How?

int ExecuteBlocking(const char *appName, const char *cmdLine)
{
 char sz[260];
 STARTUPINFO siStartupInfo;
 PROCESS_INFORMATION piProcessInfo;
 memset(&siStartupInfo, 0, sizeof(siStartupInfo));
 memset(&piProcessInfo, 0, sizeof(piProcessInfo));
 siStartupInfo.cb = sizeof(siStartupInfo);
 BOOL b = CreateProcess(0, sz, 0, 0, 0, CREATE_DEFAULT_ERROR_MODE, 0, 0, &siStartupInfo, &piProcessInfo);
 if (b == 0)
  return -1;
 WaitForSingleObject(piProcessInfo.hProcess, -1);
 CloseHandle(piProcessInfo.hProcess);
 CloseHandle(piProcessInfo.hThread);
 return 0;
}
+1  A: 

That C code does not prevent a program from executing. It simply waits for it to finish executing, the function won't return until that happens. You'd get the exact same thing in .NET with Process.WaitForExit().

Hans Passant
oops i have upload the wrong function, please let me update the question, but anyway how to blocking application from being executed in net2
Power-Mosfet
Please don't update the question. I gave you a good answer to your original question, it behooves you to mark it answered and start another one.
Hans Passant