Jump to content
david1337

Set application in idle state

Recommended Posts

david1337

Hi guys

I have a script that runs for about 20 seconds.

If Outlook.exe is not already open, and I open it while the script is running, I want Outlook to wait until the script is done, and then open.
Is it possible to set an application in some sort of idle state until the script is done? I want to avoid it from just closing Outlook, and open it again.
 

Thanks

David

Share this post


Link to post
Share on other sites
johnmcloud
; Johnmcloud - 2016
; _GetAllProcessThreads by monoceres, a little edited

Local $iPID = Run("notepad")
Sleep(1000)

_ProcessSuspend($iPID)
Sleep(2000)
_ProcessResume($iPID)

Func _ProcessSuspend($iPID)
    Local $THREAD_SUSPEND_RESUME = 0x0002
    Local $hWnd, $aProcessThreads = _GetAllProcessThreads($iPID)
    For $i = 1 To $aProcessThreads[0][0]
        $hWnd = DllCall('Kernel32.dll', 'hwnd', "OpenThread", "int", $THREAD_SUSPEND_RESUME, "int", 0, 'int', $aProcessThreads[$i][0])
        If Not @error Then DllCall('Kernel32.dll', 'uint', "SuspendThread", 'hwnd', $hWnd[0])
    Next
    Return 1
EndFunc   ;==>_ProcessSuspend

Func _ProcessResume($iPID)
    Local $THREAD_SUSPEND_RESUME = 0x0002
    Local $hWnd, $aProcessThreads = _GetAllProcessThreads($iPID)
    For $i = 1 To $aProcessThreads[0][0]
        $hWnd = DllCall('Kernel32.dll', 'hwnd', "OpenThread", "int", $THREAD_SUSPEND_RESUME, "int", 0, 'int', $aProcessThreads[$i][0])
        If Not @error Then DllCall('Kernel32.dll', 'uint', "ResumeThread", 'hwnd', $hWnd[0])
    Next
    Return 1
EndFunc   ;==>_ProcessResume

Func _GetAllProcessThreads($iPID)
    Local Const $TH32CS_SNAPTHREAD = 0x00000004
    Local Const $THREADENTRY32 = "dword dwSize;dword cntUsage;dword th32ThreadId;dword th32OwnerProcessID;long tpBasePri;long tpDeltaPri;dword dwFlags;"
    Local $aCall = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0)
    If @error Then Return SetError(1, 0, 0)
    Local $hThread = $aCall[0]
    Local $aReturn[1][3]
    Local $Thread32 = DllStructCreate($THREADENTRY32)
    DllStructSetData($Thread32, "dwSize", DllStructGetSize($Thread32))
    $aCall = DllCall("Kernel32.dll", "int", "Thread32First", "ptr", $hThread, "ptr", DllStructGetPtr($Thread32))
    If @error Then Return SetError(2, 0, 0)
    If DllStructGetData($Thread32, "th32OwnerProcessID") = $iPID Then _GetAllThreads_ArrHelper($aReturn, $Thread32)
    Do
        $aCall = DllCall("Kernel32.dll", "int", "Thread32Next", "ptr", $hThread, "ptr", DllStructGetPtr($Thread32))
        If Not $aCall[0] Then ExitLoop
        If DllStructGetData($Thread32, "th32OwnerProcessID") = $iPID Then _GetAllThreads_ArrHelper($aReturn, $Thread32)
    Until True And False
    $aReturn[0][0] = UBound($aReturn) - 1 ; number of items in the array
    DllCall("Kernel32.dll", "bool", "CloseHandle", "handle", $hThread)
    If @error Then Return SetError(3, 0, 0)
    Return $aReturn
EndFunc   ;==>_GetAllProcessThreads

Func _GetAllThreads_ArrHelper(ByRef $aArray, $Thread32_Struct)
    Local $iUBound = UBound($aArray)
    ReDim $aArray[$iUBound + 1][3]
    $aArray[$iUBound][0] = DllStructGetData($Thread32_Struct, "th32ThreadId")
    $aArray[$iUBound][1] = DllStructGetData($Thread32_Struct, "th32OwnerProcessID")
    $aArray[$iUBound][2] = DllStructGetData($Thread32_Struct, "tpBasePri")
EndFunc   ;==>_GetAllThreads_ArrHelper

 

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

  • Similar Content

    • Miliardsto
      By Miliardsto
      I want to detect if exact process or window uses directx or opengl or maybe something else library used in applications.
      Thats becouse there could be many windows with same names and different names and the same with process. I got so much process names I want to my script works with all, so i want standardize.
      All of this processes uses DirectX or OpenGL so then If I check this window/process uses these libraries I will be sure thats the right process
    • TryWare90Days
      By TryWare90Days
      I'm trying to kill a malware process, that I can't remove with my www.sophus.com/hom antivirus.

      The malware is known as coinminer,config and my Sophus only creates popups of blocking the malware.

      I know that the malware is constantly launching a svchost *32.exe processes, where the svchost.exe processes are from my Windows 7 operating system.
      I have with no luck tried to do this:
      Global $_bStatus = False
      While $_bStatus = False
                 Global $_iPid
                 Global $_sActiveTitleNew = "svchost *32.exe"
                 $_iPid = WinGetProcess($_sActiveTitleNew)
                 If $_iPid <> -1 Then $_bStatus = ProcessClose($_iPid)   
      Wend
      EXIT
       
      But the $_iPid doesn't ever show anything else than  -1, even if I can see the svchost *32.exe process in my TaskManager
       
      YES - I know I shouldn't EXIT after killing the first malware detection, but it is easier to explain the above for you, so I can get a solution.
    • guinness
      By guinness
      Right now the script will exit immediately if I don't pause it somehow (obvious of course).
      I was  curious on people's opinions of how they do it or what option they prefer below? Thanks
      Option 1 (I prefer)
      #include <MsgBoxConstants.au3> HotKeySet('^!p', SomeFunc) ProcessWaitClose(@AutoItPID) Func SomeFunc() MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) EndFunc Option 2 (in the help file)
      #include <MsgBoxConstants.au3> HotKeySet('^!p', SomeFunc) While Sleep(100) WEnd Func SomeFunc() MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) EndFunc Option 3
      #include <MsgBoxConstants.au3> HotKeySet('^!p', SomeFunc) While 1 GUIGetMsg() ; Use the internal sleep WEnd Func SomeFunc() MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) EndFunc  
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry after your permission
      I found a function to get the special line commands for any operation
      It requires the name of the process to be searched
      I want to use it to know the process
      Is this possible with this function
      Here is the code
       
      Func commandLineGet($proc, $strComputer=".")
      dim $array[1]
      local $ArrayNumber
      local $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
      local $oProcessColl = $oWMI.ExecQuery("Select * from Win32_Process where Name= " & '"'& $Proc & '"')
      local $Process
      For $Process In $oProcessColl
      $Process = $Process.Commandline
          ReDim $Array[UBound($Array)+1]
      $ArrayNumber = UBound($Array)-1
      $array[$ArrayNumber] = $Process
      Next
      $ArrayNumber = UBound($Array)-1
      $array[0] = $ArrayNumber
      return $array
      EndFunc
    • simy8891
      By simy8891
      Hi guys,
      It's been a while since I wrote my last message here and a while since I used AutoIt. I'm currently sort of desperate and I'm trying to find some help in regards of getting the network usage per process!
      I'm not interested in the total network usage of the NIC, but only on a specific PID's network utilization. They idea is to collect the amount of traffic uploaded and downloaded by a list of specific processes. So far Process Hacker and Process Explorer are capable of getting what I need, but I need to use these numbers in another script so they're sort of useless to me. I can't seem to find a way around it.
      Any idea, help is greatly appreciated.
      Thanks
×