Search notes:

Examples for Visual Basic for Application accessing the Windows API: CreateProcess

The following example creates a process.
This example needs the VBA declarations of the Windows API which can be found here.
option explicit

sub main() ' {

    dim secAttrPrc as SECURITY_ATTRIBUTES : secAttrPrc.nLength = len(secAttrPrc)
    dim secAttrThr as SECURITY_ATTRIBUTES : secAttrThr.nLength = len(secAttrThr)

    dim startInfo  as STARTUPINFO ' : startInfo.cb = len(startInfo)
    dim procInfo   as PROCESS_INFORMATION

    if CreateProcess (                                         _
         lpApplicationName      :=   vbNullString            , _
         lpCommandLine          :=  "cmd.exe"                , _
         lpProcessAttributes    :=   secAttrPrc              , _
         lpThreadAttributes     :=   secAttrThr              , _
         bInheritHandles        :=   false                   , _
         dwCreationFlags        :=   0                       , _
         lpEnvironment          :=   0                       , _
         lpCurrentDirectory     :=   environ("USERPROFILE")  , _
         lpStartupInfo          :=   startInfo               , _
         lpProcessInformation   :=   procInfo )  then

     else
        MsgBox "Couldn't create process"
     end if

end sub ' }
Github repository WinAPI-4-VBA, path: /examples/CreateProcess.bas

See also

Other examples

Index