27089 total geeks with 3528 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
timsattemme
<ul><li><str ong><a href="http:/ /www.ywjx8.c om/">cheap wedding dresses</a>< /strong> </l i><li><stron g><a href="http:/ /www.ywjx8.c om/">Sexy Beach Wedding Dresses Sale</a></st rong> </li>< li><strong>< a href="http:/ /www.ywjx8.c om/">cheap wedding dresses</a>< /st
timsattemme
[b][url=http ://www.watch esiphone5.co m/]replica o<strong><a href="http:/ /www.watches iphone5.com/ ">replica omega watches</a>< /strong> <br > <strong><a href="http:/ /www.watches iphone5.com/ ">replica cartier watches</a>< /strong> <br >
timsattemme
<strong><a href="http:/ /www.watches iphone5.com/ ">cartier watches</a>< /strong> | <strong><a href="http:/ /www.watches iphone5.com/ ">rolex watches</a>< /strong> | <strong><a href="http:/ /www.watches iphone5.com/ ">omega watches</a>< /strong> <br > <title>Longi
timsattemme
[b][url=http ://www.copyr olexdaytona. com/]rolex new 2013[/url][/ b] [b][url=h ttp://www.co pyrolexdayto na.com/]role x basel[/url][ /b] [b][url=http ://www.copyr olexdaytona. com/]rolex Y<br><strong ><a href="http:/ /www.copyrol exdaytona.co m/">rolex new 2013</a></st
timsattemme
<br><strong> <a href="http:/ /www.copyrol exdaytona.co m/">rolex new 2013</a></st rong> <stron g><a href="http:/ /www.copyrol exdaytona.co m/">rolex basel</a></s trong> <br>< strong><a href="http:/ /www.copyrol exdaytona.co m/">rolex Yacht-Master II</a></stro ng> <br><b

Donate
Donate and help us fund new challenges
Donate!
Due Date: Oct 31
October Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
SKYPE has the HOTS
for my NAKED WIFE
Time to test your
sarcasm detectors:
It"s the UN"s
global comms
shakeup
extravaganza!
Wanna see how
Russia et al hope
to shape the
internet? ITU opens
up (a little more)
t
Google CEO Larry
Page gives Sundar
Pichai keys to the
kingdom
Cheapo telcos fined
for their cheapo
security: Financial
records on 305,000
people spill
LG taps TSMC to
bake its first-ever
mobile chip
FCC: You"ll have to
wait even longer
for faster wireless
broadband
Breaking news:
Google exec in
terrifying SKY
PLUNGE DRAMA
Revealed: The
amazing magical
innovation in the
iPad Mini 3 ? a
lick of paint
Silicon Valley
scrooges paid staff
$1.21 an hour in a
122-hour week
Slashdot
Peter Kuran:Visual
Effects Artist and
Atomic Bomb
Archivist
OwnCloud Dev
Requests Removal
From Ubuntu Repos
Over Security Holes
Microsoft Now Makes
Money From Surface
Line, Q1 Sales
Reach Almost $1
Billion
Days After
Shooting, Canada
Proposes New
Restrictions On and
Offline
AT&T Locks
Apple SIM Cards On
New iPads
Passwords: Too Much
and Not Enough
Verizon Injects
Unique IDs Into
HTTP Traffic
Secretive Funding
Fuels Ongoing Net
Neutrality
Astroturfing
Controversy
A Low Cost, Open
Source Geiger
Counter (Video)
Computer Scientist
Parachutes From
135,908 Feet,
Breaking Record
Article viewer

Included Dlls with your exe without needing an install



Written by:Pertinax
Published by:Codybob90
Published on:2009-05-06 18:18:31
Topic:Dot.Net
Search OSI about Dot.Net.More articles by Pertinax.
 viewed 5030 times send this article printer friendly

Digg this!
    Rate this article :
I created a WinForms utility that depended on some DLLs and wanted the user to be able to just download and click on the exe to run the app. Usually if your exe needs some other files you wrap things up into a package and the user has to go through an install process. This takes time and forces the user to unistall if they don't want the program after it's served its purpose. I didn't like this and found a way to embed the files I needed into my exe and extract and link them when the program ran.

.Net won't let you include a dll as a resource. The way around this is to push your dll into an image and include the image in the exe. If you skip the image header .net won't complain. You just need to mark the beginning and end of the dll binary data so you know where to start and stop when extracting it.

Here is a program I wrote that makes it easy to push your file into an image.
http://www.securitysoftware.cc/Programs/FileMerge.exe

Once you have done this you can use the following methods to save the image to a file and then extract the dll from the image.

//Save image to a file
PictureBox.Image.Save("C:\\temp_file");

//Extract the dll
ExtractFile("C:\\temp_file", "C:\\MyDll.dll", "^^^^^^^^^^", "**********");


//This method extracts the dll from the image file and saves it with the name given
public static bool ExtractFile(string sourceFile, string destination, string startMarker, string endMarker)
{

       int filestart = 0;
       int fileend = 0;

       int marker_position = 0;

       FileInfo finfo = new FileInfo(sourceFile);

       FileStream fs = new FileStream(sourceFile, FileMode.Open);

       //Create Buffer
       byte[] buff = new byte[finfo.Length];

       //Read file contents
       fs.Read(buff, 0, (int)finfo.Length);

       //Close file
       fs.Close();

       //Get file start position
       for(int bytecnt = 0; bytecnt < buff.Length; bytecnt++)
       {
           //Look for startMarker
           while (buff[bytecnt + marker_position] == startMarker[marker_position++])
           {
               if (marker_position == startMarker.Length)
               {
                   filestart = bytecnt + marker_position;
                   break;
               }
           }

           marker_position = 0;
       }

       //Find end position
       for (int bytecnt = filestart; bytecnt < buff.Length; bytecnt++)
       {
           //Look for startMarker
           while (buff[bytecnt + marker_position] == endMarker[marker_position++])
           {
               if (marker_position == startMarker.Length)
               {
                   fileend = bytecnt;
                   break;
               }
           }

           marker_position = 0;
       }

       //Save to file
       fs = new FileStream(destination, FileMode.Create);
       fs.Write(buff, filestart, fileend - filestart);
       fs.Close();

       return File.Exists(destination);
}




Did you like this article? There are hundreds more.

Comments:
Anonymous
2009-06-30 14:53:14
Hi
This is very good idea to let end user free from installations and addins... but when you programming in .Net the user must install the .Net framework first. anyway take a look at product named thinstall or vmware virtualisation suit you may find them useful too.
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Blogs: (People who have posted blogs on this subject..)
bb
ASP.NET RadioButton GroupName when inside a Repeater on Sun 10th Jun 8am
I was thankful on finding this nugget of code, which makes the groupname work out when slamming in radiobuttons in an asp.net repeater. http://www.codeguru.com/csharp/csharp/cs _controls/custom/article.php/c12371/


     
Your Ad Here
 
Copyright Open Source Institute, 2006