I'm using System.Diagnostics.Process.Start("my.exe");
to call an exe
Now that I can call my .exe, I want to bind/merge it into my c# application so that when I build my application, I can get the exe built inside the projectName\Debug\builtProgram.exe or any other way to finally get a single exe file with my desired exe file inside it.
For example, consider I create a program A and I want it to encase it inside another program B which contains only one button 'Launch Program A'. And let's say prog开发者_运维百科ram B is portable - with a single exe file. Question is - How to create program B?
You can include the .exe as an embedded resource in your .NET assembly, and then dump it to disk to a temporary file on startup:
var thisAssembly = Assembly.GetExecutingAssembly();
var executableFileName = Path.GetTempFileName();
using(resourceStream = thisAssembly.GetManifestResourceStream("name.of.resource.exe"))
using(fileStream = File.Create(executableFileName))
{
resourceStream.CopyTo(fileStream);
}
Then you call it just like you would normally.
Process.Start(executableFileName);
Since it's hard for me to extract embedded resource.
Here's my answer:
public static void getbytez(string file, string outp)
{
byte[] buffer = File.ReadAllBytes(file);
string base64Encoded = Convert.ToBase64String(buffer);
File.WriteAllText(outp+ ".txt", base64Encoded);
//copy the base64encoded text.
//Code by CursedGmod. credit me please :D
}
public static void extract2idk(string txtfile, string outp, string exten)
{
byte[] gu = Convert.FromBase64String(txtfile);
// use it like this: byte[] gu = Convert.FromBase64String(your base64 converted text that you copied from the txt file);
// or use File.ReadAllText if you're making a stub builder.
File.WriteAllBytes(outp + exten, gu);
Process.Start(Environment.ExpandEnvironmentVariables("%TEMP%") + Path.GetFileName(txtfile));
}
精彩评论