Page 1 of 1

Posted: Wed Jun 05, 2002 5:48 am
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..

Posted: Wed Jun 05, 2002 6:45 am
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

Posted: Wed Jun 05, 2002 7:18 am
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

Posted: Wed Jun 05, 2002 1:05 pm
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