using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace PowerShellScript
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// ideiglenes fájl létrehozása
string tempFile = Path.GetTempFileName() + ".ps1";
File.WriteAllText(tempFile, @"
Write-Output 'PowerShell script...'
Start-Sleep -Seconds 5
");
// új ProcessStartInfo objektum létrehozása
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "powershell.exe";
startInfo.Arguments = "-ExecutionPolicy Bypass -File " + tempFile;
startInfo.Verb = "runas";
// futtatás rendszergazdaként
Process.Start(startInfo);
}
}
}