Jump to content

Help Me, Please with code ProcessClose on Windows


triviet4
 Share

Recommended Posts

Welcome to AutoIt and the forum!
Please have a look at function ProcessList. Loop through the array and close all processes but the 1, 2.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

i cann't unknown ProcessList. At a time Turn on Computer, i will be different ProcessList

As well as With shorcut:

taskkill /F /FI "USERNAME eq user_name" /FI "IMAGENAME ne explorer.exe" /FI "IMAGENAME ne dwm.exe"

 

Edited by triviet4
Link to comment
Share on other sites

I found this code. It's wrong or right + How add Hotkey

Local $sProcessList = ProcessList()
For $i=0 To UBound($sProcessList)-1
    CloseProcess($sProcessList[$i][0])
Next

Func CloseProcess($sProcess)
    Local $sListProcessSystem=StringSplit("smss.exe|csrss.exe|wininit.exe|services.exe|lsass.exe|svchost.exe|spoolsv.exe|MsMpEng.exe|NisSrv.exe|dasHost.exe|SearchIndexer.exe|OSPPSVC.EXE|audiodg.exe|winlogon.exe|dwm.exe|taskeng.exe|sihost.exe|taskhostw.exe|RuntimeBroker.exe|ShellExperienceHost.exe|SearchUI.exe|SettingSyncHost.exe|SearchProtocolHost.exe|WUDFHost.exe|InstallAgent.exe|WmiPrvSE.exe|HxTsr.exe|SearchFilterHost.exe|rundll32.exe|", "|")
    For $x=0 To UBound($sListProcessSystem)-1
        If Not StringInStr($sProcess,$sListProcessSystem[$x]) Then
            ConsoleWrite("ProcessClose: " & $sProcess&@CRLF)
            ProcessClose($sProcess)
        EndIf
    Next
EndFunc

 

Edited by triviet4
Link to comment
Share on other sites

Opt("TrayAutoPause", 0)

HotKeySet("{F6}", "CloseProcess")
HotKeySet("{F7}", "_Exit")

While 1
    Sleep(10)
    ToolTip("F6: CloseProcess - F7: Exit", @DesktopWidth / 2, @DesktopHeight / 2, "", 2, 2)
WEnd

Func CloseProcess()
    Local $sProcessList = ProcessList()
    For $i = 0 To UBound($sProcessList) - 1
        _CloseProcess($sProcessList[$i][0])
    Next
EndFunc   ;==>CloseProcess

Func _CloseProcess($sProcess)
    Local $sListProcessSystem = StringSplit(@ScriptName & "|AutoIt3.exe|SciTE.exe|dllhost.exe|UniKey.exe|explorer.exe|smss.exe|csrss.exe|wininit.exe|services.exe|lsass.exe|svchost.exe|spoolsv.exe|MsMpEng.exe|NisSrv.exe|dasHost.exe|SearchIndexer.exe|OSPPSVC.EXE|audiodg.exe|winlogon.exe|dwm.exe|taskeng.exe|sihost.exe|taskhostw.exe|RuntimeBroker.exe|ShellExperienceHost.exe|SearchUI.exe|SettingSyncHost.exe|SearchProtocolHost.exe|WUDFHost.exe|InstallAgent.exe|WmiPrvSE.exe|HxTsr.exe|SearchFilterHost.exe|rundll32.exe", "|")
    Local $sTrue = False
    For $x = 0 To UBound($sListProcessSystem) - 1
        If $sProcess = $sListProcessSystem[$x] Then $sTrue = True
    Next
    If Not $sTrue Then
        ConsoleWrite("ProcessClose: " & $sProcess & @CRLF)
        ToolTip("ProcessClose: " & $sProcess, @DesktopWidth / 2, @DesktopHeight / 2, "", 2, 2)
        ProcessClose($sProcess)
    EndIf
EndFunc   ;==>_CloseProcess

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

Regards,
 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...