Metrolog / ITG.MetrControl.2.3

.msi пакет для распространения в рамках домена продукта АИС Метроконтроль версии 2.3
1 stars 0 forks source link

Найти способ спрятать окно powershell при запуске приложения #11

Closed sergey-s-betke closed 11 years ago

sergey-s-betke commented 11 years ago

Пока вижу следующий способ: создать управляемое приложение на C# (или на чём другом - посмотрю, где лучше и прозрачнее обёртка для обработки командной строки). И либо непосредственно в этом приложении и переработаю свой скрипт (чего не хотелось бы), либо же в приложении воспользуюсь объектом powershell.

namespace HostSamples {
  using System;
  using System.Management.Automation;  // Windows PowerShell namespace.

  /// <summary>
  /// This class defines the main entry point for a host application that 
  /// synchronously invokes the following pipeline: 
  /// [Get-Process]
  /// </summary>
  internal class HostPS1
  {
    /// <summary>
    /// The PowerShell object is created and manipulated within the 
    /// Main method.
    /// </summary>
    /// <param name="args">This parameter is not used.</param>
private static void Main(string[] args)
{
  // Call the PowerShell.Create() method to create an 
  // empty pipeline.
  PowerShell ps = PowerShell.Create();

  // Call the PowerShell.AddCommand(string) method to add 
  // the Get-Process cmdlet to the pipeline. Do 
  // not include spaces before or after the cmdlet name 
  // because that will cause the command to fail.
  ps.AddCommand("Get-Process");

  Console.WriteLine("Process                 Id");
  Console.WriteLine("----------------------------");

  // Call the PowerShell.Invoke() method to run the 
  // commands of the pipeline.
    foreach (PSObject result in ps.Invoke())
  {
    Console.WriteLine(
            "{0,-24}{1}",
            result.Members["ProcessName"].Value,
            result.Members["Id"].Value);
  } // End foreach.
    } // End Main.
  } // End HostPs1.
  }
sergey-s-betke commented 11 years ago

Пошёл другим путём - переписал загрузчик на c# полностью, без вызова powershell.