Originally Posted by
ecaep42
So then how are you supposed to target the application you want to suspend and resume?
By process name, like mentioned above.
Code:
For each pp as Process in Process.GetProcesses()
If pp.ProcessName = "TargetProcessName" Then '// Without the extension! Process.ProcessName doesn't include extension.
''This is our target process! Store a reference to it.
End If
Next pp
''No need to loop over all of them like that. Just use .GetProcessesByName() like OP said. However, it does return an array, so, your choice. Also did it for consistency between the 3 examples.
"main window title". Obviously this only works if the process has a Window displayed, and hopefully only 1.
Code:
For each pp as Process in Process.GetProcesses()
If pp.MainWindowTitle = "TargetProcessWindowTitle" Then
''This is our target process! Store a reference to it.
End If
Next pp
''Tip: You might not have to (or be able to) use the entire Window Title -> .Contains(), .StartsWith(), .EndsWith() and .ToLower() might be useful.
Force the user to look up the process ID manually. Every time.
Code:
''This one isn't cool for the user; included for completeness.
Dim targetProcessID As Int32 = CInt(InputBox("Please enter the target process ID", "Input Required", "1"))
For Each pp as Process in Process.GetProcesses()
If pp.Id = targetProcessID Then
''This is our target process! Store a reference to it.
End If
''Same as above. Could avoid the loop and use Process.GetProcessById(). It will return only 1 process (by nature of ID's being unique), not an array like the comment in box 1.
By starting the process yourself using Process.Start(), which returns a reference to the newly created process.
Code:
targetProcess = Process.Start("C:\file_path") '' Assumes you've created the targetProcess variable in this class, or with global scope.
edit: no error-handling in the code to save space & for clarity.