Sign in to follow this  
Followers 0
oageng

How to create a process list and close processes not on list?

21 posts in this topic

I want to create a list of processes and the script to compare against the running processes and close any process not on the list. How do I do this?

And if somebody wants to launch Task Manager, they press a hotkey and prompted to enter a password. How?

This is functionality that I want:

1)Compare running processes against a process list, and close any process not on list

2)Assign a hotkey for opening Task Manger

3)Prompt for password to open Task Manager

Share this post


Link to post
Share on other sites



1) search in the helpfile for ProcessList

2) hotkeyset

3) when u run task manager make the window invisible, ask the password and if it is right make the window visible

Share this post


Link to post
Share on other sites

1) search in the helpfile for ProcessList

2) hotkeyset

3) when u run task manager make the window invisible, ask the password and if it is right make the window visible

Could you help with the script? I'm still learning how to code scripts

Share this post


Link to post
Share on other sites

ask what u didnt understand...

Share this post


Link to post
Share on other sites

ask what u didnt understand...

Please if you cant help don't make this a burden on yourself. This is not a concrete block. Others may help if they can

Share this post


Link to post
Share on other sites

I want to create a list of processes and the script to compare against the running processes and close any process not on the list. How do I do this?

And if somebody wants to launch Task Manager, they press a hotkey and prompted to enter a password. How?

This is functionality that I want:

1)Compare running processes against a process list, and close any process not on list

2)Assign a hotkey for opening Task Manger

3)Prompt for password to open Task Manager

I also do not understand your question. What are you going to compare the resulting list of processes?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Please if you cant help don't make this a burden on yourself. This is not a concrete block. Others may help if they can

if u want someone to make the code for u then go here: www.rentacoder.com, if u have a specific question then ask. Edited by oMBRa

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

1)Compare running processes against a process list, and close any process not on list

2)Assign a hotkey for opening Task Manger

3)Prompt for password to open Task Manager

Something like this:

#NoTrayIcon

Global $sPassword = "AutoIt"
Global $sProcList = _ProcessListToString()

HotKeySet("^+t", "_Run_TaskMgr_Proc") ;Ctrl + Shift + T will call our function to run task manager
HotKeySet("^+e", "_Quit_Proc") ;Ctrl + Shift + E will exit the script

AdlibEnable("_CompareProcesses_Proc", 2000) ;Every 2 seconds we compare the processes list

While 1
    Sleep(100)
WEnd

Func _ProcessListToString()
    Local $aProcList = ProcessList()
    Local $sRet_ProcList = "|"
    
    For $i = 1 To $aProcList[0][0]
        $sRet_ProcList &= $aProcList[$i][1] & "|"
    Next
    
    Return $sRet_ProcList
EndFunc

Func _Run_TaskMgr_Proc()
    While 1
        Local $iPassword_Ask = InputBox("Task Manager Run", "Please enter password to run Task Manager:", "", "*")
        If @error Then Return
        
        If $iPassword_Ask == $sPassword Then Return Run("Taskmgr.exe")
        
        MsgBox(48, "Task Manager Run - Error", "Wrong password, please try again.")
    WEnd
EndFunc

Func _CompareProcesses_Proc()
    Local $aProcList = ProcessList()
    
    For $i = 1 To $aProcList[0][0]
        If Not StringInStr($sProcList, "|" & $aProcList[$i][1] & "|") Then ProcessClose($aProcList[$i][1])
    Next
EndFunc

Func _Quit_Proc()
    Exit
EndFunc

?

:)

P.S

The comparision process will not be executed when InputBox is displayed, but that also can be fixed with callback timers.

Edited by MrCreatoR

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

That seems like it could end up with an awful lot of loops MrCreator. I might suggest reading the first ProcList() into a string with front and back non-digit delimiters. Then loop through the new ProcList() with a StringInStr() method.

I only say this, because if I had an exaggerated amount of processes (let's say 200), then every time you call that function, you're going to loop 40,000 times (if no new processes are started). When you could loop just 200.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Something like this:

#NoTrayIcon

Global $sPassword = "AutoIt"
Global $aProcList = ProcessList()

HotKeySet("^+t", "_Run_TaskMgr_Proc") ;Ctrl + Shift + T will call our function to run task manager
HotKeySet("^+e", "_Quit_Proc") ;Ctrl + Shift + E will exit the script

AdlibEnable("_CompareProcesses_Proc", 2000) ;Every 2 seconds we compare the processes list

While 1
    Sleep(100)
WEnd

Func _Run_TaskMgr_Proc()
    While 1
        Local $iPassword_Ask = InputBox("Task Manager Run", "Please enter password to run Task Manager:", "", "*")
        If @error Then Return
        
        If $iPassword_Ask == $sPassword Then Return Run("Taskmgr.exe")
        
        MsgBox(48, "Task Manager Run - Error", "Wrong password, please try again.")
    WEnd
EndFunc

Func _CompareProcesses_Proc()
    Local $aCurent_ProcList = ProcessList()
    Local $iProc_Found = 0
    
    For $i = 1 To $aCurent_ProcList[0][0]
        $iProc_Found = 0
        
        For $j = 1 To $aProcList[0][0]
            If $aCurent_ProcList[$i][1] = $aProcList[$j][1] Then
                $iProc_Found = 1
                ExitLoop
            EndIf
        Next
        
        If Not $iProc_Found Then ProcessClose($aCurent_ProcList[$i][1])
    Next
EndFunc

Func _Quit_Proc()
    Exit
EndFunc

?

:)

P.S

The comparision process will not be executed when InputBox is displayed, but that also can be fixed with callback timers.

Thank you very much. Let me run this and I'll give you feedback (though I'm new to AutoIT). I'm grateful that u were able to understand my idea.

We always learn from others. Tomorrow you could lean on me i.e I could also extend my hand

Share this post


Link to post
Share on other sites

That seems like it could end up with an awful lot of loops MrCreator. I might suggest reading the first ProcList() into a string with front and back non-digit delimiters. Then loop through the new ProcList() with a StringInStr() method.

I only say this, because if I had an exaggerated amount of processes (let's say 200), then every time you call that function, you're going to loop 40,000 times (if no new processes are started). When you could loop just 200.

Ok, modified my post with the example.


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Something like this:

#NoTrayIcon

Global $sPassword = "AutoIt"
Global $sProcList = _ProcessListToString()

HotKeySet("^+t", "_Run_TaskMgr_Proc") ;Ctrl + Shift + T will call our function to run task manager
HotKeySet("^+e", "_Quit_Proc") ;Ctrl + Shift + E will exit the script

AdlibEnable("_CompareProcesses_Proc", 2000) ;Every 2 seconds we compare the processes list

While 1
    Sleep(100)
WEnd

Func _ProcessListToString()
    Local $aProcList = ProcessList()
    Local $sRet_ProcList = "|"
    
    For $i = 1 To $aProcList[0][0]
        $sRet_ProcList &= $aProcList[$i][1] & "|"
    Next
    
    Return $sRet_ProcList
EndFunc

Func _Run_TaskMgr_Proc()
    While 1
        Local $iPassword_Ask = InputBox("Task Manager Run", "Please enter password to run Task Manager:", "", "*")
        If @error Then Return
        
        If $iPassword_Ask == $sPassword Then Return Run("Taskmgr.exe")
        
        MsgBox(48, "Task Manager Run - Error", "Wrong password, please try again.")
    WEnd
EndFunc

Func _CompareProcesses_Proc()
    Local $aProcList = ProcessList()
    
    For $i = 1 To $aProcList[0][0]
        If Not StringInStr($sProcList, "|" & $aProcList[$i][1] & "|") Then ProcessClose($aProcList[$i][1])
    Next
EndFunc

Func _Quit_Proc()
    Exit
EndFunc

?

:)

P.S

The comparision process will not be executed when InputBox is displayed, but that also can be fixed with callback timers.

I tried to modify this because it has an undesired behaviour. It immediately closes Task Manager after entering the password. If it could pause for some specified time or wait for Task Manager to close that would be great.

I thought to register Task Manager as soon as the script executes, so that it puts it in the current process list. But this doesn't work. Task Manager doesn't show. What could be the problem?

#NoTrayIcon

Global $sPassword = "deception"
Global $aProcList = ProcessList()

HotKeySet("!t", "_Run_TaskMgr");Alt+T will call our function to run task manager
HotKeySet("!e","Terminate")

AdlibEnable("_CompareProcesses_Proc", 2000);Every 2 seconds we compare the processes list

While 1
    Sleep(100)
WEnd

Run("Taskmgr.exe","",@SW_HIDE);register Task Manager(in hidden mode) in the current process list

Func _Run_TaskMgr() 
;While 1
        Local $iPassword_Ask = InputBox("Task Manager Run", "Please enter password to run Task Manager:", "", "*")
        If @error Then Return
       
        If $iPassword_Ask == $sPassword Then Return WinSetState("Windows Task Manager","",@SW_SHOW)
        
        MsgBox(48, "Task Manager Access - Error", "Wrong password, please try again.")
   ;WEnd
EndFunc

Func _CompareProcesses_Proc()   
    Local $aCurent_ProcList = ProcessList()
    Local $iProc_Found = 0
   
    For $i = 1 To $aCurent_ProcList[0][0]
        $iProc_Found = 0
       
        For $j = 1 To $aProcList[0][0]
            If $aCurent_ProcList[$i][1] = $aProcList[$j][1] Then
                $iProc_Found = 1                
                ExitLoop            
            EndIf
        Next
            
        If Not $iProc_Found Then ProcessClose($aCurent_ProcList[$i][1])
    Next
EndFunc

Func Terminate()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

You need to start it befor $aProcList = ProcessList() is create

#NoTrayIcon

Run("Taskmgr.exe","",@SW_HIDE);register Task Manager(in hidden mode) in the current process list
Global $sPassword = "deception"
Global $aProcList = ProcessList()

HotKeySet("!t", "_Run_TaskMgr");Alt+T will call our function to run task manager
HotKeySet("!e","Terminate")

AdlibEnable("_CompareProcesses_Proc", 2000);Every 2 seconds we compare the processes list

While 1
    Sleep(100)
WEnd
.
.

Share this post


Link to post
Share on other sites

:
If $iPassword_Ask == $sPassword Then Return WinSetState("Windows Task Manager","",@SW_SHOW)
:

How can I make this show for a specified amount of time, and hide Task Manager again?

Share this post


Link to post
Share on other sites

If Not $iProc_Found And $aCurent_ProcList[$i][0] <> "taskmgr.exe" Then ProcessClose($aCurent_ProcList[$i][1])

did you understand what you are doing there ? i don't think so :-|

Share this post


Link to post
Share on other sites

If Not $iProc_Found And $aCurent_ProcList[$i][0] <> "taskmgr.exe" Then ProcessClose($aCurent_ProcList[$i][1])

did you understand what you are doing there ? i don't think so :-|

I don't understand much, A bit. I do have some idea. I'm still learning...

Share this post


Link to post
Share on other sites

First check what is the resulte from ProcessList()

#include <array.au3>
Global $aProcList = ProcessList()
_ArrayDisplay( $aProcList )oÝ÷ ØX§v­Â­Ëaz·¬º[_®´ß¦®ËvÑ©ÝÓ~>º.+-ÛV®¶­sb6æ6ÇVFRfÇC¶'&æS2fwC°¤vÆö&Âb33c¶&ö4Æ7BÒ&ö6W74Æ7B¤6öç6öÆUw&FRb33c¶&ö4Æ7E³%Õ³Òfײ5"¤6öç6öÆUw&FRb33c¶&ö4Æ7E³%Õ³Òfײ5"¥ô'&F7Æb33c¶&ö4Æ7B

Try to understand what _CompareProcesses_Proc() is doing and how to prevent that taskmgr.exe is closed.

_CompareProcesses_Proc() compare $aProcList[$i][1] with aCurent_ProcList[$i][1]. [$i][1] is the pid. So one way is to start the taskmgr.exe and prevent that taskmgr.exe is closed.

If Not $iProc_Found And $aCurent_ProcList[$i][0] <> "taskmgr.exe" Then ProcessClose($aCurent_ProcList[$i][1])

$aCurent_ProcList[$i][0] retrun the Processname. So if processname not equal taskmgr.exe then close the process.

Start taskmgr with the hotkey and change the line where the process a closed.

Share this post


Link to post
Share on other sites

If Not $iProc_Found And $aCurent_ProcList[$i][0] <> "taskmgr.exe" Then ProcessClose($aCurent_ProcList[$i][1])

did you understand what you are doing there ? i don't think so :-|

This brings up Task Manager without the input box i.e bypasess the password promt !? Unless I dont follow you

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

First check what is the resulte from ProcessList()

#include <array.au3>
Global $aProcList = ProcessList()
_ArrayDisplay( $aProcList )

Global $aProcList = ProcessList()
ConsoleWrite($aProcList[1][0] & @CR)
ConsoleWrite($aProcList[1][1] & @CR)

Try to understand what _CompareProcesses_Proc() is doing and how to prevent that taskmgr.exe is closed.

_CompareProcesses_Proc() compare $aProcList[$i][1] with aCurent_ProcList[$i][1].

[$i][1] is the pid. So one way is to start the taskmgr.exe and prevent that taskmgr.exe is closed.

If Not $iProc_Found And $aCurent_ProcList[$i][0] <> "taskmgr.exe" Then ProcessClose($aCurent_ProcList[$i][1])

$aCurent_ProcList[$i][0] retrun the Processname. So if processname not equal taskmgr.exe then close the process.

Start taskmgr with the hotkey and change the line where the process is closed.

Sorry for my bad english.

Edited by Tec

Share this post


Link to post
Share on other sites

Hey I think I did a great enhancement, without complicating the code for myself. This even simulates closing Task manager when started through Ctrl+Alt+Del, which I think its a great enhancement.

I decreased the refresh rate of _CompareProcesses_Proc() by increasing the time to 7 seconds instead of 2. Have a look:

#NoTrayIcon

Run("Taskmgr.exe","",@SW_HIDE);register Task Manager(in hidden mode) in the current process list
Global $sPassword = "deception"
Global $aProcList = ProcessList()

HotKeySet("!t", "_Run_TaskMgr");Alt+T will call our function to run task manager
HotKeySet("!e","_Terminate");Exit script

AdlibEnable("_CompareProcesses_Proc", 7000);Every 2 seconds we compare the processes list

While 1
    Sleep(100)
WEnd

Func _Run_TaskMgr() 
;While 1
        Local $iPassword_Ask = InputBox("Acess Task Manager", "Please enter password to run Task Manager:", "", "*")
        If @error Then Return
       
        If $iPassword_Ask == $sPassword Then Return WinSetState("Windows Task Manager","",@SW_SHOW)     
        
        MsgBox(48, "Task Manager Access - Error", "Wrong password, please try again.")
   ;WEnd
EndFunc

Func _CompareProcesses_Proc()
    Call("_Hide_Taskmgr") 
    Local $aCurent_ProcList = ProcessList()
    Local $iProc_Found = 0
   
    For $i = 1 To $aCurent_ProcList[0][0]
        $iProc_Found = 0
       
        For $j = 1 To $aProcList[0][0]
            If $aCurent_ProcList[$i][1] = $aProcList[$j][1] Then
                $iProc_Found = 1                
                ExitLoop            
            EndIf
        Next
            
        If Not $iProc_Found Then ProcessClose($aCurent_ProcList[$i][1])
    Next
EndFunc

Func _Hide_Taskmgr()
    WinSetState("Windows Task Manager","",@SW_HIDE)
EndFunc

Func _Terminate()
    Exit
EndFunc

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  
Followers 0