Jump to content

taking something from a input box and loading it into a variable


Recommended Posts

I'm building a script that will GUI a net use connection. I ran into a problem with putting what I type in the input box of the GUI into the variable that when run the commands. I'm sure its something small I'm missing but some help would be much appreciated

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


#Region ### START Koda GUI section ### Form=c:\new folder\retina_script.kxf
$Retina_Script = GUICreate("Retina_Script", 625, 445, 193, 125)
$hostname = GUICtrlCreateInput("hostname", 56, 216, 121, 21)
$username = GUICtrlCreateInput("username", 56, 248, 121, 21)
$password = GUICtrlCreateInput("password", 56, 280, 121, 21)
$IPAddress = _GUICtrlIpAddress_Create($Retina_Script, 56, 184, 130, 21)
_GUICtrlIpAddress_Set($IPAddress, "0.0.0.0")
$Exit = GUICtrlCreateButton("Exit", 64, 408, 75, 25, 0)
$Netuse = GUICtrlCreateButton("Netuse", 64, 312, 75, 25, 0)
$Preretina = GUICtrlCreateButton("PreRetina", 368, 360, 75, 25, 0)
$Postretina = GUICtrlCreateButton("PostRetina", 464, 360, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Retina Script", 248, 8, 136, 29)
GUICtrlSetFont(-1, 17, 800, 0, "Times New Roman")
$Label2 = GUICtrlCreateLabel("Label2", 80, 48, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 80, 72, 36, 17)
$Label4 = GUICtrlCreateLabel("Label4", 80, 96, 36, 17)
$Label5 = GUICtrlCreateLabel("Label5", 80, 120, 36, 17)
$Label6 = GUICtrlCreateLabel("Label6", 80, 144, 36, 17)
$Label7 = GUICtrlCreateLabel("Target IPAdress", 200, 184, 80, 17)
$Label8 = GUICtrlCreateLabel("Host name", 200, 216, 55, 17)
$Label9 = GUICtrlCreateLabel("User name", 200, 248, 55, 17)
$Label10 = GUICtrlCreateLabel("Password", 200, 280, 50, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$netuseAPP='net use \\'& $IPAddress &'\ipc$ * /user:'& $hostname &'\'& $username &''

While 1
    $nMsg = GUIGetMsg()
    If $nMsg=-3 Then Exit
    If $nMsg=$Exit then exit1()
    If $nMsg=$Netuse then Netuse()
    If $nMsg=$Preretina then PreRetina1()
    If $nMsg=$Postretina then PostRetina1()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func exit1()
    Exit
EndFunc

Func Netuse()
    RunWait(@ComSpec & " /c " & $netuseAPP, "",@SW_SHOW)
EndFunc

Func PreRetina1()
    RunWait("sc.exe config lanmanworkstation start= demand" ,"" ,@SW_SHOW)
    RunWait("sc.exe config lanmanserver start= demand" ,"" ,@SW_SHOW)
    RunWait("sc.exe config browser start= demand" ,"" ,@SW_SHOW)
    RunWait("sc.exe config remoteregistry start= demand" ,"" ,@SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start Workstaton", "",@SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start Server", "",@SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start Browser", "",@SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start remoteregistry", "",@SW_SHOW)
EndFunc

Func PostRetina1()
    RunWait(@ComSpec & " /c " & "net stop Browser", "",@SW_SHOW)
    RunWait(@ComSpec & " /c " & "net stop Workstaton", "",@SW_SHOW)
    RunWait(@ComSpec & " /c " & "net stop Server", "",@SW_SHOW)
    RunWait(@ComSpec & " /c " & "net stop remoteregistry", "",@SW_SHOW)
    RunWait("sc.exe config lanmanworkstation start= disabled" ,"" ,@SW_SHOW)
    RunWait("sc.exe config lanmanserver start= disabled" ,"" ,@SW_SHOW)
    RunWait("sc.exe config browser start= disabled" ,"" ,@SW_SHOW)
    RunWait("sc.exe config remoteregistry start= disabled" ,"" ,@SW_SHOW)
EndFunc
Link to comment
Share on other sites

The variable name given to a control like an input is a variable which identifies that control, it is not a variable which contains the data in that control. When you need to use the contents of an input you must read the contents and use it .

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


#Region ### START Koda GUI section ### Form=c:\new folder\retina_script.kxf
$Retina_Script = GUICreate("Retina_Script", 625, 445, 193, 125)
$hostname = GUICtrlCreateInput("hostname", 56, 216, 121, 21)
$username = GUICtrlCreateInput("username", 56, 248, 121, 21)
$password = GUICtrlCreateInput("password", 56, 280, 121, 21)
$IPAddress = _GUICtrlIpAddress_Create($Retina_Script, 56, 184, 130, 21)
_GUICtrlIpAddress_Set($IPAddress, "0.0.0.0")
$Exit = GUICtrlCreateButton("Exit", 64, 408, 75, 25, 0)
$Netuse = GUICtrlCreateButton("Netuse", 64, 312, 75, 25, 0)
$Preretina = GUICtrlCreateButton("PreRetina", 368, 360, 75, 25, 0)
$Postretina = GUICtrlCreateButton("PostRetina", 464, 360, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Retina Script", 248, 8, 136, 29)
GUICtrlSetFont(-1, 17, 800, 0, "Times New Roman")
$Label2 = GUICtrlCreateLabel("Label2", 80, 48, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 80, 72, 36, 17)
$Label4 = GUICtrlCreateLabel("Label4", 80, 96, 36, 17)
$Label5 = GUICtrlCreateLabel("Label5", 80, 120, 36, 17)
$Label6 = GUICtrlCreateLabel("Label6", 80, 144, 36, 17)
$Label7 = GUICtrlCreateLabel("Target IPAdress", 200, 184, 80, 17)
$Label8 = GUICtrlCreateLabel("Host name", 200, 216, 55, 17)
$Label9 = GUICtrlCreateLabel("User name", 200, 248, 55, 17)
$Label10 = GUICtrlCreateLabel("Password", 200, 280, 50, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


;$netuseAPP='net use \\'& $IPAddress &'\ipc$ * /user:'& $hostname &'\'& $username &'';<----------no no no :)

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = -3 Then Exit
    If $nMsg = $Exit Then exit1()
    If $nMsg = $Netuse Then Netuse()
    If $nMsg = $Preretina Then PreRetina1()
    If $nMsg = $Postretina Then PostRetina1()

    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
WEnd

Func exit1()
    Exit
EndFunc ;==>exit1

Func Netuse()
    ;get the data/text here when it's needed
    Local $sIP = _GUICtrlIpAddress_Get($IPAddress)
    Local $sHostn = GUICtrlRead($hostname)
    Local $sUser = GUICtrlRead($username)
    $netuseAPP = 'net use \\' & $sIP & '\ipc$ * /user:' & $sHostn & '\' & $sUser & ''
    ConsoleWrite($netuseAPP & @CRLF);so you can check it is correct
    RunWait(@ComSpec & " /c " & $netuseAPP, "", @SW_SHOW)
EndFunc ;==>Netuse


Func PreRetina1()
    RunWait("sc.exe config lanmanworkstation start= demand", "", @SW_SHOW)
    RunWait("sc.exe config lanmanserver start= demand", "", @SW_SHOW)
    RunWait("sc.exe config browser start= demand", "", @SW_SHOW)
    RunWait("sc.exe config remoteregistry start= demand", "", @SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start Workstaton", "", @SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start Server", "", @SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start Browser", "", @SW_SHOW)
    RunWait(@ComSpec & " /c " & "net start remoteregistry", "", @SW_SHOW)
EndFunc ;==>PreRetina1

Func PostRetina1()
    RunWait(@ComSpec & " /c " & "net stop Browser", "", @SW_SHOW)
    RunWait(@ComSpec & " /c " & "net stop Workstaton", "", @SW_SHOW)
    RunWait(@ComSpec & " /c " & "net stop Server", "", @SW_SHOW)
    RunWait(@ComSpec & " /c " & "net stop remoteregistry", "", @SW_SHOW)
    RunWait("sc.exe config lanmanworkstation start= disabled", "", @SW_SHOW)
    RunWait("sc.exe config lanmanserver start= disabled", "", @SW_SHOW)
    RunWait("sc.exe config browser start= disabled", "", @SW_SHOW)
    RunWait("sc.exe config remoteregistry start= disabled", "", @SW_SHOW)
EndFunc ;==>PostRetina1

Not tested but I hope it gives you the idea

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I just did this exact function in a recent little script.

Basically you:

$input=GUICtrlCreateInput("default text",50,3,250,20)

then:

$text = GUICtrlRead($input)

whatever is typed into the input becomes the $text variable

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I just did this exact function in a recent little script.

Basically you:

$input=GUICtrlCreateInput("default text",50,3,250,20)

then:

$text = GUICtrlRead($input)

whatever is typed into the input becomes the $text variable

Not really, though probably you don't mean it the way I read it. What is more correct is that whenever you execute

$text = GUICtrlRead($input)

$text will contain the text that was in the edit.

But if you have

$text = GUICtrlRead($input)

and then type something into the edit, then $text will be out of date and will not contain th esame text as is in the edit.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Yes, that is correct. I had a "go" button in my gui that committed all the inputs to variables.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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