Hi again..
i'm looking for how to running notepad from vb6..
please help me.
any help will be appreciated.

WaltP commented: Please stop beggin? You don't have to explicitly ask for help. That's why you posted and we already know it! -3

Dani AI

Generated

's suggestion to use VB6's Shell is the simplest way to launch Notepad and it correctly solved 's immediate need. Two practical follow-ups people commonly want but the thread did not show are (1) how to wait until the launched Notepad closes, and (2) how to open a specific file (or rely on the system default app) rather than just the EXE. The snippets below show safe, commonly used approaches and a few caveats to watch for.

Use Shell plus the Windows API to wait for the program to exit (Shell returns a task/process id; you need a process handle to wait):

Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Const INFINITE = &HFFFFFFFF
Public Const SYNCHRONIZE = &H100

Sub RunNotepadAndWait()
    Dim pid As Long, hProc As Long
    Dim npath As String
    npath = Environ$("WINDIR") & "\system32\notepad.exe"
    pid = Shell(npath, 1)   ' start program, store returned PID
    If pid <> 0 Then
        hProc = OpenProcess(SYNCHRONIZE, False, pid)
        If hProc <> 0 Then
            WaitForSingleObject hProc, INFINITE
            CloseHandle hProc
        End If
    End If
End Sub

To open a file with the associated editor (or specify "runas" to prompt elevation), ShellExecute is handy:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

' Example: open C:\Temp\notes.txt with default program (usually Notepad)
ret = ShellExecute(0, "open", "C:\Temp\notes.txt", vbNullString, vbNullString, 1)

Notes and gotchas: use a full path if PATH lookup fails; on 64-bit Windows a 32-bit VB6 app may be redirected (use "C:\Windows\sysnative\notepad.exe" if you need the 64-bit binary); launching programs that require elevation will trigger UAC unless you use the "runas" verb; OpenProcess can fail for permission reasons. These additions cover common gaps left after the original Shell example and keep the behaviour predictable for real-world use.

Recommended Answers

All 6 Replies

you mean run notepad of windows program or make a notepad in vb6?

you mean run notepad of windows program or make a notepad in vb6?

Running notepad of windows program from vb.
i can run notepad from vb like i click on notepad exe file.
please help.

thanks..

oh, i see,,
You can use shell function to execute an exe file.

Shell(PathName,WindowStyle)

oh, i see,,
You can use shell function to execute an exe file.

Shell(PathName,WindowStyle)

Thanks sir..
but can u give a hand for an example of shell function?

please.
Thanks.

Okay,,
see if this help :

Private Sub Command1_Click()
Call Shell("notepad.exe", vbNormalFocus)
End Sub
commented: simple but good +4
commented: Always Helping +1

its working nice..
thank you very much sir for helping me..

now this thread is solved.

commented: post your code another time.. +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.