How to Use CreateProcess in VB6

Written by lora covrett
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Use CreateProcess in VB6
API stands for application programming interface. (Hemera Technologies/ Images)

"CreateProcess" is a function available in one of the Microsoft Windows core application programming interfaces (APIs) available with the Windows operating system. "CreateProcess" opens a program as a Windows process and within its own thread. Windows APIs give more flexibility to VB programmers. For example, there are several functions available within the Windows API that allow programmers to perform specific actions with a function call to the API rather than attempting to write their own code to do the same thing.

Skill level:

Other People Are Reading


  1. 1

    Start a new Standard EXE Visual Basic project. Add user-defined types named "PROCESS_INFORMATION" and "STARTUPINFO" in the code for "Form1" that is automatically created with the new project. These are structures used in Visual Basic to group data and are required parameter types of the "CreateProcess" function.

  2. 2

    Create two constants that are also parameters of the "CreateProcess" function.

    Const SYNCHRONISE = 1048576


    Declare the "CreateProcess" function as "Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" ."

  3. 3

    Declare additional functions to open the process ("Private Declare Function OpenProcess Lib "kernel32.dll""), terminate the process ("Private Declare Function TerminateProcess Lib "kernel32"") and to close the handle ("Private Declare Function CloseHandle Lib "kernel32"").

  4. 4

    Add a command button to "Form 1' and name it "cmdOpenNotepad." In the code for "cmdOpenNotepad", define a variable of type PROCESS_INFORMATION, STARTUPINFO, a string to represent null and two longs for return values.

    Pass the Notepad.exe to the "CreateProcess" function as follows:

    CreateProcess(sNull, "Notepad.exe", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)

  5. 5

    Terminate the process with "TerminateProcess(pInfo.hProcess, 0&)."

    Close the handle to the thread with "CloseHandle(pInfo.hThread)" and to the process with "CloseHandle(pInfo.hProcess)."

Tips and warnings

  • Always close the thread handle and the process handle to avoid memory leaks.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.