Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
1.2 kB
4
Indexable
Never
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "powercfg",
                    Arguments = "/GETACTIVESCHEME",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true,
                    Verb = "runas", // UAC prompt
                }
            };
            process.Start();
            string output = process.StandardOutput.ReadToEnd();
            process.WaitForExit();

            var match = Regex.Match(output, @"GUID: (.*)  \(");
            if (match.Success)
            {
                string guid = match.Groups[1].Value;
                Console.WriteLine($"Current power scheme GUID: {guid}");
            }
            else
            {
                Console.WriteLine("Could not find power scheme GUID");
            }
        }
    }
}