Absolutley any suggestions on this matter will be good, cuz i have no idea how to do this
thx
Printable View
Absolutley any suggestions on this matter will be good, cuz i have no idea how to do this
thx
Hi,
I'm afraid it is in no way clear what you are talking about. Are you talking about editing your code in Debug mode, as you can do in VB6? In that case, to the best of my knowledge, it is not possible at all. You need to stop, edit and recompile.
Or maybe you are talking about adding code to an event, a button click for example. You would use the Addhandler to accomplish this - it is very useful whne you create objects at runtime.
Please clarify.
zaza
Hi,
here's an example:
i have an app running on a remote pc which is controlled by me from my pc, it can do stuff like delete file, copy file, but i accidently forgot to put in a move file code, so now i need to add code to an already compiled and working app.
I can send it a file which will contain the needed code, but how do i get the app to run it?
You have a few options.
1) You could replace the executable with another which contains the updated code. i.e. an update for your program.
2) You could put it in a second executable and run that one whenever you need to move a file.
There's no way to tell code that you want it to do something different unless you change the code. To do that, once it is compiled, is very much non-trivial unless you've been crafty enough to build it in in advance. For example, if your app works by opening a text file and extracting a list of the functions that are available to it and the locations of various sets of code to run these properties, then doing just that. In other words, if your main app is just a frontend for a load of different code in separate files and it pulls these in in order to function. But I suspect you're talking about modifying an exe, in which case you'd be better of just replacing it with an updated version.
zaza
Well i dont nesseserly have to modify the exe, and extracting functions from files sounds promissing, could you plz give me an example on this
Thx
Don't release half-finished software. Thats the easiest way.
i wrote: "Here's an example:"Quote:
Originally Posted by wossname
I dont have no exe on a remote pc, it was just an example
I think there is a way to re-compile an existing exe.
Not sure if this is what your looking for but here is what I've got for vb6
Quote:
EXE Compiler - Readme
.: Introduction
This code sample demonstrates how to create your own exe files.
Not a direct approach. The program writes to the end of an existing exe file. The exe file can then access this data and work with it.
The compiled exe does not require any extra files for working (except the vb runtimes, of course!)
.: In more detail... :.
prjRdfce.vbp is the program (when compiled) that acts as the template for the exe. It is compiled to 'rdfce.ext'.
prjExeCompiler is the program used to create new exe files. It first makes a copy of rdfce.ext to the file name supplied by the user, say test.exe. It then writes user supplied data to the end of test.exe.
When test.exe is run, it reads the data contained in itself and work accordingly (all that code is done in prjRdfce)
Hopefully, that explains the working.
.: Uses :.
For creating apps like self extracting archives, stand alone photo album, etc etc. If you have done something with it then please write to me.
.: Copyright and stuff
© 2002, Anoop Sankar
For distribution and usage see the notice on the source.
.: Contact
e-mail : [email protected]
Website : www.smilehouse.cjb.net
Title: [ Exe Compiler ]
Description: This code demonstrates how to compile exe files using vb code, like the winzip self extractor.
This file came from Planet-Source-Code.com...the home millions of lines of source code
You can view comments on this code/and or vote on it at: http://www.Planet-Source-Code.com/vb...40144&lngWId=1
The author may have retained certain copyrights to this code...please observe their request and the law by reviewing all copyright conditions at the above URL.
'--------------------------------------------------------
' Copyright 2002, Anoop Sankar
'You may freely use, modify and distribute this source
'code, provided that you do not remove this message.
'But, you are NOT allowed to distribute the compiled
'version (.EXE,.DLL,.OCX etc etc.) of this program
'or any program which uses the below code without my
'consent.
'
'If you modified something, put your name below..
'
'Orginal Code : Anoop Sankar ([email protected])
'Modified by : No one so far
'
'Last Update : Oct 25,2002
'Visit www.smilehouse.cjb.net for more source code
'-------------------------------------------------------
'
'Purpose of the project is to create a stand alone exe
'file from VB code. It doesn't do this directly, but uses
'a simple work around. I think this is quite a useful
'way to do this. If you think otherwise or if you have
'other methods, I would love to hear from you.
'
'The method is .. write to the end of a pre-created exe
'file, in binary mode.
'
'Check 'readme.html' for more details.
'
'-------------------------------------------------------
VB Code:
Private Sub cmdCompile_Click() 'This is were all the action takes place On Local Error GoTo errTrap Dim BeginPos As Long 'variable to store the start of data Dim PropBag As New PropertyBag 'property bag to store the data Dim varTemp As Variant 'for file writing 'Below section loads data into the property bag. With PropBag .WriteProperty "Caption", txtCaption.Text .WriteProperty "Text", txtText.Text .WriteProperty "Picture", imgPic.Picture .WriteProperty "Protected", chkPass.Value .WriteProperty "Password", txtPass.Text 'You may add your own propery using the syntax 'PropBag.WriteProperty "<property name>",<property value> 'As you might have noticed, property value can be anything 'string, picture, or numerical. End With 'rdfce.ext is the template we use to create our exe. 'RDFCE = Renamed Dummy For Creating Executable ;-) '(source of that file is included too) 'first copy that file to the user provided file name. FileCopy App.Path & "\rdfce.ext", App.Path & "\" & txtExeFile.Text 'now open the file in binary mode Open App.Path & "\" & txtExeFile.Text For Binary As #1 BeginPos = LOF(1) 'the point were we add extra data varTemp = PropBag.Contents Seek #1, LOF(1) Put #1, , varTemp 'write data Put #1, , BeginPos 'write starting point of extra data Close #1 MsgBox "Exe File created without a problem", vbInformation, "Compilation Done" Exit Sub 'Thats it! The exe is compiled. 'Read the prjExeDummy (prjRdfce.vbp) to find how the 'compiled exe works. errTrap: 'to err is electronic Msg = "There was an error during compilation" & vbCrLf Msg = Msg & vbCrLf & Err.Description MsgBox Msg, vbCritical, "Error" End Sub Private Sub lblAddPic_Click() On Local Error GoTo errTrap ComDLG.CancelError = True ComDLG.ShowOpen imgPic.Picture = LoadPicture(ComDLG.FileName) errTrap: End Sub Private Sub chkPass_Click() On Local Error Resume Next If chkPass.Value > 0 Then txtPass.Enabled = True txtPass.SetFocus Else txtPass.Enabled = False End If End Sub
In the other form
VB Code:
Dim PropBag As New PropertyBag 'the property bag Private Sub Form_Load() 'On Local Error Resume Next Dim BeginPos As Long Dim varTemp As Variant Dim byteArr() As Byte Open App.Path & "\" & App.EXEName & ".exe" For Binary As #1 Get #1, LOF(1) - 3, BeginPos 'get the start position of data Seek #1, BeginPos 'seek to data start Get #1, , varTemp 'get property bag contents byteArr = varTemp PropBag.Contents = byteArr 'load property bag PropBag.WriteProperty "LOF", LOF(1) 'a few extra props PropBag.WriteProperty "BeginPos", BeginPos Close #1 'password protection 'I know that this is not tight, but just for a demo If Val(PropBag.ReadProperty("Protected", "0")) > 0 Then Dim PassInp As String PassInp = InputBox("Enter password:", "Password Required") If PassInp <> PropBag.ReadProperty("Password") Then MsgBox "Password not valid", vbCritical, "Nice Try!" End End If End If With PropBag txtText.Text = .ReadProperty("Text") Set imgPic.Picture = .ReadProperty("Picture") Me.Caption = .ReadProperty("Caption") End With End Sub Private Sub cmdExeInfo_Click() 'display exe stats lblInfo(0).Caption = App.EXEName & ".exe" lblInfo(1).Caption = PropBag.ReadProperty("LOF") & " bytes" lblInfo(2).Caption = PropBag.ReadProperty("BeginPos") & " bytes" lblInfo(3).Caption = (PropBag.ReadProperty("LOF") - PropBag.ReadProperty("BeginPos")) & " bytes" lblInfo(4).Caption = Format((PropBag.ReadProperty("BeginPos") / PropBag.ReadProperty("LOF")) * 100, "0.00") & " %" picInfo.Visible = True End Sub Private Sub Label3_Click() picInfo.Visible = False End Sub
thx, but in this matter recompiling an exe isn't the solution (thou i can use this later :))
anyway, like zaza wrote, i need a code that can read code from file and somehow procces it
Hmmm are you sure?
I dont think you can do it that way, but my example fits your request.
The existing app needs it's "file content" added unto, so that it can run it.Quote:
it can do stuff like delete file, copy file, but i accidently forgot to put in a move file code, so now i need to add code to an already compiled and working app.
I can send it a file which will contain the needed code, but how do i get the app to run it?
Unless, you had originally designed it to accept files, to execute as code.
You did not. So
Maybe I missunderstood your objectives.
Well the reason why i dont want to recompile an exe in this situation is because the app is supposed to run on a remote machine without shutdown all the time, and becides, recompiling an exe file on a remote machine will require the user to do it as i understood, thats why i want it to accept files with code and execute them, so all i need is an explanation how to make it execute code from file
Thx
I think you'd better think about doing so.Quote:
Well the reason why i dont want to recompile an exe in this situation is because the app is supposed to run on a remote machine without shutdown all the time,
I dont think this example would require the user to do it.Quote:
becides, recompiling an exe file on a remote machine will require the user to do it as i understood,
You would be adding an application, to do the recompilation of the original.
If you want an existing app, that was not designed to do this, to somehow know what to execute from a file... good luck I can't help you with that...Quote:
thats why i want it to accept files with code and execute them,
so all i need is an explanation how to make it execute code from file
Thx
Anyone.... anyone.... na didn't think so.
If you are planning for future conditions, then it should be possible to design the original application. Not easy but plausible.
For example I use an App.ini file, to execute startup code.
This code is essentially saved during runtime by the user, in the ini file.
When they choose preferences etc.
I could elaborate on this example?
You mean the code that's supposed to be in the form_load() is in the app.ini file and it executes when the app starts?Quote:
Originally Posted by TTn
I think TTn means that user preferences, such as background colour, font size etc can be savd in an ini file and then read in when the user executes the app. That way, user-defined preferences can be maintained.
What I was talking about earlier would have to be built in from scratch but, as Wossy says, usually it's better to actually define your objectives and finish your app rather than make it too open-ended. Of course, if you wanted the user to be able to import exe's as well, then that's a bit different...
So, what you might do is write a text file:
"Bobbins", "c:\Bobbins.exe"
"Cobblers", "c:\Cobblers.exe"
"doodah", "c:\doodah.exe"
and use the streamreader or a simple sequential file access (Fileopen, Fileclose methods) to get a name and a file path out of a settings file. Then you could match up the function that you have selected with the exe file you've extracted from the settings file and run that exe.
Of course, if you wanted to pass things to the executable to get it to perform actions on your data, you'd need to build that in or have a separate text-file writing system to export the data...
It's all starting to get a bit complicated. There are a lot of things that you won't be able to foresee and then you'll wish you'd just replaced the exe.
zaza
well i guess you're right, it is starting to get complicated, and i guess replacing the exe is the way to go here, though i still cant understand, is it really impossible to import code from file into a sub or a function?
Once it is compiled into an executable, things don't exist in the same way. It doesn't just take a text file and rename the tag as ".exe". You can't just tack an extra Sub onto the end and expect things to work as normal. It'd involve editing the exe itself which is not a particularly enticing proposition. It really is easier to replace the file entirely.
Anyway, at some stage you'd have to stop executing the file in order to edit it so why not just replace it instead?
zaza
Hmm...
Have you ever heard of net bot's? the code of a net bot can be modified at runtime with outside scripts, the problem is i don't know what language are the bots written or anything else bout them, so i guess until i found out im stuck with replacing exe's
Well almost, It would similarly be built from scratch.Quote:
I think TTn means that user preferences, such as background colour, font size etc can be savd in an ini file and then read in when the user executes the app. That way, user-defined preferences can be maintained.
Indeed.Quote:
Anyway, at some stage you'd have to stop executing the file in order to edit it so why not just replace it instead?.
Sounds a lil suspicious to me.. and what are these net bots you are talking about?? Chat bots??? All chatbots do is post a text file or strings of data into random rooms... just a matter of loading a different text file with different responses...
Quote:
Originally Posted by Filik
I could be mistaken or drunk, but...
Move = Copy + Delete
Copy the file to the new location, then delete the original.
Also, if the source and destination is the same partition, rename might work as well.
Think he was using the move thing as an example of where the source code would have to be updated. Still, the nature of the example seems a bit... how shall I say... suspicious...
But anyway, I've written an application where I work and there are two exe's... the first one runs when the user clicks the icon on the desktop and displays a 'please wait' dialog and checks the server for an updated application - if there is an updated exe it downloads it and runs it, if there is no updated one then it runs the existing exe.
Another project I worked on I developed my own scripting language with a syntax similar to BASIC that didn't compile, instead it was 'interpreted'. This meant I could write add-ins and new functions at a later date. Obviously this code ran slower and there were lots of limitations.
You mentioned web bots... I think they're a bad comparison as their behaviour/construction is somewhat different to the VB app you described in your example.
If I were to write a web bot, it would use MSScript to do the update. It would output a pre-created script to a .vbs file, run it, and then the bot's process would terminate (leaving the script running), the script would download a new exe over the existing one. When done, it would run the updated exe. Upon running, the exe would delete the script file as the file would probably be outdated.
Any time you create a remote file managment system of any kind, (when I design it) it always has these three features: a) file transfer, b) file execution, and c) authentication.
Using some combination of those features, you'll always be able to remotely add/remove features.
This is a breach of the AUP by the way, just thought you guys should know that. :D
In alot of cases where constant update is required a scripting language is created for the program (an interpreted language), or just advanced settings, depending how dynamic these changes need to be.
I have once written a program to read a language sort of hybrid to the old mIRC, VB and C
a small game written in it
very ugly, but works and gets the job done. Gets very tricky to code the interpretor though, especially with loading of functions etc. But point being, these scripts can be modified during runtime of the application.Code:game{
$a{0}
$r{$rnd * 9 + 1}
ref{1}
$a{%a + 1}
ref{2}
input{guess the number between 1-10 to win}
$g{$input}
if(%g < 1){msgbox{number must be between 1-10}goto{2}}
if(%g > 10){msgbox{number must be between 1-10}goto{2}}
$d{%g - %r}
if(%d = 0){msgbox{you win! it took you %a attempts}if(%a < 3){msgbox{well done!}}goto{0}}
if(%d > 0){msgbox{[%g] lower}}
if(%d < 0){msgbox{[%g] higher}}
goto{1}
ref{0}
}
If you need to frequently recode your program, you need this to be either settings, or script.
replacement of exe's all the time is never nice, as wossname said, debug your programs before you release them to avoid bug fixing. If something MUST change in your program then it shouldn't be hard coded.