embedding executable as resource?

D

davis

Hi,

Let's say I have a project, and I add notepad.exe into it and set its
property as an embedded resource.

Now, when I build the project and run it, I want my code to launch
notepad.exe. How can I do this?

Thanks in advance,
Davsi
 
P

Peter Bromberg [C# MVP]

In the case of an unmanaged executable such as notepad.exe, you would need
to extract the bytes using GetManifestResourceStream, deposit the file on
the filesystem with the proper name and extension, and use the Process class
to execute it. For managed code, you could extract the bytes and load into
the AppDomain directly from memory.
-Peter
 
D

davis

Thanks Peter -- this is what I was afraid of. It would be an
unmanaged resource. Is there really *no other way*? Read the byte-
stream into memory and onto disk somewhere kind of defeats the whole
purpose of what I'm trying to accomplish. There is no way to have the
Process class execute on a byte[] array -- or any other solution?
 
A

Arne Vajhøj

davis said:
Thanks Peter -- this is what I was afraid of. It would be an
unmanaged resource. Is there really *no other way*? Read the byte-
stream into memory and onto disk somewhere kind of defeats the whole
purpose of what I'm trying to accomplish. There is no way to have the
Process class execute on a byte[] array -- or any other solution?

There is very little you can do.

The Windows operating system has some code to run executables.

If that support running from the file system and not from a
..NET embedded resource then ...

Arne
 
A

Arne Vajhøj

Paul said:
You're not actually aiming to do this with Notepad, are you? Copyright law
applies.

It would be a good guess that notepad is already on the target system
making it completely unnecessary to distribute it.

So it is probably just an example.

A shame - I would have loved to see the headlines
"xxx sued by Microsoft for distributing notepad to another
Windows system".

:)

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top