Skip to content

Commit

Permalink
adding null check in KillProcess task (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinhuafei authored and HongGit committed Sep 4, 2018
1 parent fbd1ca3 commit 1de1b31
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,27 @@
using(var results = searcher.Get())
{
var mo = results.Cast<ManagementObject>().FirstOrDefault();
Log.LogMessage("ExecutablePath is {0}", (string)mo["ExecutablePath"]);
if(mo != null && ((string)mo["ExecutablePath"]).StartsWith(ImagePath, StringComparison.OrdinalIgnoreCase))
if(mo != null)
{
p.Kill();
p.WaitForExit();
Log.LogMessage("{0} is killed", (string)mo["ExecutablePath"]);
break;
var path = (string)mo["ExecutablePath"];
var executablePath = path != null ? path : string.Empty;
Log.LogMessage("ExecutablePath is {0}", executablePath);
if(executablePath.StartsWith(ImagePath, StringComparison.OrdinalIgnoreCase))
{
p.Kill();
p.WaitForExit();
Log.LogMessage("{0} is killed", executablePath);
break;
}
}
}
}
}
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
Log.LogWarning(ex.Message);
}
return true;
]]>
Expand Down

0 comments on commit 1de1b31

Please sign in to comment.