|
-
Sep 8th, 2004, 04:16 PM
#1
Thread Starter
Addicted Member
Killing a Server Process from a ASPX web page.
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.
-
Sep 8th, 2004, 11:36 PM
#2
Addicted Member
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:
Code:
tskill PROCESSNAMEHERE
Add the ASPExec DLL to your ASP.NET project. .NET should automatically create the interop for the file.
Your code:
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 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.
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:
Code:
cd \
cd pstoolsdirectory
pskill PROCESSNAMEHERE
The rest of the code and such is all the same.
I hope this helps or gives you a really good idea of what to do.
Last edited by rdove; Sep 8th, 2004 at 11:44 PM.
-
Sep 22nd, 2004, 11:53 PM
#3
Member
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
Thomas Corey
IT Engineering Consultant
TALSoft Enterprises Inc.
Oklahoma City, OK
-
Sep 23rd, 2004, 07:10 AM
#4
Frenzied Member
If you are really brave you could use api.....
This involves marshalling or even worse managed c++
Code:
#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);
}
this might help some
http://msdn.microsoft.com/library/de...ess_rights.asp
Magiaus
If I helped give me some points.
-
Sep 23rd, 2004, 07:12 AM
#5
Frenzied Member
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
what namespace is that process object in?
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|