AutoHotkey Community

It is currently May 27th, 2012, 9:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: December 8th, 2011, 1:36 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
I want to write a GUI to hold some commands that I run against computers frequently.

What I'm trying to get to is a script that when I launch it asks for the computer name, once I type that in, I'll have a list of buttons that I can click on that will run commands against that computer name.

So I started with the example GUI that asks for a first and last name and all my attempts to edit it to suit have failed miserably.

So here what I have so far:

Code:
; Example: A simple input-box that asks for the computer name

::
Gui, Add, Text,, Computer name:
Gui, Add, Edit, vComputerName ym  ; The ym option starts a new column of controls.
Gui, Add, Button, default, OK  ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, Show,, Simple Input Example
return  ; End of auto-execute section. The script is idle until the user does something.

GuiClose:
ButtonOK:
Gui, Submit  ; Save the input from the user to each control's associated variable.
MsgBox You entered "%ComputerName%.
ExitApp



When I try to edit that so that instead of popping up a msg box with the computer name it instead opens to the gui with a button that i could click to change the computer name var, which would be the first button I would want, I can't get it to work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2011, 1:49 pm 
Code:
; Example: A simple input-box that asks for the computer name
DetectHiddenWindows, on

#c:: ; added hotkey win-c
IfWinExist, Simple Input Example
   Gui, Show,, Simple Input Example
Else   
   {
   Gui, Add, Text,, Computer name:
   Gui, Add, Edit, vComputerName ym  ; The ym option starts a new column of controls.
   Gui, Add, Button, default, OK  ; The label ButtonOK (if it exists) will be run when the button is pressed.
   Gui, Show,, Simple Input Example
  }
Return  ; End of auto-execute section. The script is idle until the user does something.

ButtonOK:
Gui, Submit, Hide  ; Save the input from the user to each control's associated variable.
MsgBox You entered "%ComputerName%".
Return

GuiClose:
ExitApp
:?:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2011, 1:54 pm 
Offline

Joined: August 10th, 2009, 2:44 pm
Posts: 170
Location: Minnesota, USA
Why prompt for the computer name at all?

http://www.autohotkey.com/docs/Variables.htm#BuiltIn

A_ComputerName

_________________
PLEASE READ IF YOU'RE NEW: How to Get Answers Effectively
http://www.autohotkey.com/forum/viewtopic.php?t=4986


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2011, 2:24 pm 
Online
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1714
Location: Somewhere near you
Code:
myname = John Doe

Gui, Add, Text,, Computer name:
Gui, Add, Edit, vComputerName ym
Gui, Add, Button, default, OK
Gui, Show,, Simple Input Example
return

GuiClose:
ButtonOK:
Gui, Submit
if ComputerName = %myname%
goto creategui
ExitApp

creategui:
Gui, 2:Add, Text,, Welcome %ComputerName% !
Gui, 2:Add, Button,, %ComputerName%
Gui, 2:Add, Button,, Button2
Gui, 2:Add, Button,, Button3
Gui, 2:Add, Button,, Button4
Gui, 2:Show,, My GUI
return

ESC::ExitApp

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2011, 4:23 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
Thank you Guest! ;)

So continuing with your suggestions, now I'm trying to get it so the update button will allow the computer name to be changed at will, and I added a couple of buttons to run ping against the computer name, but when I click the buttons nothing happens:

Code:
; Example: A simple input-box that asks for the computer name
DetectHiddenWindows, on

#c:: ; added hotkey win-c
IfWinExist, TSC GUI
   Gui, Show,, TSC GUI
Else   
   {
   Gui, Add, Text,, Computer name:
   Gui, Add, Edit, vComputerName ym  ; The ym option starts a new column of controls.
   Gui, Add, Button, default, Update  ; The label update (if it exists) will be run when the button is pressed.
   Gui, Add, Button, default, Ping  ; The label ping (if it exists) will be run when the button is pressed.
   Gui, Add, Button, default, PingCon  ; The label pingcon (if it exists) will be run when the button is pressed.
   Gui, Show,, TSC GUI
  }
Return  ; End of auto-execute section. The script is idle until the user does something.

Update:
Gui, Submit  ; Save the input from the user to each control's associated variable.

Ping:
run, ping %ComputerName%

PingCon:
run, ping %ComputerName% -t


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2011, 8:15 pm 
Offline

Joined: November 17th, 2011, 6:04 pm
Posts: 392
Code:
; Example: A simple input-box that asks for the computer name
DetectHiddenWindows, on

#c:: ; added hotkey win-c
IfWinExist, TSC GUI
   Gui, Show,, TSC GUI
Else   
   {
   Gui, Add, Text,, Computer name:
   Gui, Add, Edit, vComputerName ym  ; The ym option starts a new column of controls.
   Gui, Add, Button, default, Update  ; The label update (if it exists) will be run when the button is pressed.
   Gui, Add, Button, default, Ping  ; The label ping (if it exists) will be run when the button is pressed.
   Gui, Add, Button, default, PingCon  ; The label pingcon (if it exists) will be run when the button is pressed.
   Gui, Show,, TSC GUI
  }
Return  ; End of auto-execute section. The script is idle until the user does something.

ButtonUpdate:
Gui, Submit  ; Save the input from the user to each control's associated variable.
MsgBox, You pressed Update.
return

ButtonPing:
Gui, Submit
msgbox, You pressed Ping.
return

ButtonPingCon:
Gui, Submit
msgbox, You pressed PingCon.
return

You need to add "Button" + button name else the script would thing it's a glabel, I believe.

Also, if you are working with variables like Vcomputername then you need to use the Gui,Submit command to store the input for every button you have got.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2011, 1:53 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
What I have so far is working great, but I just ran into an issue I've never had before with my AHK scripts.

I incorporated gui.ahk into my main AHK script with #include gui.ahk.

Now when I do the hotkey to call it it launches fine the first time, then on subsequent presses of the hotkey I get the following error:

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2011, 2:05 pm 
Offline

Joined: August 8th, 2010, 4:11 pm
Posts: 9
I was having the same issue in my script until just now.

The script is trying to create the GUI every time you fire the hotkey. Since the control for the variable ComputerName exists from the first time you fire the hotkey, the script runs into an error whenever it executes that line again.

Fix the problem by throwing that whole block of code except for "GUI, Show" into your script's auto-execute section. You will want to include a "GUI, Submit" section somewhere in your code as well to remove the dialog when you are finished using it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2011, 2:08 pm 
Online
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1714
Location: Somewhere near you
If you want to recreate a GUI over and over again, use Gui: Destroy at the first line, so the variable can be used again and again.

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2011, 2:16 pm 
Sung Sang Ra wrote:
If you want to recreate a GUI over and over again, use Gui: Destroy at the first line, so the variable can be used again and again.
That is one way, but if you look at the post above with the IfWinExist you see that is not required, you can simply hide and show the Gui. But even that is not the best of examples. You can define the Gui outside of the hotkey so it is only created once
Code:
Gui, Add, Edit, vComputerName ym  ; The ym option starts a new column of controls.
Gui, Add, Button, default, OK  ; The label ButtonOK (if it exists) will be run when the button is pressed.

#c:: ; added hotkey win-c
Gui, Show,, Simple Input Example
Return  ; End of auto-execute section. The script is idle until the user does something.

ButtonOK:
Gui, Submit, Hide  ; Save the input from the user to each control's associated variable.
MsgBox You entered "%ComputerName%".
Return

GuiClose:
ExitApp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2011, 2:16 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
TYVM guys!

Sung Sang Ra, your suggestion worked perfectly!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2011, 5:44 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
So I went back and rewrote the beginning of the script because I wanted the computername var to stay alive between hotkey presses, and that's working great, and when run by itself, it works great, but when incorporated back into my main script with #include when I hit the hotkey the GUI shows up in the Taskbar, but no place else. It is not accessible as a GUI.

Code:
DetectHiddenWindows, on

Gui, Add, Text,, Computer name:
Gui, Add, Edit, vComputerName 
Gui, Add, Button, default, SIP  ; The label SIP (if it exists) will be run when the button is pressed.
Gui, Add, Button, default, Ping  ; The label ping (if it exists) will be run when the button is pressed.
Gui, Add, Button, default, PingCon  ; The label pingcon (if it exists) will be run when the button is pressed.

#c:: ; added hotkey win-c
Gui, Show,, TSC GUI
Return  ; End of auto-execute section. The script is idle until the user does something.

ButtonSIP:
Gui, Submit  ; Save the input from the user to each control's associated variable.
runwait %comspec% /c "psexec.exe \\%ComputerName%  "tasklist"  /v /fi "IMAGENAME eq System idle process" /fo table /nh > SIP.txt""
Gui, 2:destroy
fileread,sipresults,sip.txt
Gui, 2:add, text,,%sipresults%
Gui, 2:show,w800 h100,Results
return

ButtonPing:
Gui, Submit
;pingresults := ping_("%ComputerName%", "pingresults", "1000")
;msgbox, %pingresults%
return

ButtonPingCon:
Gui, Submit
run, ping %ComputerName% -t
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2011, 5:58 pm 
Online
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1714
Location: Somewhere near you
Why do you want to use #Include? The GUI can be added into your main script without #Include, right?

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2011, 6:08 pm 
Offline

Joined: September 2nd, 2008, 4:20 pm
Posts: 50
Yes, I suppose, but by using #include I'm able to keep different parts in different files which helps with editing, it makes it much easier to find the part that I want to edit.

As a test I just commented out #include gui.ahk and added the gui to my main script, I have the same issue, hitting the hotkey only calls up the name of the window in the taskbar.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2011, 6:12 pm 
Post your current script.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Google Feedfetcher, migz99 and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group