Skip to content

Commit

Permalink
Fix running empty command
Browse files Browse the repository at this point in the history
  • Loading branch information
qJake committed Jun 21, 2016
1 parent 1d1bb53 commit b8ac799
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions Source/PSRunner/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,36 @@ private void CommandBox_KeyDown(object sender, KeyEventArgs e)
// Execute the command on Enter, and check if we need to run as admin.
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
{
if (!string.IsNullOrWhiteSpace(CommandBox.Text))
{
var elevate = (ModifierKeys & Keys.Control) > 0 && (ModifierKeys & Keys.Shift) > 0;
SaveAutocomplete();
RunCommand(CommandBox.Text, elevate);
}
else
{
// If the box is empty, just open a PowerShell window.
var elevate = (ModifierKeys & Keys.Control) > 0 && (ModifierKeys & Keys.Shift) > 0;
RunCommand("-noexit", elevate);
}

// After executing (which is somewhat asynchronous), close the dialog.
DialogResult = DialogResult.OK;
Close();
RunCommand();
}
}

/// <summary>
/// Occurs when the user clicks the OK button.
/// </summary>
private void OKButton_Click(object sender, EventArgs e)
{
RunCommand();
}

private void RunCommand()
{
if (!string.IsNullOrWhiteSpace(CommandBox.Text))
{
var elevate = (ModifierKeys & Keys.Control) > 0 && (ModifierKeys & Keys.Shift) > 0;
SaveAutocomplete();
RunCommand(CommandBox.Text, false);
StartPowerShell(CommandBox.Text, elevate);
}
else
{
// If the box is empty, just open a PowerShell window.
var elevate = (ModifierKeys & Keys.Control) > 0 && (ModifierKeys & Keys.Shift) > 0;
StartPowerShell("-noexit", elevate);
}

// After executing (which is somewhat asynchronous), close the dialog.
DialogResult = DialogResult.OK;
Close();
}

/// <summary>
Expand All @@ -123,7 +124,7 @@ private void Escape_KeyUp(object sender, KeyEventArgs e)
/// </summary>
/// <param name="command">The command text to run.</param>
/// <param name="elevate">Whether or not to run the command in an elevated context.</param>
private void RunCommand(string command, bool elevate)
private void StartPowerShell(string command, bool elevate)
{
var p = new Process
{
Expand Down

0 comments on commit b8ac799

Please sign in to comment.