Create an .exe at runtime with .NET 2.0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

It is possible to create an .exe file at runtime with .NET 2.0? I would like
to create a .exe that should include:

- an encrypted file
- a simple winform to decrypt the included encrypted file (already compiled
as .exe)


When the user opens the created exe file, the simple winform should be
started so the user can decrypt the included file.

Thanks and Regards,
andersch
 
Hi Andersch,

Based on my understanding, you'd like to create an executable file at
runtime with .NET 2.0, which in turn lauches an existing simple winform
application to decrypt an encrypted file. If I'm off base, please feel
free to let me know.

The .NET Framework includes a mechanism called the Code Document Object
Model (CodeDOM) that enables developers of programs that emit source code
to generate source code in multiple programming languages at run time,
based on a single model that represents the code to render.

The System.CodeDom namespace defines types that can represent the logical
structure of source code, independent of a specific programming language.
The System.CodeDom.Compiler namespace defines types for generating source
code from CodeDOM graphs and managing the compilation of source code in
supported languages.

FYI, The .NET Framework includes code generators and code compilers for C#,
JScript, and Visual Basic.

For more information on CodeDOM and how to use it, you may visit the
following link.
'Dynamic Source Code Generation and Compilation'
http://msdn2.microsoft.com/en-us/library/650ax5cx.aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Linda

Thank you for your answer.

Can you show me a simple code example please? I've searched without sucess
for an example how I can compile a new executable with the encrypted file
(resource file) and the already compiled winform (.exe).

Thanks and Regards,
andersch
 
Hi Andersch,

Sorry for my delayed reply.

Firstly, creating an executable file at runtime means you should create a
program first, which creates the executable file when it runs.

In your practice, since you already have a WinForm application to decrypt
the encrypted file, you could just write a program A to lanuch the existing
WinForm application and decypt the encrypted file. You needn't create
another executable file B which in turn lauches the existing WinForm
applicaion, when you run program A.

If you do need to do like that, a simple way is to write the code of the
program B first in VS, and then translate the code into CodeDOM, following
the MSDN sample I suggest to you in my first reply. It should not be a
difficult thing.

In additon, I don't think you need to embed the encrypted file into the
resources of the program B. The encrypted file can be a separate file.

Hope this helps.

If you have any question, please feel free to let us know.

BTW, I will be on a long vacation from the next Monday to Friday. During my
leave, my team mates will follow up with you and it may not in time. Sorry
for the inconvenience it may bring to you!



Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Michael,

Since my colleague Linda is on vacation this week, I will continue to work
with you.

How about this issue now? Does Linda's reply make sense to you? If you
still need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Jeffry

Sorry for the delay. I was very busy this week!

So, in the meantime I've found out how I can add the precompiled winform
(*.exe) and the encrypted file as a ressource.

CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();

if (provider.Supports(GeneratorSupport.Resources))
{
// Set the embedded resource file of the assembly.
cp.EmbeddedResources.Add("DecryptForm.exe");
cp.EmbeddedResources.Add("encryptedFile.enc");
}


But how can I access the resource 'DecryptForm.exe'? I would like to start
the form in the memory (not saving on the disk), so that the user can
decrypt the resource 'encryptedFile.enc'. Do you have a code example?


Thanks,
Dominik
 
Hi Dominik,

I am back from my vocation.

To access an embedded resource, we could use
Assembly.GetManifestResourceStream method.

If you'd like the executable that is created at runtime to access the
embedded resource, you should translate the code to CodeDOM.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Dominik,

How about the problem?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Back
Top