Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ private static SystemEnforcementMode GetAppLockerPolicy(string path, SafeHandle
}
finally
{
if (IO.File.Exists(testPathScript)) { IO.File.Delete(testPathScript); }

if (IO.File.Exists(testPathModule)) { IO.File.Delete(testPathModule); }
// Ok to leave the test scripts in the temp folder if they happen to be in use
// so that PowerShell will still startup.
PathUtils.TryDeleteFile(testPathScript);
PathUtils.TryDeleteFile(testPathModule);
}

s_cachedSaferSystemPolicy = result;
Expand Down
18 changes: 18 additions & 0 deletions 18 src/System.Management.Automation/utils/PathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,23 @@ internal static DirectoryInfo CreateTemporaryDirectory()
Directory.CreateDirectory(moduleDirectory.FullName);
return new DirectoryInfo(moduleDirectory.FullName);
}

internal static bool TryDeleteFile(string filepath)
{
if (IO.File.Exists(filepath))
{
try
{
IO.File.Delete(filepath);
return true;
}
catch (IOException)
{
// file is in use on Windows
}
}

return false;
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.