Click here to Skip to main content
12,757,627 members (38,724 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


19 bookmarked
Posted 13 Aug 2009

Transferring Data to the New EXE

, 13 Aug 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Have you ever wanted to change variables without rebuilding?


Changing one or more variables in your application without even rebuilding might sometimes be a lifesaver for developers and users. Let's assume that you coded an application which uploads files to a server but you want to enable your users to write their server info on their own. You probably can do this by adding a registry key or an application setting. But what if the user wants this application to be portable, to be used on other PCs or not to save anything to the PC. With this code, I am going to explain it in this article and you will be able to do all these. 

In order to use this code, you only need to include the "TransferData.cs" to your project and create an instance of it. After creating an instance of the class, it is actually straight forward thanks to IntelliSense.

Anyway, I included a demonstration Editor (which makes changes on the stub) and the output stub. Output stub is basically your application. 


I needed a solution like this to use in my project and I couldn't find a satisfactory solution, so I coded it myself and I thought someone might need this code someday. So, here it is.

Using the Code

How It Works?

  • Editor reads the output stub from the resource and appends the separator and then the data you entered. PE files aren't affected when you append data at the end of the file, therefore your program will work without a problem. If you open the output file and the stub file on hex editor and compare them, you will see something like this. If you want, you can encrypt the string before you write it to the file.

  • At runtime, your output reads the data from end of file and processes it. This way, you can change the variables in your application without the need of rebuilding it or make your users be able to customize your application. There are infinite fields of use.

Editor Side (Writing the Data) 

The editor writes the variables (of course as one string) to the end of the file so that the application will be able to read them at runtime. As most of you know, you can append data to the end of an PE file and the PE file will work without a problem. In order to write data to the output, you should first create an instance of the class with:

TransferData.TransferData td = new TransferData.TransferData();

and then write the data with:

td.Write(Resource.Output, "output-new.exe", strToWrite, strSeperator); 

Resource.Output is your output stub which you included into your project, the rest is self explanatory. 

Application Side (Reading the Data)

Your application reads the variables from itself at runtime. In order to get the transferred data, you need to create an instance of the class with:

TransferData.TransferData td = new TransferData.TransferData();

and then read the data with:

td.Read(Application.ExecutablePath, strSeperator);

Read method returns the data as string so that you can work on it easily. If the application is not able to read the data correctly, it doesn't throws an exception. It just returns an "ERROR OCCURED" string. An important point is that the separator string (strSeperator) should be the same as the separator string you used in the editor.

Points of Interest

Here are some things that you should be careful about when using this code:

  • Only use ASCII characters in your data.
  • Your separator and data should not exceed 200 characters. You can actually change this limit by changing the buffer length on Read() method. Its length should be LIMIT+20.
  • Your data should never contain the separator in itself.


  • 14th August, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Turkey Turkey
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralGood share! Pin
alrsds19-Sep-09 21:52
memberalrsds19-Sep-09 21:52 
GeneralA few things need to be discussed... Pin
supercat914-Aug-09 6:13
membersupercat914-Aug-09 6:13 
GeneralGreat!May be we can use it do other thing Pin
guaike14-Aug-09 4:44
memberguaike14-Aug-09 4:44 
GeneralRe: Great!May be we can use it do other thing Pin
SimpleData14-Aug-09 4:45
memberSimpleData14-Aug-09 4:45 
GeneralMy vote of 1 Pin
Michael E. Jones14-Aug-09 0:23
memberMichael E. Jones14-Aug-09 0:23 
GeneralRe: My vote of 1 Pin
Jefis14-Aug-09 0:38
memberJefis14-Aug-09 0:38 
GeneralRe: My vote of 1 Pin
SimpleData14-Aug-09 0:41
memberSimpleData14-Aug-09 0:41 
GeneralRe: My vote of 1 Pin
Michael E. Jones14-Aug-09 1:16
memberMichael E. Jones14-Aug-09 1:16 
GeneralRe: My vote of 1 Pin
SimpleData14-Aug-09 1:18
memberSimpleData14-Aug-09 1:18 
GeneralRe: My vote of 1 Pin
Michael E. Jones14-Aug-09 2:04
memberMichael E. Jones14-Aug-09 2:04 
GeneralRe: My vote of 1 Pin
Johnno7417-Aug-09 17:10
memberJohnno7417-Aug-09 17:10 
GeneralRe: My vote of 1 Pin
Tom Spink18-Aug-09 11:34
memberTom Spink18-Aug-09 11:34 
AnswerMy vote + Pin
Member 28788514-Sep-09 21:39
memberMember 28788514-Sep-09 21:39 
GeneralRe: My vote + Pin
Tom Spink5-Sep-09 0:17
memberTom Spink5-Sep-09 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 14 Aug 2009
Article Copyright 2009 by SimpleData
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid