computergroove Posted August 2, 2015 Share Posted August 2, 2015 Is there a way to make a for loop that will call for the $VM1 then $VM2 then $VM3 etc including $Title1, $Title2 etc?OpenVM1() OpenVM2() OpenVM3() OpenVM4() Func OpenVM1() ;Open a vm window from the command line. $VM1 = Run('"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "Win8-1" --startvm "5ebbcf32-3392-45db-bd65-98fe93a1cfb5"') Sleep(60 * 1000) $Title1 = WinGetTitle($VM1) WinMove($Title1,"",0,0) EndFunc Func OpenVM2() ;Open a vm window from the command line. $VM2 = Run('"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "Win8-2" --startvm "5ebbcf32-3392-45db-bd65-98fe93a1cfb5"') Sleep(60 * 1000) $Title2 = WinGetTitle($VM2) WinMove($Title2,"",0,0) EndFunc Func OpenVM3() ;Open a vm window from the command line. $VM3 = Run('"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "Win8-3" --startvm "5ebbcf32-3392-45db-bd65-98fe93a1cfb5"') Sleep(60 * 1000) $Title3 = WinGetTitle($VM3) WinMove($Title3,"",0,0) EndFunc Func OpenVM4() ;Open a vm window from the command line. $VM4 = Run('"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "Win8-4" --startvm "5ebbcf32-3392-45db-bd65-98fe93a1cfb5"') Sleep(60 * 1000) $Title4 = WinGetTitle($VM4) WinMove($Title4,"",0,0) EndFunc Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Developers Jos Posted August 2, 2015 Developers Share Posted August 2, 2015 After being 7 years with us and 807 post I guess I am allowed to ask what your problem was adding a loop around the function calls and using the parameters in these calls?Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JohnOne Posted August 2, 2015 Share Posted August 2, 2015 It's a valid question, as is where you seen you can use Win* functions with a PID. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
computergroove Posted August 2, 2015 Author Share Posted August 2, 2015 For $i=1 To 4 $VM & $i = Run('"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "Win8-' & $i & '" --startvm "5ebbcf32-3392-45db-bd65-98fe93a1cfb5"') Sleep(60 * 1000) $Title & $i = WinGetTitle($VM & $i) WinMove($Title & $i,"",0,0)next This is my guess but I haven't tried it. I was hoping that someone could just tell me that I could or couldn't call variable names with a built in loop counter. Ill try this. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
JohnOne Posted August 2, 2015 Share Posted August 2, 2015 Those functions are almost identical, you only need one, and call it in a loop with some parameters. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted August 2, 2015 Share Posted August 2, 2015 (edited) Here's is a quickly scribbled and untested example just to get the idea...Func _Example() $aVMs[4] For $i = 1 To 4 $VMs[$i-1] = OpenVM($i) Next EndFunc Func OpenVM($num) ;Open a vm window from the command line. $VM = Run('"C:\Program Files\Oracle\VirtualBox\VirtualBox.exe" --comment "Win8-' & $num & '1" --startvm "5ebbcf32-3392-45db-bd65-98fe93a1cfb5"') Sleep(60 * 1000) ;$Title1 = WinGetTitle($VM1); sorry don't know what all this is about ;WinMove($Title1,"",0,0) Return $VM EndFunc Edited August 2, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
odaylton Posted November 25, 2015 Share Posted November 25, 2015 Text translated from Portuguese by google - please apologize for any errorsUsing Oracle VirtualBoxDear Friend think that this listing will give a light to opening existing VMs in the GUI Window expandcollapse popup#region Faze inicial RECOLHER Global $Contato = @CRLF & _ ;quebra a linha para ficar em baixo "Skype: junior.prof" & @CRLF & _ ; Dados do meu skype "Fone: +55 (11) 9-9372-0074 TIM" & @CRLF & _ ; Cel "E-mail: junior.prof@yahoo.com.br" ; e-mail #region Variaveis de Arquivos e pastas Global $NomeProjeto = "", _ ;nome da pasta $DirProjeto = "", _ ;path da pasta $PastaProjeto = "", _ ;caminho sem o drive (usado em _PathMake) $DriveProjeto ;letra do drive da pasta(usado em _PathMake) Global $ArqGravacao, _ ;contem os dados do arq de grava��o $ArqAbertoGravacao, _ ;Buter do arqiovo Aberto ou Handle $ArqQuantGravacao, _ ;Total de Bytes do arquivo de Leituta $ArqPosGravacao, _ ;Posi��o atual do arquivo em Bytes $ArqLinhaGravacao ;Linha atual do arquivo de leitura Global $ArqLeitura, _ ;contem os dados do arq de leitura $ArqAbertoLeitura, _ ;Buter do arqiovo Aberto ou Handle $ArqQuantLeitura, _ ;Total de Bytes do arquivo de Leituta $ArqPosLeitura, _ ;Posi��o atual do arquivo em Bytes $ArqLinhaLeitura ;Linha atual do arquivo de leitura #endregion Variaveis de Arquivos e pastas #region --- Internal functions Au3Recorder Start --- Func _Au3RecordSetup() Opt('WinWaitDelay', 100) Opt('WinDetectHiddenText', 1) Opt('MouseCoordMode', 0) EndFunc ;==>_Au3RecordSetup Func _WinWaitActivate($title, $text, $timeout = 0) ;15/09/03 mostra a janela que esta sendo aguardada TrayTip("Esperando...", _ ; Titulo do Tip "Janela [" & $title & "]" & @CRLF & _ "Contendo[" & $text & "]", _ ; Testo 30, _ ; tempo de 10-30s 2) ; [Icone] 1=? ,2=! ,3=X erro TraySetToolTip("Janela [" & $title & "]" & @CRLF & _ "Contendo[" & $text & "]") WinWait($title, $text, $timeout) If Not WinActive($title, $text) Then WinActivate($title, $text) WinWaitActive($title, $text, $timeout) EndFunc ;==>_WinWaitActivate _AU3RecordSetup() #endregion --- Internal functions Au3Recorder Start --- ;AutoIt_Debugger_Command:Enable_Debug #region Cria a pasta do projeto ;aqui define o nome do projeto>>>>>>>>>>>>>>>> $NomeProjeto = "TesteVM" ;Nesta pasta conter�o os Dados dos clientes e seus atendimentos ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $PastaProjeto = "\1" & $NomeProjeto If FileExists("c:") Then ;da preferencia a drive(C:) $DriveProjeto = "c:" Else $DriveProjeto = @HomeDrive EndIf $DirProjeto = $DriveProjeto & $PastaProjeto ;criando pasta If DirGetSize($DirProjeto) = -1 Then ; verifica se o diretorio existe DirCreate($DirProjeto) ; cria o diretorio EndIf #endregion Cria a pasta do projeto #endregion Faze inicial RECOLHER #region Pasta do VM $DirVM = @ProgramFilesDir & "\Oracle\VirtualBox" $tentativas = 3 While FileExists($DirVM) = 0 Or $tentativas = 0 ; não existe localizar pasta $DirVM = FileSelectFolder("Localiza a pasta do VirtualBox[" & $tentativas & "].", "", 2, @ProgramFilesDir) $tentativas -= 1 WEnd If FileExists($DirVM) = 0 Then Exit (1) Else ;Inicio do controle de VMs ;1) identificar quantas VMs exiten ;antes é precizo fechar as abertas usabdo o Camando runningvms para listalas e encerralas ;a) obtem a lista FileDelete($DirProjeto & '\ListaVM.txt');deleta a antiga $a = '"' & $DirVM & '\VBoxManage.exe" list vms > ' & $DirProjeto & '\ListaVM.txt' RunWait (@ComSpec & ' /c ' & $a) ;b) obtem os nomes $ArqLeitura = $DirProjeto & '\ListaVM.txt' $ArqAbertoLeitura = FileOpen($ArqLeitura);leitura If $ArqAbertoLeitura = -1 Then ;Caso Verdade erro de abertura BlockInput(0); desbloqueia o usuario MsgBox(Default, _; flag "Cancelado a montagem ", _;"title" "O arquivo ( " & $ArqLeitura & " ) não existe ou não esta disponivel" & @CRLF & _ "Ação: Abertura do arquivo Origem" & @CRLF & _ "Quarquer duvida entrar em contato" & @CRLF & _ $Contato, _ ; "text" 5, _ ;[, timeout Default);[, hwnd]]) Else ;Caso Mentira leitura das varias linhas Local $NomeVM[10] $iLineNumber = 0 While True $iLineNumber += 1 $sCurrentLine = FileReadLine($ArqAbertoLeitura) ; , $iLineNumber) If @error = -1 Then ExitLoop ;acabou o arquivo então sai ;obtem os dados da linha $nome = StringSplit($sCurrentLine, '" {',1) If $nome[0] = 2 Then $NomeVM[$iLineNumber] = $nome[1] Else MsgBox(Default, _; flag "Ignorando a Linha", _;"title" "A Linha ( " & $nome & " ) não contem os Dados Corretos" & @CRLF & _ "Ação: Leitura dos nomes das VMs ativas" & @CRLF & _ "Quarquer duvida entrar em contato" & @CRLF & _ $Contato, _ ; "text" 5, _ ;[, timeout Default);[, hwnd]]) EndIf ;se houver estouro If $iLineNumber = UBound($NomeVM) - 1 Then ReDim $NomeVM[UBound($NomeVM) + 10] EndIf WEnd $NomeVM[0] = $iLineNumber - 1 ;c) abre as maquina Virtuais For $i = 1 To $NomeVM[0] ;Abrindo a VM ;VBoxManage startvm "Windows XP" $a = '"' & $DirVM & '\VBoxManage.exe" startvm ' & $NomeVM[$i] & '"' RunWait( $a) ;espera o arquivo Devolve.txt ser criado no programa colocado no Start do VM Next EndIf EndIf #endregion Pasta do VM Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now