Jump to content

run an program, close it, run next program, wait for 10 minutes after closeing program 1 and repeat


Recommended Posts

Hi

im looking for a way to open a program then close it, open the next program, close it, open next program close it and after 10 minutes when the first program gor closed it should open the first program again.

Could you help me on building the concept for it?

 

this is my code in my thoughts:

while 1

shellexec(prog1)

close(prog1)

      while 1

     sleep(10 min)

    shellexec(prog1)

    wend

shellexec(prog2)

close(prog2)

wend

 

Link to comment
Share on other sites

Basic example, for testing I've set it to 10 seconds.

HotKeySet("{ESC}", "_ExitScript")

;~ Global $g_iTimerDiff = 1000 * 60 * 10    ;~ 10 minutes
Global $g_iTimerDiff = 1000 * 10            ;~ 10 seconds for testing
Global $g_hTimerInit, $fTimerDiff = $g_iTimerDiff
Global $g_iProcessId
Global $g_aPrograms[2] = ["Notepad.exe", @ComSpec & " /k"]
Global $i = (UBound($g_aPrograms) - 1)
While 1
    If $fTimerDiff >= $g_iTimerDiff Then
        ProcessClose($g_iProcessId)
        $i = $i = (UBound($g_aPrograms) - 1) ? 0 : $i + 1
        _RunProgram($g_aPrograms[$i])
    EndIf
    Sleep(100)
    $fTimerDiff = TimerDiff($g_hTimerInit)
WEnd

Func _RunProgram($_sProgram)
    $g_hTimerInit = TimerInit()
    $g_iProcessId = Run($_sProgram)
EndFunc


Func _ExitScript()
    Exit
EndFunc

 

Link to comment
Share on other sites

Thanks for your quick response : )

that works like a charm : )

almost : )

i wanna run chrome with profile 1 and then chrome with profile 2 the links to the profiles are placed on the desktop.

ShellExecute("C:\Users\User\Desktop\acc 1 - Chrome.lnk")

ShellExecute("C:\Users\User\Desktop\acc 2 - Chrome.lnk")

if i replace the line

Global $g_aPrograms[2] = ["Notepad.exe", @ComSpec & " /k"]

with

Global $g_aPrograms[2] = ["C:\Users\User\Desktop\acc 1 - Chrome.lnk", "C:\Users\User\Desktop\acc 2 - Chrome.lnk" & " /k"]

then nothing happens on the run

Link to comment
Share on other sites

thanks earthshine, well ur right, i first had to think how to generally run my thoughts in a script : )

now ive changed it to.... and this works perfectly : )

 

HotKeySet("{ESC}", "_ExitScript")

;~ Global $g_iTimerDiff = 1000 * 60 * 10    ;~ 10 minutes
Global $g_iTimerDiff = 1000 * 10            ;~ 10 seconds for testing
Global $g_hTimerInit, $fTimerDiff = $g_iTimerDiff
Global $g_iProcessId
$linktorun1 = '"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1"'
$linktorun2 = '"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 2"'
Global $g_aPrograms[2] = [$linktorun1, $linktorun2& " /k"]
Global $i = (UBound($g_aPrograms) - 1)
While 1
    If $fTimerDiff >= $g_iTimerDiff Then
        ProcessClose($g_iProcessId)
        $i = $i = (UBound($g_aPrograms) - 1) ? 0 : $i + 1
        _RunProgram($g_aPrograms[$i])
    EndIf
    Sleep(100)
    $fTimerDiff = TimerDiff($g_hTimerInit)
WEnd

Func _RunProgram($_sProgram)
    $g_hTimerInit = TimerInit()
    $g_iProcessId = Run($_sProgram)
EndFunc


Func _ExitScript()
    Exit
EndFunc

 

 

 

Edited by svenjatzu
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...