Jump to content

Gotta be a better way... Reading GUI text and outputting as more text


Recommended Posts

This is going to be attached to another script to collect login info so I can automate some things. What I'm trying to figure out is how can I take the text or whatever being typed into one of the fields and output it as typed text into something else. At the moment this is the only way I've been able to get it to output text as referencing $AUser just spits out the number 6 instead of the stuff typed in the box.

At the moment it's set to output the text to notepad, but I'll probably store it as a variable or something. I'm just trying to get the mechanics down first.

#include <GUIConstantsEx.au3>

Global $mainwindow, $AUser, $Password, $NewUser
Global $var = 1

Func GUICollectData()

Local $BTNEXIT

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Need Login Credentials", 300, 200) ;Creates a window and assigns it a handle
GUICtrlCreateLabel("Enter Information Here...", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 125, 150, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Your Domain Username...", 10, 30, 180)
$AUser = GUICtrlCreateInput("", 10, 45, 275, 20)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetTip(-1, "The title of the message box.")

GUICtrlCreateLabel("Your Password...", 10, 70, 180)
$Password = GUICtrlCreateInput("", 10, 85, 275, 20)
GUICtrlSetTip(-1, "The title of the message box.")

GUICtrlCreateLabel("Machine Owner's Username...", 10, 110, 180)
$NewUser = GUICtrlCreateInput("", 10, 125, 275, 20)
GUICtrlSetTip(-1, "The title of the message box.")

While($var)
Sleep(1000) ;Sleep around
WEnd

EndFunc

Func OKButton()
;Note: at this point @GUI_CTRLID would equal $okbutton
ConsoleWrite(GUICtrlRead($AUser) & @CRLF)
$BUser = (GUICtrlRead($AUser))
ConsoleWrite(GUICtrlRead($Password) & @CRLF)
ConsoleWrite(GUICtrlRead($NewUser) & @CRLF)
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("test" & @CRLF)
Send($Buser,1)
$var = 0
EndFunc

Func CLOSEClicked()
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
;@GUI_WINHANDLE will be either $mainwindow or $dummywindow
If @GUI_WINHANDLE = $mainwindow Then
Exit
EndIf
EndFunc


GUICollectData()

Apologies for the ugly text, for some reason this form won't accept my indents when I copy paste this in.

Link to comment
Share on other sites

  • Moderators

MeepZero,

I would like a better explanation of why you want to "collect login info" than merely saying "so I can automate some things". :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Sorry, this is going to be plugged into another script so I can add a user to the local admin group on our domain. This section of script, when run, should prompt for the tech's user name and password (for domain authentication) and the user account that the machine is going to be attached to. So it should prompt for 3 fields. After this runs it will plug the login / password data typed in into the authenticate domain admin screen and then plug in the end user's login to the local administrator window.

I was using the notepad to output as a test to see if I could get the script to push the text back out into a field / form / whatever.

Let me know if you have further questions.

Link to comment
Share on other sites

Thats not quite the problem, the output window is active when the text is firing, the problem is without rassigning the text to a new variable it just comes up as "6" in the output. What I'm trying to figure out, is is this the correct way to handle text coming from a field that a user types into? Do I need to do this....

Func OKButton()
;Note: at this point @GUI_CTRLID would equal $okbutton
ConsoleWrite(GUICtrlRead($AUser) & @CRLF)
$BUser = (GUICtrlRead($AUser)) ;Assign the $Auser content to $Buser
ConsoleWrite(GUICtrlRead($Password) & @CRLF)
ConsoleWrite(GUICtrlRead($NewUser) & @CRLF)
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("test" & @CRLF)
Send($Buser,1) ;Push Buser out as text
$var = 0
EndFunc

When I could be doing something like this somehow...

Func OKButton()
;Note: at this point @GUI_CTRLID would equal $okbutton
ConsoleWrite(GUICtrlRead($AUser) & @CRLF)
ConsoleWrite(GUICtrlRead($Password) & @CRLF)
ConsoleWrite(GUICtrlRead($NewUser) & @CRLF)
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("test" & @CRLF)
Send($Auser,1) ;Pull directly from the $Auser variable
$var = 0
EndFunc
Link to comment
Share on other sites

Here your script, only change function OKButton()

#include 

Global $mainwindow, $AUser, $Password, $NewUser
Global $var = 1

Func GUICollectData()

Local $BTNEXIT

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Need Login Credentials", 300, 200) ;Creates a window and assigns it a handle
GUICtrlCreateLabel("Enter Information Here...", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 125, 150, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Your Domain Username...", 10, 30, 180)
$AUser = GUICtrlCreateInput("", 10, 45, 275, 20)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetTip(-1, "The title of the message box.")

GUICtrlCreateLabel("Your Password...", 10, 70, 180)
$Password = GUICtrlCreateInput("", 10, 85, 275, 20)
GUICtrlSetTip(-1, "The title of the message box.")

GUICtrlCreateLabel("Machine Owner's Username...", 10, 110, 180)
$NewUser = GUICtrlCreateInput("", 10, 125, 275, 20)
GUICtrlSetTip(-1, "The title of the message box.")

While($var)
Sleep(1000) ;Sleep around
WEnd

EndFunc

Func OKButton()
;Note: at this point @GUI_CTRLID would equal $okbutton
$BUser = GUICtrlRead($AUser)
ConsoleWrite($BUser & @CRLF)

$BPassword = GUICtrlRead($Password)
ConsoleWrite($BPassword & @CRLF)

$BNewUser = GUICtrlRead($NewUser)
ConsoleWrite($BNewUser & @CRLF)


Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
;Send("test" & @CRLF)
Send($BUser & @CRLF)
Send($BPassword & @CRLF)
Send($BNewUser & @CRLF)
$var = 0
EndFunc

Func CLOSEClicked()
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
;@GUI_WINHANDLE will be either $mainwindow or $dummywindow
If @GUI_WINHANDLE = $mainwindow Then
Exit
EndIf
EndFunc


GUICollectData()
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...