Jump to content

How to launch external apps with the use of buttons


Recommended Posts

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 141, 53, 193, 125)

$Button1 = GUICtrlCreateButton("Button1", 16, 8, 113, 25, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

run("notepad.exe")

EndSwitch

WEnd

Link to comment
Share on other sites

;====================================================

;================= Example of a GUI =================

;====================================================

; AutoIt version: 3.0.103

; Language: English

; Author: "SlimShady111"

;

; ----------------------------------------------------------------------------

; Script Start

; ----------------------------------------------------------------------------

;Include constants

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()

;Initialize variables

Local $GUIWidth = 300, $GUIHeight = 250

Local $Edit_1, $OK_Btn, $Cancel_Btn, $Def_Btn, $msg

#forceref $Edit_1

;Create window

GUICreate("Cockpit", $GUIWidth, $GUIHeight)

GuiCtrlCreateLabel("Optimize your Windows", 10, 10)

;Create an "OK" button

$OK_Btn = GUICtrlCreateButton("System Restore", 10, 50, 90, 25)

;Create a "CANCEL" button

$Cancel_Btn = GUICtrlCreateButton("Registry Editor", 200, 50, 90, 25)

$Def_Btn = GUICtrlCreateButton("Defragmenter", 105, 50, 90, 25)

;Show window/Make the window visible

GUISetState(@SW_SHOW)

;Loop until:

;- user presses Esc

;- user presses Alt+F4

;- user clicks the close button

While 1

;After every loop check if the user clicked something in the GUI window

$msg = GUIGetMsg()

Select

;Check if user clicked on the close button

Case $msg = $GUI_EVENT_CLOSE

;Destroy the GUI including the controls

GUIDelete()

;Exit the script

Exit

;Check if user clicked on the "OK" button

Case $msg = $OK_Btn

run("rstrui.exe" ,"C:Windows/system32/restore/rstrui.exe")

;Check if user clicked on the "CANCEL" button

Case $msg = $Def_Btn

Run("rstrui.exe" ,"c:/windows/system32/restore",1,1)

EndSelect

WEnd

EndFunc ;==>_Main

Link to comment
Share on other sites

You are using it wrong.

Run("C:\Program files\iTunes\iTunes.exe")

The first parameter of Run() is the full path to the application you want to run. The second parameter is the working directory.

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...