hello all , i will post how to make process suspender and process killer , if you can't create a form you can see my first post
okay let's go
Tutorial:
- Create project and select "Windows Application Form"
- And add this component :
Button : 2
Textbox : 1
Module : 1
- type the button1 text to : Suspend
type the button 2 text to : kill process
- for the code you can see in attachman
- and open file Form1.txt and right click form1 and click view code
- open file Form1.txt CTRL+A and CTRL+C and open your project CTRL+A and CTRL+V
- now the press F5 and test your program
So then how are you supposed to target the application you want to suspend and resume?
oh i forgot for button 1 :
Dim game As Process() = Process.GetProcessesByName(TextBox1.Text)
If Button1.Text = "SUSPEND!" Then
SuspendProcess(game(0))
Button1.Text = "RESUME!"
Else
ResumeProcess(game(0))
Button1.Text = "SUSPEND!"
End If
Originally Posted by jimbocyber
oh i forgot for button 1 :
You'll need administrative permissions to do Process Debug Mode... well for me atleast. So I would suggest adding "Change the windows settings in the project properties.
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.
Image of the code in IDE; proper syntax highlighting
edit: no error-handling in the code to save space & for clarity.
Originally Posted by abuckau907
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.
Image of the code in IDE; proper syntax highlighting
edit: no error-handling in the code to save space & for clarity.