Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fa532942
Commit
fa532942
authored
Oct 23, 2018
by
Jeremy Kloth
Committed by
Steve Dower
Oct 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34980: P/Invoke QueryFullProcessImageName to get process names (GH-9901)
parent
4f399be0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
10 deletions
+25
-10
PCbuild/pyproject.props
PCbuild/pyproject.props
+25
-10
No files found.
PCbuild/pyproject.props
View file @
fa532942
...
@@ -109,19 +109,34 @@
...
@@ -109,19 +109,34 @@
<FileName
Required=
"true"
/>
<FileName
Required=
"true"
/>
</ParameterGroup>
</ParameterGroup>
<Task>
<Task>
<Code
Type=
"Fragment"
Language=
"cs"
>
<Using
Namespace=
"System.Diagnostics"
/>
<Using
Namespace=
"System.IO"
/>
<Using
Namespace=
"System.Runtime.InteropServices"
/>
<Using
Namespace=
"System.Text"
/>
<Code
Type=
"Method"
Language=
"cs"
>
<![CDATA[
<![CDATA[
string fullPath = System.IO.Path.GetFullPath(FileName);
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
Log.LogMessage("Looking for " + fullPath, MessageImportance.Normal);
public static extern bool QueryFullProcessImageName([In]IntPtr hProcess, [In]int dwFlags,
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) {
[Out]StringBuilder lpExeName, ref int lpdwSize);
try {
public override bool Execute() {
Log.LogMessage("Found running process: " + p.MainModule.FileName, MessageImportance.Low);
string fullPath = Path.GetFullPath(FileName);
if (fullPath.Equals(System.IO.Path.GetFullPath(p.MainModule.FileName), StringComparison.OrdinalIgnoreCase)) {
Log.LogMessage("Looking for " + fullPath, MessageImportance.Normal);
Log.LogMessage("Terminating " + p.MainModule.FileName, MessageImportance.High);
foreach (Process p in Process.GetProcesses()) {
p.Kill();
try {
int pathLength = 32768;
StringBuilder pathBuilder = new StringBuilder(pathLength);
if (QueryFullProcessImageName(p.Handle, 0, pathBuilder, ref pathLength)) {
string exeName = Path.GetFullPath(pathBuilder.ToString());
Log.LogMessage("Found running process: " + exeName, MessageImportance.Low);
if (fullPath.Equals(exeName, StringComparison.OrdinalIgnoreCase)) {
Log.LogMessage("Terminating " + exeName, MessageImportance.High);
p.Kill();
}
}
} catch {
}
}
} catch {
}
}
return true;
}
}
]]>
]]>
</Code>
</Code>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment