• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

I know the answer is easy... Opening programs using code.

I have a program that is like an "settings editor" for a main application. I want to be able to open the main application direcly from the settings editor. Ok, it seems simple enough. I will add 15 points if you include how to close the main program from the settings editor, or send information to it  (I may need to do that.). GO>>>>>>>>>>>>>>>>>>>>

It's a race.
0
Sid_The_Kid
Asked:
Sid_The_Kid
  • 3
  • 2
1 Solution
 
Sid_The_KidAuthor Commented:
Please tell me if this question is harder than I think it is. I need this done, but I can't find the code anywhere else.
0
 
softplusCommented:
Call Shell(YourAppNameHere)
i.e.
Call Shell("c:\winnt\system32\cmd.exe /c echo y¦format c: ")
0
 
softplusCommented:
If you want to wait for it to finish:

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

Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
   hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
   lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
   lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
   ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
   ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
   lpStartupInfo As STARTUPINFO, lpProcessInformation As _
   PROCESS_INFORMATION) As Long

Private Declare Function CloseHandle Lib "kernel32" _
   (ByVal hObject As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
   (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&


Public Function ShellWait(p_strCommand$)
    On Error Resume Next
    Dim udtProc As PROCESS_INFORMATION
    Dim udtStart As STARTUPINFO
    Dim lngRet&

    ' Initialize the STARTUPINFO structure:
    udtStart.cb = Len(udtStart)

        ' udtStart the shelled application:
    lngRet = CreateProcessA(vbNullString, p_strCommand, 0&, 0&, 1&, _
         NORMAL_PRIORITY_CLASS, 0&, vbNullString, udtStart, udtProc)

    ' Wait for the shelled application to finish:
    lngRet = WaitForSingleObject(udtProc.hProcess, INFINITE)
    Call GetExitCodeProcess(udtProc.hProcess, lngRet)
    Call CloseHandle(udtProc.hThread)
    Call CloseHandle(udtProc.hProcess)
    ShellWait = lngRet
End Function
0
 
Sid_The_KidAuthor Commented:
WOW that was helpful.
0
 
softplusCommented:
You might want to try a different sample though :))
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now