Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b46aef3

Browse files
jpegtran errors with: "This program is blocked by group policy." #268
1 parent 8e13f0d commit b46aef3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/ImageProcessor.Web/PostProcessor/PostProcessor.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,27 @@ private static Task<PostProcessingResultEventArgs> RunProcess(string sourceFile,
9191
return tcs.Task;
9292
}
9393

94-
Process process = new Process
94+
try
9595
{
96-
StartInfo = start,
97-
EnableRaisingEvents = true
98-
};
96+
Process process = new Process
97+
{
98+
StartInfo = start,
99+
EnableRaisingEvents = true
100+
};
99101

100-
process.Exited += (sender, args) =>
101-
{
102-
tcs.SetResult(new PostProcessingResultEventArgs(sourceFile, length));
103-
process.Dispose();
104-
};
102+
process.Exited += (sender, args) =>
103+
{
104+
tcs.SetResult(new PostProcessingResultEventArgs(sourceFile, length));
105+
process.Dispose();
106+
};
105107

106-
process.Start();
108+
process.Start();
109+
}
110+
catch (System.ComponentModel.Win32Exception)
111+
{
112+
// Some security policies don't allow execution of programs in this way
113+
tcs.SetResult(null);
114+
}
107115

108116
return tcs.Task;
109117
}
@@ -155,7 +163,6 @@ private static string GetArguments(string sourceFile, long length)
155163
case ".gif":
156164
return string.Format(CultureInfo.CurrentCulture, "/c gifsicle --no-comments --no-extensions --no-names --optimize=3 --batch \"{0}\" --output=\"{0}\"", sourceFile);
157165
}
158-
159166
return null;
160167
}
161168
}

0 commit comments

Comments
 (0)