Notifications
Clear all

[Closed] Kill running max via doscommand?

What is the best way to get the PID for the current Max session from within Max so I it forcefully kill itself via ‘taskkill /pid’ without killing all the other running max sessions.

( I cannot use the ‘quitMax()’ command for reasons I can not disclose at this time )

3 Replies

i wrote a custom python extension to handle this, though it’s mostly called from outside max (as part of my plugin dev).

Could you use dotnet? There is a Kill() method for the Process object.

s = dotNetObject "System.Diagnostics.Process"
dotNetObject:System.Diagnostics.Process
showmethods s
  .BeginErrorReadLine()
  .BeginOutputReadLine()
  .CancelErrorRead()
  .CancelOutputRead()
  .Close()
  .<System.Boolean>CloseMainWindow()
  .<System.Runtime.Remoting.ObjRef>CreateObjRef <System.Type>requestedType
  .Dispose()
  .[static]EnterDebugMode()
  .<System.Boolean>Equals <System.Object>obj
  .[static]<System.Boolean>Equals <System.Object>objA <System.Object>objB
  .[static]<System.Diagnostics.Process>GetCurrentProcess()
  .<System.Int32>GetHashCode()
  .<System.Object>GetLifetimeService()
  .[static]<System.Diagnostics.Process>GetProcessById <System.Int32>processId
  .[static]<System.Diagnostics.Process>GetProcessById <System.Int32>processId <System.String>machineName
  .[static]<System.Diagnostics.Process[]>GetProcesses()
  .[static]<System.Diagnostics.Process[]>GetProcesses <System.String>machineName
  .[static]<System.Diagnostics.Process[]>GetProcessesByName <System.String>processName
  .[static]<System.Diagnostics.Process[]>GetProcessesByName <System.String>processName <System.String>machineName
  .<System.Type>GetType()
  .<System.Object>InitializeLifetimeService()
  .Kill()
  .[static]LeaveDebugMode()
  .[static]<System.Boolean>ReferenceEquals <System.Object>objA <System.Object>objB
  .Refresh()
  .<System.Boolean>Start()
  .[static]<System.Diagnostics.Process>Start <System.Diagnostics.ProcessStartInfo>startInfo
  .[static]<System.Diagnostics.Process>Start <System.String>fileName
  .[static]<System.Diagnostics.Process>Start <System.String>fileName <System.String>arguments
  .[static]<System.Diagnostics.Process>Start <System.String>fileName <System.String>userName <System.Security.SecureString>password <System.String>domain
  .[static]<System.Diagnostics.Process>Start <System.String>fileName <System.String>arguments <System.String>userName <System.Security.SecureString>password <System.String>domain
  .<System.String>ToString()
  .WaitForExit()
  .<System.Boolean>WaitForExit <System.Int32>milliseconds
  .<System.Boolean>WaitForInputIdle()
  .<System.Boolean>WaitForInputIdle <System.Int32>milliseconds
true
1 Reply
(@jonadb)
Joined: 11 months ago

Posts: 0

Check! While Kill trows an error I can call the .GetCurrentProcess() method which returns lots of info including the PID!

Thank you!

edit: For future reference:


proc = dotNetObject "System.Diagnostics.Process"
info=proc.GetCurrentProcess()
pid=info.Id