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

Windows specific forum
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

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

Post 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?
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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?
@}--`--,-- A rose by any other name ..
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post 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".
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
real
User
User
Posts: 49
Joined: Fri Oct 08, 2004 5:17 am

Post 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
Last edited by real on Fri May 05, 2006 11:54 am, edited 1 time in total.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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()))
El_Choni
Post Reply