I'm designing a game server managment system. I need to know if you can end a process "MOHAA_spearhead_server.exe" on the server by using a ASP.NET command or is another program is needed that can receive commands from the web page.
Printable View
I'm designing a game server managment system. I need to know if you can end a process "MOHAA_spearhead_server.exe" on the server by using a ASP.NET command or is another program is needed that can receive commands from the web page.
download ASPExec from:
http://www.serverobjects.com/products.htm#free
Register it in component services, make sure you run the component as an admin on the server so you don't run into an permissions issues.
Create a batch file to kill the process, most likely:
Add the ASPExec DLL to your ASP.NET project. .NET should automatically create the interop for the file.Code:tskill PROCESSNAMEHERE
Your code:
I know it sounds like a lot of work for something that seems simple, but it is the easiest way i have found to get this accomplished.Code:Try
Dim p As New AspExec.Execute
p.Application = "cmd.exe"
p.Parameters = "/c INSERTFILENAME.bat"
p.ShowWindow = False
p.ExecuteWinApp()
p = Nothing
Catch ex As Exception
Throw
End Try
I also recommend you do not bother with the System.Diagnostics class dealing with processes and such, you will only be wasting your time.
If the tskill command doesn't work, which it may not if you are using windows 2000 server or running it from a os like Windows 2000 or windows XP then instead download PSTOOLS:
http://www.snapfiles.com/get/pstools.html
Extract the zip and place the files in a directory of your choosing.
In the batch file:
The rest of the code and such is all the same.Code:cd \
cd pstoolsdirectory
pskill PROCESSNAMEHERE
I hope this helps or gives you a really good idea of what to do.
Here's something you could try:
VB Code:
Function KillProcess(ByVal sProcessName As String) As Boolean Try Dim localProcesses As Process() = Process.GetProcessesByName("MOHAA_spearhead_server.exe") If localProcesses.Length <> 0 Then Dim i As Integer For i = 0 To (localProcesses.Length - 1) Try localProcesses(i).Kill Catch 'Process is already unloaded or 'the assembly doesn't have sufficient security permissions 'for this method. End Try Next End If Catch ex As Exception 'Log the exception somewhere. End Try End Function
If you are really brave you could use api.....
This involves marshalling or even worse managed c++
this might help someCode:#include <windows.h>
#using <mscorlib.dll>
//will most likely not work......
//compiles though.....
namespace JustAnExample
{
public __gc class KillProc
{
public:
static void KillDie(System::IntPtr* hProc);
};
}
void JustAnExample::KillProc::KillDie(System::IntPtr* hProc)
{
TerminateProcess(((HANDLE)(hProc->ToInt32())), 0);
}
http://msdn.microsoft.com/library/de...ess_rights.asp
what namespace is that process object in?Quote:
Originally posted by tcorey08
Here's something you could try:
VB Code:
Function KillProcess(ByVal sProcessName As String) As Boolean Try Dim localProcesses As Process() = Process.GetProcessesByName("MOHAA_spearhead_server.exe") If localProcesses.Length <> 0 Then Dim i As Integer For i = 0 To (localProcesses.Length - 1) Try localProcesses(i).Kill Catch 'Process is already unloaded or 'the assembly doesn't have sufficient security permissions 'for this method. End Try Next End If Catch ex As Exception 'Log the exception somewhere. End Try End Function