Sign in to follow this  
Followers 0
C45Y

RunMyBox

3 posts in this topic

#1 ·  Posted (edited)

A small app that can auto Launch Virtualbox virtual machines.

Simply run the application for the first time and a .ini will be created with your preferences

Then next time you run the app it will ask you if you would like to make changes to the configuration file, if no option is selected it will boot the virtual machine specified in the configuration file.

A shortcut in the startup folder would autorun the program on logon

Note: no real error checking right now. ill get to it when im home from work Done

vboxmanage.exe is usually found at "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" but not always :graduated: Yea fixed somewhat

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=RunMyBox.ico
#AutoIt3Wrapper_outfile=RunMyBox.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Fileversion=0.0.0.5
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_Icon_Add=info.ico
#AutoIt3Wrapper_Res_Icon_Add=right.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.3.5.6 (beta)
    Author:         Stephen McGregor (C45Y)
    Script Function:
    Starts a Virtualbox VM.
    
#ce ----------------------------------------------------------------------------

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>



Opt("TrayMenuMode", 1)
Local $vboxmanage, $vboxname, $vboxdir, $vmpath
Local $ini = @ScriptDir & "\RunMyBox.ini"



If FileExists($ini) Then
    If IniRead($ini, "prog", "sel", "") = "" Then _EditINI()
    If IniRead($ini, "prog", "sel", "") = "1" Then
        If IniRead($ini, "Vbox", "Dir", "") = "" Then _EditINI()
        If IniRead($ini, "Vbox", "Name", "") = "" Then _EditINI()
        If IniRead($ini, "Vbox", "Location", "") = "" Then _EditINI()
    EndIf
    If IniRead($ini, "prog", "sel", "") = "0" Then
        If IniRead($ini, "VMW", "Path", "") = "" Then _EditINI()
    EndIf
    If MsgBox(4, "RunMyBox", "Start up your VM?", 9) = 7 Then Exit
    If MsgBox(4, "RunMyBox", "Edit the Configuration?", 9) = 6 Then _EditINI()
Else
    _EditINI()
EndIf


If IniRead($ini, "prog", "sel", "") = 1 Then
    If IniRead($ini, "Vbox", "Dir", "") = "" Then _EditINI()
    If IniRead($ini, "Vbox", "Name", "") = "" Then _EditINI()
    If IniRead($ini, "Vbox", "Location", "") = "" Then _EditINI()
    $vboxdir = IniRead($ini, "Vbox", "Dir", "")
    $vboxname = IniRead($ini, "Vbox", "Name", "")
    $vboxmanage = IniRead($ini, "Vbox", "Location", "")
    Run($vboxmanage & ' startvm "' & $vboxname & '"', $vboxdir, @SW_HIDE)
    If @error Then MsgBox(0, "Error", "Run Error, Edit the config")
EndIf

;0 = VMWare | 1 = Virtualbox
;@MyDocumentsDir & "\Virtual Machines\"
;C:\Users\C45Y\Documents\Virtual Machines\bt
If IniRead($ini, "prog", "sel", "") = 0 Then
    If IniRead($ini, "VMW", "Path", "") = "" Then _EditINI()
    $vmpath = IniRead($ini, "VMW", "Path", "")
    Run(@ProgramFilesDir & '\VMware\VMware Workstation\vmrun.exe start "' & $vmpath & '"', @ProgramFilesDir & "\VMware\VMware Workstation\",@SW_HIDE)
EndIf



Func _EditINI()
    ;#Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("RunMyBox", 240, 191, 348, 210)
    $Group1 = GUICtrlCreateGroup("VirtualBox", 8, 8, 225, 89)
    $Icon1 = GUICtrlCreateIcon(@ScriptFullPath, 201, 24, 32, 16, 16, BitOR($SS_NOTIFY,$WS_GROUP))
    GUICtrlSetTip($Icon1, "The location of 'vboxmanage.exe', should be in " & @CRLF & "C:\$programs\oracle\ect.... but is sometimes found " & @CRLF & "elsewhere.")
    $Icon2 = GUICtrlCreateIcon(@ScriptFullPath, 201, 24, 56, 16, 16, BitOR($SS_NOTIFY,$WS_GROUP))
    GUICtrlSetTip($Icon2, "Name of Virtualbox to run, Name is CASE SENSITIVE!")
    $Input1 = GUICtrlCreateInput(IniRead($ini, "Vbox", "Location", ""), 54, 32, 138, 21)
    $Input2 = GUICtrlCreateInput(IniRead($ini, "Vbox", "Name", ""), 54, 56, 138, 21)
    $Button1 = GUICtrlCreateButton("->", 202, 31, 20, 20, $BS_ICON)
    GUICtrlSetImage(-1, @ScriptFullPath, 202,0)
    $Button2 = GUICtrlCreateButton("Save changes", 66, 160, 105, 25)
    $Checkbox1 = GUICtrlCreateCheckbox("", 208, 8, 17, 17)
    $Group2 = GUICtrlCreateGroup("VMWare", 8, 104, 225, 55)
    $Checkbox2 = GUICtrlCreateCheckbox("", 208, 104, 17, 17)
    $Button3 = GUICtrlCreateButton("->", 202, 127, 20, 20, $BS_ICON)
    GUICtrlSetImage(-1, @ScriptFullPath, 202,0)

    $Input3 = GUICtrlCreateInput("", 54, 128, 138, 21)
    $Icon3 = GUICtrlCreateIcon(@ScriptFullPath, 201, 24, 128, 16, 16, BitOR($SS_NOTIFY,$WS_GROUP))
    GUICtrlSetTip($Icon3, "Name of VMWare .vmx file to run." & @CRLF & "Little arrow button to launch a file select dialog")
    GUICtrlSetFont(-1, 7)
    If IniRead($ini, "prog", "sel", "") = "1" Then GUICtrlSetState($Checkbox1, $GUI_CHECKED)
    If IniRead($ini, "prog", "sel", "") = "0" Then GUICtrlSetState($Checkbox2, $GUI_CHECKED)
    GUISetState(@SW_SHOW)
    ;#EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Checkbox2
                GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
                IniWrite($ini, "prog", "sel", "0")
            Case $Checkbox1
                GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
                IniWrite($ini, "prog", "sel", "1")
            Case $Button2
                $vboxmanage = GUICtrlRead($Input1)
                $vboxname = GUICtrlRead($Input2)
                $vmpath = GUICtrlRead($Input3)
                ExitLoop
            Case $Button1
                GUICtrlSetData($Input1, FileOpenDialog("RunMyBox", @ProgramFilesDir & "\Oracle\VirtualBox", "Executables (Vboxmanage.exe)", 1, "Vboxmanage.exe"))
            Case $Button3
                GUICtrlSetData($Input3, FileOpenDialog("RunMyBox", @MyDocumentsDir & "\Virtual Machines\", "Virtual Machines(*.vmx)", 1))
        EndSwitch
    WEnd
    GUIDelete($Form1)
    
    IniWrite($ini, "VMW", "Path", $vmpath)
    IniWrite($ini, "Vbox", "Location", $vboxmanage)
    IniWrite($ini, "Vbox", "Name", $vboxname)
    
    ;Figure workingdir
    $vboxdir = StringTrimRight($vboxmanage, StringLen($vboxmanage) - StringInStr($vboxmanage, "\", 1, -1))
    IniWrite($ini, "Vbox", "Dir", $vboxdir)
EndFunc   ;==>_EditINI

Compiled version and/or installer available at http://twentylinesofcode.blogspot.com/2010/11/runmybox.html

Edited by C45Y

http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Update!

Using a much better layout, the stupid little labels are gone and replaced by tooltips and nice icons.

Added support for VMWare virtual machines.

Basically just testing and GUI changes to follow the design principles outlined in a recent seminar i attended

thanks for all the views guys, 412 from this topic. and not a single comment.

lurk moar?

Edited by C45Y

http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun

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