Jump to content
Sign in to follow this  

Kill process runing in usb and unplug usb

Recommended Posts

Hi All.

Im sorry because my english is not well.

I want a scrip that auto kill process runing in usb, and auto unplug usb.

Can anyone give me some idea :graduated:)

Tks a lot ^^

Share this post

Link to post
Share on other sites

As far as I know there is no Windows equivalent of lsof which means the only way to kill the process running on a usb is if you know the process name.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF


Share this post

Link to post
Share on other sites


'I want a script' - it isn't script request forum. You can ask for advice but not for full script.

To get process path you should try use this:

Func _ProcessGetLocation($iPID)
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If $aProc[0] = 0 Then Return SetError(1, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
    Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
    If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
    Return $aReturn[3]

To get an array of currently running processes you should use:

$Process = ProcessList()

And write For... Next loop which checks each process path. If process is from USB then kill it using ProcessClose.

Edited by Ramzes

Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...