Get ExeName... and load the running exe file

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Gwen.

Hi
Is there a way to get the name/path of the running purebasic exe ?
And is there then a way for a PB exe to load it's own exe file from disk??

I would like to be able to append data to the end of the running exe and then save it to a new filename i.e MyNew.exe this would be the beginnings of a simple program generator...



I do this easily in Delphi... I stumbled upon the Purebasic web site and liked the idea of being able to make such tiny executables! But I need to be able to do some basic stuff like this and can't find any info about such things in the Purebasic help...

I have so many questions :)

..Gwen..
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Is there a way to get the name/path of the running purebasic exe ?

These two lines have always worked perfectly for me on all versions of Windows:

; Get app's directory.
appdir$=Space(255) : GetCurrentDirectory_(255,appdir$) : If Right(appdir$,1)"\" : appdir$=appdir$+"\" : EndIf

; Get app's name.
appname$=PeekS(GetCommandLine_()) : appname$=GetFilePart(appname$) : appname$=Left(appname$,FindString(appname$,".exe",1)+3)


PB - Registered PureBasic Coder

Edited by - PB on 06 June 2002 00:11:35
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Gwen.

Hello PB

Thanks! That works perfectly

Now I just have to figure out how to load the running exe into something I can work with... a string maybe .... and then append some data to it, and then write the modified data to disk as 'MyNew.exe'

..Gwen..

p.s. PureBasic could really use a complete users guide with lots of examples!
just a simple guide with demo code for each routine,function,keyword..etc would be a great help
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Hi, try this:

Code: Select all

If OpenFile(0, "myapp.exe")
  FileSize = FileSize("myapp.exe")
  ReadData(AllocateMemory(0, Filesize, 0), FileSize)
  ; now the app binary data is located at MemoryID()
  CloseFile(0)
EndIf
; modify whatever
If OpenFile(0, "mynewapp.exe")
  WriteData(MemoryID(), NewFileSize)
  ; change NewFileSize to siut the new file size :wink:
  CloseFile(0)
EndIf
Hope this was what you were looking for. Otherwise, insist :wink:

Bye,

El_Choni
Post Reply