Hello I figured out how to make a C# File that would rewrite a bat file in to a exe.
I did this because
1. I noticed a lot of pay for bat to exe programs.
2. I was bored.
this C# File uses the Text Props
Make a Text called Props and put this in it if you want it to work.
E:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/csc.exe
(The second first line is your csc path Auto makes the Props.txt now type your path into the exe now and it will be saved. change it if you need to)
This file cannot compile files with a " "(Space) in the name!
the CS file is
(Edit it can use C# commands by putting ": " before the c# command in the bat file.)
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Bat
{
public class EXE
{
[DllImport("msvcrt.dll")]
public static extern int system(string cmd);
public static int Exit()
{
try
{
return 1;
}
catch
{
return -1;
}
}
public static void Main()
{
if (File.Exists("Props.txt")) {}else{Console.Write("CSC Path: "); string Pasd = Console.ReadLine(); StreamWriter GAS = new StreamWriter("Props.txt"); GAS.Write(Pasd); GAS.Close(); system("cls");}
StreamReader NI = new StreamReader("Props.txt");
string CSCP = NI.ReadLine();
NI.Close();
if (CSCP.Length <= 1) {Console.WriteLine("Enter your csc.exe path in Props.txt");Console.ReadKey(); Exit();}
int Prop1 = 34;
int Prop2 = 58;
int Prop3 = 59;
char QU = (char)(Prop1);
char BS = (char)(Prop2);
char SC = (char)(Prop3);
system("Title Bat to Exe Compiler");
Console.Write("Bat File: ");
string BATt = Console.ReadLine();
string BAT = BATt+".bat";
StreamReader AddEnd = new StreamReader(@BAT);
string ENDFILE = AddEnd.ReadToEnd();
AddEnd.Close();
StreamWriter Adding = new StreamWriter(@BAT);
Adding.Write(ENDFILE);
Adding.Write(Adding.NewLine);
Adding.Write("THEEND");
Adding.Close();
StreamReader B = new StreamReader(@BAT);
int BN = 0;
int GO = 1;
while (GO == 1)
{
system("CLS");
Console.WriteLine("Compiling.");
string BaT = B.ReadLine();
string BPa = BAT+BN+".txt";
StreamWriter BB = new StreamWriter(@BPa);
BB.Write(BaT);
BB.Close();
BN++;
system("CLS");
Console.WriteLine("Compiling..");
if (BaT == "THEEND")
{
GO++;
}
system("CLS");
Console.WriteLine("Compiling...");
}
B.Close();
StreamWriter BC = new StreamWriter("BAT.cs");
int NB = 0;
while (NB <= BN-2)
{
system("CLS");
Console.WriteLine("Compiling.");
string BPA = BAT+NB+".txt";
StreamReader BR = new StreamReader(@BPA);
string bat = BR.ReadLine();
BR.Close();
system("CLS");
Console.WriteLine("Compiling..");
if (NB == 0)
{
char bbB = bat[0];
if (bbB == BS)
{
string bs = BS+" ";
string Command = bat.Replace(bs, " ");
BC.Write(Command);
}
BC.Write("using System.Runtime.InteropServices"+SC+" namespace BAT { public class Write { [DllImport("+QU+"msvcrt.dll"+QU+")] public static extern int system(string cmd)"+SC+" public static void Main() {");
BC.Write(BC.NewLine);
}
else
{
char bbb = bat[0];
if (bbb == BS)
{
string bs = BS+" ";
string Command = bat.Replace(bs, " ");
BC.Write(Command);
}
else
{
BC.Write("system("+QU+bat+QU+")"+SC);
}
}
NB++;
system("CLS");
Console.WriteLine("Compiling...");
}
BC.Write("}}}");
BC.Close();
int NN = 0;
while (NN <= BN-1)
{
string BPAA = BAT+NN+".txt";
File.Delete(BPAA);
NN++;
}
string CSCC = CSCP+" /Nologo /out:"+BATt+".exe BAT.cs";
system("cls");
system(CSCC);
File.Delete("BAT.cs");
Console.WriteLine(BAT+" has been made in to "+BATt+".exe.");
system("pause");
StreamWriter Ax = new StreamWriter(@BAT);
Ax.Write(ENDFILE);
Ax.Close();
}
}
}
if you want to test it you can that is why I posted it here. =P
Oh and at the end of the bat file you have to have the word exit otherwise this won't work.
The above statement is false I have changed it so it works without the exit command written in.
and the goto or set commands will not work in this exe maker.
Examples
@echo off
echo Hello
pause
becomes
using System.Runtime.InteropServices; namespace BAT { public class Write { [DllImport("msvcrt.dll")] public static extern int system(string cmd); public static void Main() {
system("@echo off");system("echo Hello");system("pause");
}}}
and
@echo off
: int GO = 1;
: while (GO == 1)
: {
echo Hello
: }
pause
becomes
using System.Runtime.InteropServices; namespace BAT { public class Write { [DllImport("msvcrt.dll")] public static extern int system(string cmd); public static void Main() {
system("@echo off"); int GO = 1; while (GO == 1) {system("echo Hello"); }system("pause");
}}}
and one last example
: using System; using System.IO;
@echo off
title Make File
: int B = 1;
: if (B == 1) {
: Console.Write("File - ");
: string F = Console.ReadLine();
: File.Create(F); }
: else {
set /p F=File -
set /a L=%F%
: }
becomes
using System; using System.IO; using System.Runtime.InteropServices; namespace BAT { public class Write { [DllImport("msvcrt.dll")] public static extern int system(string cmd); public static void Main() {
system("@echo off"); system("title Make File"); int B = 1; if (B == 1) { Console.Write("File - "); string F = Console.ReadLine(); File.Create(F); } else { system("set /p F=File - "); system(""set /a L=%F%); }
}}}