Results 1 to 5 of 5

Thread: Killing a Server Process from a ASPX web page.

  1. #1

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    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.

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    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.
    ~Ryan





    Have I helped you? Please Rate my posts.

  3. #3
    Member
    Join Date
    Sep 2004
    Location
    Oklahoma City, OK
    Posts
    36
    Here's something you could try:

    VB Code:
    1. Function KillProcess(ByVal sProcessName As String) As Boolean
    2.     Try
    3.         Dim localProcesses As Process() = Process.GetProcessesByName("MOHAA_spearhead_server.exe")
    4.         If localProcesses.Length <> 0 Then
    5.             Dim i As Integer
    6.             For i = 0 To (localProcesses.Length - 1)
    7.                 Try
    8.                     localProcesses(i).Kill
    9.                 Catch
    10.                     'Process is already unloaded or
    11.                     'the assembly doesn't have sufficient security permissions
    12.                     'for this method.
    13.                 End Try
    14.             Next
    15.         End If
    16.     Catch ex As Exception
    17.         'Log the exception somewhere.
    18.     End Try
    19. End Function
    Thomas Corey
    IT Engineering Consultant
    TALSoft Enterprises Inc.
    Oklahoma City, OK

  4. #4
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    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.

  5. #5
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    Originally posted by tcorey08
    Here's something you could try:

    VB Code:
    1. Function KillProcess(ByVal sProcessName As String) As Boolean
    2.     Try
    3.         Dim localProcesses As Process() = Process.GetProcessesByName("MOHAA_spearhead_server.exe")
    4.         If localProcesses.Length <> 0 Then
    5.             Dim i As Integer
    6.             For i = 0 To (localProcesses.Length - 1)
    7.                 Try
    8.                     localProcesses(i).Kill
    9.                 Catch
    10.                     'Process is already unloaded or
    11.                     'the assembly doesn't have sufficient security permissions
    12.                     'for this method.
    13.                 End Try
    14.             Next
    15.         End If
    16.     Catch ex As Exception
    17.         'Log the exception somewhere.
    18.     End Try
    19. 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
  •  



Click Here to Expand Forum to Full Width