Skip to content

Commit

Permalink
Don't run wmic multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
jjxtra committed Apr 16, 2020
1 parent 13859d9 commit a7a085a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion IPBanCore/Core/Utility/OSUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ private static void LoadVersionFromWmic()

Logger.Info("Attempting to load os info from wmic");

// attempt to run wmic to generate the info we want
StartProcessAndWait(5000, "cmd", "/C wmic path Win32_OperatingSystem get Caption,Version /format:table > \"" + tempFile + "\"");

// try up to 10 times to read the file
for (int i = 0; i < 10; i++)
{
try
{
StartProcessAndWait(5000, "cmd", "/C wmic path Win32_OperatingSystem get Caption,Version /format:table > \"" + tempFile + "\"");
string[] lines = File.ReadAllLines(tempFile);
ExtensionMethods.FileDeleteWithRetry(tempFile);
if (lines.Length > 1)
Expand Down

0 comments on commit a7a085a

Please sign in to comment.