-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSInterface.cs
38 lines (32 loc) · 1.13 KB
/
PSInterface.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Management;
namespace powerLabel
{
public class PSInterface
{
public static ManagementObjectCollection RunObjectQuery(string command)
{
ManagementScope scope = new ManagementScope();
scope.Connect();
//Query system for Operating System information
ObjectQuery query = new ObjectQuery(command);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
return queryCollection;
}
public static void RunPowershell(string command)
{
var processInfo = new System.Diagnostics.ProcessStartInfo
{
Verb = "runas",
LoadUserProfile = true,
FileName = "powershell.exe",
Arguments = command,
RedirectStandardOutput = false,
UseShellExecute = true,
CreateNoWindow = true
};
var p = System.Diagnostics.Process.Start(processInfo);
p.WaitForExit();
}
}
}