NotePad'ı Çalıştırmak

Bazen yazdığınız uygulamanın Readme dosyasını görüntülemek için Not defterini çalıştırmak kullanışlı olur. 1. Formun üzerine bir CommandButton yerleştirin.
2. Aşağıdaki kodu formun Declarations Section bölümüne kopyalayın.

   Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
   Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwAccess As Long, ByVal fInherit As Integer, ByVal hObject As Long) As Long
   Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
   Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
   
   Const SYNCHRONIZE = 1048576
   Const NORMAL_PRIORITY_CLASS = &H20&
   
   Private Type PROCESS_INFORMATION
      hProcess As Long
      hThread As Long
      dwProcessId As Long
      dwThreadId As Long
   End Type

   Private Type STARTUPINFO
      cb As Long
      lpReserved As String
      lpDesktop As String
      lpTitle As String
      dwX As Long
      dwY As Long
      dwXSize As Long
      dwYSize As Long
      dwXCountChars As Long
      dwYCountChars As Long
      dwFillAttribute As Long
      dwFlags As Long
      wShowWindow As Integer
      cbReserved2 As Integer
      lpReserved2 As Long
      hStdInput As Long
      hStdOutput As Long
      hStdError As Long
   End Type
3. Şimdi, aşağıdaki kodu da Command1_Click olayına kopyalayın:
   Dim pInfo As PROCESS_INFORMATION
   Dim sInfo As STARTUPINFO
   Dim sNull As String

   sInfo.cb = Len(sInfo)
   success& = CreateProcess(sNull, "notepad.exe e:\anexis\vbpage\vbisland.html", ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)

   MsgBox "Notepad has been started. Click OK to end it."
   
   ret& = TerminateProcess(pInfo.hProcess, 0&)
   ret& = CloseHandle(pInfo.hThread)
   ret& = CloseHandle(pInfo.hProcess)

   MsgBox "Notepad has been shut down.
4. F5'e basarak uygulamayı çalıştırın.