Page 1 of 1

Is it possible to check how a executable has been launched?

Posted: Tue Apr 25, 2006 3:01 pm
by techjunkie
Hi,

Is it possible to check (in your PB application) how a executable has been launched, i.e. "double click", "command prompt" or "run"?

M$ records everything in registry, so I shouldn't be supprised if they record that kind of stuff.

Do they?

If not - is there another way to find out this information?

Posted: Tue Apr 25, 2006 3:14 pm
by Dare2
If you control the install, can you make each method send a command argument? Eg:

Code: Select all

C:\mypath\myprog.exe shortcut
Too simplistic?

Posted: Tue Apr 25, 2006 4:01 pm
by techjunkie
Dare2 wrote:Too simplistic?
Yes, if the application is launched by a "double click" I would launch it in "restore mode", in any other way in "install mode".

Posted: Fri May 05, 2006 11:28 am
by real
You could check the parent process like that:

Code: Select all

Procedure GetParentProcess(hwnd.l)
  Protected hwndp.l, pid.l, snap.l, pinfo.PROCESSENTRY32,parentinfo.PROCESSENTRY32
  GetWindowThreadProcessId_(hwnd, @pid)
  snap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS,0)
  If snap
    pinfo\dwSize=SizeOf(PROCESSENTRY32); 
    If Process32First_(snap, @pinfo)
      While Process32Next_(snap, @pinfo)
        If pid = pinfo\th32ProcessID
          CloseHandle_(snap); 
          snap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS,0)
          If snap
            parentinfo\dwSize=SizeOf(PROCESSENTRY32); 
            If Process32First_(snap, @parentinfo)
              While Process32Next_(snap, @parentinfo)
                If pinfo\th32ParentProcessID = parentinfo\th32ProcessID
                  CloseHandle_(snap); 
                  MessageRequester("Program...","started via "+Chr(39)+PeekS(@parentinfo\szExeFile)+Chr(39))
                EndIf
              Wend
            EndIf
            CloseHandle_(snap); 
          EndIf
        EndIf
      Wend
    EndIf
    CloseHandle_(snap); 
  EndIf
EndProcedure

OpenWindow(0,0,0,0,0,"proc",#PB_Window_Invisible)
GetParentProcess(WindowID(0))
What it does:
1. It creates an invisible window
2. It determines the parent process of that window

Posted: Fri May 05, 2006 11:52 am
by El_Choni
Got this from here: http://www.catch22.net/tuts/undoc01.asp

Code: Select all

; Returns TRUE if started through a shortcut, FALSE if not. 
#STARTF_TITLESHORTCUT = $800
Procedure StartedFromShortcut()
  GetStartupInfo_(@si.STARTUPINFO)
  If si\dwFlags&#STARTF_TITLESHORTCUT
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure  

MessageRequester("Started from shortcut?:", Str(StartedFromShortcut()))