Skip to content

Commit

Permalink
Added support for batch scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Goodwin committed Nov 20, 2016
1 parent 8b9b679 commit 7772920
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 11 deletions.
Binary file modified Make-EXE/Assets/MakeReg.reg
Binary file not shown.
Binary file added Make-EXE/Assets/gear_32xLG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions Make-EXE/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
xmlns:local="clr-namespace:Make_EXE"
mc:Ignorable="d"
Title="Make EXE" Height="250" Width="300" Loaded="Window_Loaded" Icon="BuildSolution.ico">
<Grid Background="Black">
<TextBlock Foreground="White" Margin="10,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="25">Make EXE</TextBlock>
<Grid Background="Black" >
<Image Source="Assets/gear_32xLG.png" Opacity="0.15" Margin="20"></Image>
<TextBlock Foreground="White" Margin="10,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="25" FontFamily="Source Code Pro" FontWeight="Bold">Make EXE</TextBlock>
<Button Name="buttonInfo" Background="Transparent" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,10,10,0" Cursor="Hand" ToolTip="Info" Click="buttonInfo_Click" BorderBrush="{x:Null}">
<Image Source="Assets/StatusHelp_grey_32xLG.png" Height="20" Width="20"></Image>
</Button>
Expand Down
4 changes: 2 additions & 2 deletions Make-EXE/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ private void buttonInstall_Click(Object sender, RoutedEventArgs e)
File.Copy(Application.ResourceAssembly.ManifestModule.Assembly.Location, installedPath, true);
buttonInstall.IsEnabled = false;
buttonRemove.IsEnabled = true;
MessageBox.Show("Install completed! Now right-click some PowerShell files! If the 'Make EXE' option isn't showing up, reset your program defaults and reinstall Make-EXE.", "Install Completed", MessageBoxButton.OK, MessageBoxImage.Information);
MessageBox.Show("Install completed! If the 'Make EXE' option isn't showing up, reset your program defaults and reinstall Make-EXE.", "Install Completed", MessageBoxButton.OK, MessageBoxImage.Information);
}

private void buttonRemove_Click(Object sender, RoutedEventArgs e)
{
Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Make-EXE", true);
var psi = new ProcessStartInfo("cmd.exe", @"/c reg.exe delete HKCR\.ps1\shell\MakeEXE /f&reg.exe delete HKCR\Microsoft.PowerShellScript.1\Shell\MakeEXE /f&reg.exe delete HKCR\Applications\powershell_ise.exe\shell\MakeEXE /f");
var psi = new ProcessStartInfo("cmd.exe", @"/c reg.exe delete HKCR\.ps1\shell\MakeEXE /f&reg.exe delete HKCR\Microsoft.PowerShellScript.1\Shell\MakeEXE /f&reg.exe delete HKCR\Applications\powershell_ise.exe\shell\MakeEXE /f&reg.exe delete HKCR\batfile\shell\MakeEXE /f");
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.Verb = "runas";
var proc = Process.Start(psi);
Expand Down
3 changes: 3 additions & 0 deletions Make-EXE/Make-EXE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
<ItemGroup>
<Resource Include="Assets\StatusHelp_grey_32xLG.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\gear_32xLG.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.1.29.4\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.1.29.4\build\dotnet\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
20 changes: 16 additions & 4 deletions Make-EXE/Maker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static void Main(string[] args)
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var resources = assembly.GetManifestResourceNames();
Console.Title = resources[0];
Console.WriteLine("Extracting resources...");
Console.WriteLine("Extracting resource files...");
var workingDir = "";
var count = 0;
while (workingDir == "")
Expand All @@ -20,16 +20,21 @@ static void Main(string[] args)
{
Directory.Delete(System.IO.Path.GetTempPath() + "Make-EXE" + count, true);
}
workingDir = System.IO.Path.GetTempPath() + "Make-EXE" + count + @"\";
Directory.CreateDirectory(workingDir);
else
{
workingDir = System.IO.Path.GetTempPath() + "Make-EXE" + count + @"\";
Directory.CreateDirectory(workingDir);
}
}
catch
{
count++;
}
}
count = 0;
foreach (var resource in resources)
{
Console.WriteLine("Extracting file " + count + " of " + resources.Length + "...");
using (var rs = assembly.GetManifestResourceStream(resource))
{
using (var fs = new FileStream(workingDir + resource, FileMode.Create))
Expand All @@ -41,7 +46,14 @@ static void Main(string[] args)
}
}
Console.WriteLine("Starting up...");
System.Diagnostics.Process.Start("powershell.exe", "-executionpolicy bypass -file \"" + workingDir + resources[0] + "\"");
if (Path.GetExtension(resources[0]).ToLower() == ".ps1")
{
System.Diagnostics.Process.Start("powershell.exe", "-executionpolicy bypass -file \"" + workingDir + resources[0] + "\"");
}
else if (Path.GetExtension(resources[0]).ToLower() == ".bat")
{
System.Diagnostics.Process.Start("cmd.exe", "/c " + resources[0]);
}
}
}
}
4 changes: 2 additions & 2 deletions Make-EXE/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.3.0")]
[assembly: AssemblyFileVersion("0.9.3.0")]
[assembly: AssemblyVersion("0.9.4.0")]
[assembly: AssemblyFileVersion("0.9.4.0")]
[assembly: Guid("eea5aba0-927d-44ef-95ff-b4eccca23cfe")]

2 changes: 1 addition & 1 deletion Make-EXE/Windows/AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Border Margin="0,67,0,35" BorderBrush="DimGray" BorderThickness="1">
<ScrollViewer>
<TextBlock TextWrapping="Wrap">
<Run Text="This app helps you easily create an EXE from a PowerShell script file. It adds 'Make EXE' as an option when right-clicking a PowerShell file in Windows Explorer."></Run>
<Run Text="This app helps you easily create an EXE from a PowerShell or batch script file. It adds 'Make EXE' as an option when right-clicking a PS/BAT script file in Windows Explorer."></Run>
<LineBreak></LineBreak>
<LineBreak></LineBreak>
<Run Text="Third-party libraries used: Fody/Costura"></Run>
Expand Down

0 comments on commit 7772920

Please sign in to comment.