Sign in to follow this  
Followers 0
trinitrotoluen

Manage multi program at the same time

10 posts in this topic

Hi, I'm new here. I want to make a solution to manage multi program.

For example : Open 10 notepad at the same time and type some text in 10 notepad at the same time.

How can I code ?

thx in advance !

Share this post


Link to post
Share on other sites



#4 ·  Posted (edited)

Open 10 notepad at the same time and type some text in 10 notepad at the same time

Here is an example of how you can do it:

Opt("WinWaitDelay", 150) ;In some cases may need to be increesed

$iTop = 30
$iRun_Instances = 5
$sSet_Data = "Notepad Instance #%i"

$hGUI = GUICreate("__Simultanius_Run_Handling_GUI__")
$nEdit = GUICtrlCreateEdit("", 0, 0, 200, 200)

For $i = 1 To $iRun_Instances
    Run(@WindowsDir & "\Notepad.exe")
    If @error Then ContinueLoop
    
    WinWait("[CLASS:Notepad]", "", 5)
    WinSetTitle("[CLASS:Notepad]", "", "Untitled_" & $i)
    
    $aWin_Pos = WinGetPos("Untitled_" & $i)
    WinMove("Untitled_" & $i, "", $aWin_Pos[0], $iTop)
    
    $iTop += 80
    
    $sRun_Script_Content = _
        '#NoTrayIcon' & @CRLF & _
        'While ControlGetText(Hwnd(' & $hGUI & '), "", "Edit1") <> "Notepad Instances = ' & $iRun_Instances & '"' & @CRLF & _
        '   Sleep(10)' & @CRLF & _
        'WEnd' & @CRLF & _
        'ControlSetText("[CLASS:Notepad;TITLE:Untitled_' & $i & ']", "", "Edit1", StringFormat("' & $sSet_Data & '", ' & $i & '))'
    
    $hFOpen = FileOpen(@TempDir & "\~Au3_Run_" & $i & ".Tmp", 2)
    FileWrite($hFOpen, $sRun_Script_Content)
    FileClose($hFOpen)
    
    Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @TempDir & '\~Au3_Run_' & $i & '.Tmp"')
    
    If $i = $iRun_Instances Then
        MsgBox(64, "Attention...", "Now we will see the data set almost in the same time in all [" & $i & "] Notepads...", 3)
        Sleep(500)
    EndIf
    
    GUICtrlSetData($nEdit, "Notepad Instances = " & $i)
Next

Sleep(2000)
MsgBox(64, "Attention...", "Now we need to clean a little :) (delete temporary files and close Notepad windows)...", 5)

Opt("WinWaitDelay", 0)

For $i = $iRun_Instances To 1 Step -1
    FileDelete(@TempDir & '\~Au3_Run_' & $i & '.Tmp')
    WinKill("Untitled_" & $i)
Next

Just run the script, and follow the message boxes :o

P.S

The concept here is quit simple: First we executing few scripts that waiting for the main Edit (of the "parent" GUI) to have specific data (in our case it is a Notepad Instances = 5), and when the last notepad process is executed, this data is set and then all scripts will "fire" (send) some string to the notepad that was preserved (by title) for this current script - so the bottom line here is that the strings are sent in the same time (for the human eye anyway, i don't think that we need here an atomic precision :) ).

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

Here is an example of how you can do it:

Opt("WinWaitDelay", 150) ;In some cases may need to be increesed

$iTop = 30
$iRun_Instances = 5
$sSet_Data = "Notepad Instance #%i"

$hGUI = GUICreate("__Simultanius_Run_Handling_GUI__")
$nEdit = GUICtrlCreateEdit("", 0, 0, 200, 200)

For $i = 1 To $iRun_Instances
    Run(@WindowsDir & "\Notepad.exe")
    If @error Then ContinueLoop
    
    WinWait("[CLASS:Notepad]", "", 5)
    WinSetTitle("[CLASS:Notepad]", "", "Untitled_" & $i)
    
    $aWin_Pos = WinGetPos("Untitled_" & $i)
    WinMove("Untitled_" & $i, "", $aWin_Pos[0], $iTop)
    
    $iTop += 80
    
    $sRun_Script_Content = _
        '#NoTrayIcon' & @CRLF & _
        'While ControlGetText(Hwnd(' & $hGUI & '), "", "Edit1") <> "Notepad Instances = ' & $iRun_Instances & '"' & @CRLF & _
        '   Sleep(10)' & @CRLF & _
        'WEnd' & @CRLF & _
        'ControlSetText("[CLASS:Notepad;TITLE:Untitled_' & $i & ']", "", "Edit1", StringFormat("' & $sSet_Data & '", ' & $i & '))'
    
    $hFOpen = FileOpen(@TempDir & "\~Au3_Run_" & $i & ".Tmp", 2)
    FileWrite($hFOpen, $sRun_Script_Content)
    FileClose($hFOpen)
    
    Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @TempDir & '\~Au3_Run_' & $i & '.Tmp"')
    
    If $i = $iRun_Instances Then
        MsgBox(64, "Attention...", "Now we will see the data set almost in the same time in all [" & $i & "] Notepads...", 3)
        Sleep(500)
    EndIf
    
    GUICtrlSetData($nEdit, "Notepad Instances = " & $i)
Next

Sleep(2000)
MsgBox(64, "Attention...", "Now we need to clean a little :) (delete temporary files and close Notepad windows)...", 5)

Opt("WinWaitDelay", 0)

For $i = $iRun_Instances To 1 Step -1
    FileDelete(@TempDir & '\~Au3_Run_' & $i & '.Tmp')
    WinKill("Untitled_" & $i)
Next

Just run the script, and follow the message boxes :)

Great ! Work like a charm ! :o

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@TempDir is it C:\WINDOWS\Temp ? I want to find it.

Edited by trinitrotoluen

Share this post


Link to post
Share on other sites

@TempDir is it C:\WINDOWS\Temp ? I want to find it.

ShellExecute(@TempDir)

?

:)


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

#8 ·  Posted (edited)

Hi, MrCreatoR. Is it possible to debug AutoIT like press F10 in VC 6 ?

Edited by trinitrotoluen

Share this post


Link to post
Share on other sites

Hi, MrCreatoR. Is it possible to debug AutoIT like press F10 in VC 6 ?

I don't know how it works in VC 6, but in AutoIt you have Syntax Check (F8), plus this little tool: _AutoItErrorHandler (and few more found on the forum).

P.S

But how is that related to this topic? :)


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

MrCreatoR

Good example my friend! :)

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