try {
WindowsIdentity.RunImpersonated(_safeAccessTokenHandle, () => {
// This will throw if the impersonation fails
//string impersonatedUser = WindowsIdentity.GetCurrent().Name;
//Console.WriteLine("Impersonation successful, current user: " + impersonatedUser);
try {
string securePath = "";
if (!Directory.Exists(securePath)) {
throw new UnauthorizedAccessException($"Access to {securePath} was denied.");
}
} catch {
throw;
}
});
} catch (Exception ex) {
Console.WriteLine($"Impersonation validation failed: {ex.Message}");
Dispose();
// Re-throw to ensure the exception is handled by the caller
throw;
}
try {
WindowsIdentity.RunImpersonated(_safeAccessTokenHandle, () => {
// This will throw if the impersonation fails
//string impersonatedUser = WindowsIdentity.GetCurrent().Name;
//Console.WriteLine("Impersonation successful, current user: " + impersonatedUser);
try {
string securePath = "";
if (!Directory.Exists(securePath)) {
throw new UnauthorizedAccessException($"Access to {securePath} was denied.");
}
} catch {
throw;
}
});
} catch (Exception ex) {
Console.WriteLine($"Impersonation validation failed: {ex.Message}");
Dispose();
// Re-throw to ensure the exception is handled by the caller
throw;
}