Sign in to follow this  
Followers 0
surfer

Variable Array, radio buttons?

2 posts in this topic

Hello I need some flexibility

so I wrote that with psshutdown from:

http://www.sysinternals.com/Utilities/PsShutdown.html

you neet an server.txt file at the same directory with the server names in it

to see what I want:

List the file entries as radio buttons:

#include <file.au3>
#include <GuiConstants.au3>
#include <Array.au3>
; http://www.sysinternals.com/Utilities/PsShutdown.html

Dim $aRecords

$file = "server.txt"

If Not _FileReadToArray($file ,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
GuiCreate("Server Restart", 210, 460)
GUICtrlCreateLabel("Server from the file: "&$file, 10, 10, 180, 95)
GUICtrlCreateLabel("________________________________", 10, 25, 180, 95)
$counter = 50
$counterOne = 0
$counterOne = $aRecords[0]-1

For $x = 1 to $counterOne
     Dim $Checkbox[$aRecords[0]]
     
     $tempCheckbox = GuiCtrlCreateCheckbox($aRecords[$x], 25, $counter, 90, 20)
     _arrayAdd( $Checkbox, $tempCheckbox)
   ;   GUICtrlCreateLabel("Server "&$x&": "&$aRecords[$x], 25, $counter, 180, 95)
    

    $counter = $counter+20
Next
GUICtrlCreateLabel("Server", 10, 170, 80, 95)
$server = GUICtrlCreateInput ("", 10,  190, 130, 20)  
GUICtrlCreateLabel("User", 10, 220, 80, 95)
$user = GUICtrlCreateInput ("", 10,  240, 130, 20)   
GUICtrlCreateLabel("Password", 10, 270, 80, 95)
$password = GUICtrlCreateInput ("", 10,  290, 130, 20)   
 
 
 




$RadioRestart = GuiCtrlCreateRadio("Restart", 10, 330, 90, 20);
$RadioShutdown = GuiCtrlCreateRadio("Shutdown", 10, 350, 90, 20);
$Button = GuiCtrlCreateButton("OK", 10, 370, 90, 20);

GUICtrlSetState(10,$GUI_CHECKED)


GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
    Case $msg = $Button
         server()
    EndSelect
WEnd






Func server()


; if GUICtrlRead($tempCheckbox[0]) = $GUI_CHECKED Then
; if $Checkbox[0] = $GUI_CHECKED Then
Msgbox(4096,'Record:' & GUICtrlRead(GUICtrlRead($Checkbox[0])), "Test XXXX>"&GUICtrlRead(GUICtrlRead($Checkbox[0]))&" Test2>"&$aRecords[0])



; EndIf



;    Msgbox(0,'Msg:'&GUICtrlRead($RadioRestart)&" Button:"&$Button & $x, "Restart")
   ; If GUICtrlRead($Button) = $GUI_CHECKED Then
        if GUICtrlRead($RadioRestart) = $GUI_CHECKED Then
       ; restart
           ; run(psshutdown \\172.22.144.1 -u Administrator -p sdfrtghrtfh -r)

                ; Run("cmd.exe")
           ; $program = "psshutdown"
           ; Send($program&" \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password)&" -r")
           ; Send ("{ENTER}")
           ; Send ("exit")
           ; Send ("{ENTER}")
                Msgbox(1,'Server Restart:', "Restart >"&GUICtrlRead($server))
                Run(@ComSpec & " /c " & "psshutdown \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password)&" -r", "", @SW_HIDE);shutdown a pc
        
        EndIf
        if GUICtrlRead($RadioShutdown) = $GUI_CHECKED Then
       ; shutdown
           ; Run("cmd.exe")
           ; $program = "psshutdown"
           ; Send($program&" \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password))
           ; Send ("{ENTER}")
           ; Send ("exit")
           ; Send ("{ENTER}")
          Msgbox(1,'Server Shutdown:', "Shutdown >"&GUICtrlRead($server))
        Run(@ComSpec & " /c " & "psshutdown \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password), "", @SW_HIDE);shutdown a pc
        
        EndIf
   ; Else
        
   ; EndIf
EndFunc

I would like to use radio buttons to select the server:

But the radio buttons didn't return the expected value but why

and why is after each line such a letter?

But the selection didn't work also the mouse doesn't work only by using TAB.

Has somebody an hint?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello,

I've got it:

#include <file.au3>
#include <GuiConstants.au3>
#include <Array.au3>
; http://www.sysinternals.com/Utilities/PsShutdown.html

Dim $aRecords

$file = "server.txt"
$server = "XXX"

If Not _FileReadToArray($file ,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
GuiCreate("Server Restart", 210, 400)
GUICtrlCreateLabel("Server from the file: "&$file, 10, 10, 180, 95)
GUICtrlCreateLabel("________________________________", 10, 25, 180, 95)
$counter = 50
$counterOne = 0
$counterOne = $aRecords[0]-1
$listTest = ""
$ListServer = GUICtrlCreateList("", 10, 40, 180, 97, -1, $WS_EX_CLIENTEDGE)
For $x = 1 to $counterOne
        $listTest = $listTest&"|"& StringStripCR($aRecords[$x])
        GUICtrlSetData(-1, $listTest)
    $counter = $counter+20
Next
GUICtrlCreateLabel("Server", 10, 170, 80, 95)
$server = GUICtrlCreateInput ("", 10,  190, 130, 20)
GUICtrlCreateLabel("User", 10, 220, 80, 95)
$user = GUICtrlCreateInput ("", 10,  240, 130, 20)   
GUICtrlCreateLabel("Password", 10, 270, 80, 95)
$password = GUICtrlCreateInput ("", 10,  290, 130, 20)   
$RadioRestart = GuiCtrlCreateRadio("Restart", 10, 330, 90, 20);
$RadioShutdown = GuiCtrlCreateRadio("Shutdown", 10, 350, 90, 20);
$Button = GuiCtrlCreateButton("OK", 10, 370, 90, 20);

GUICtrlSetState(10,$GUI_CHECKED)


GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
    Case $msg = $Button
         server()
    EndSelect
WEnd

; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

++
Func server()
if GUICtrlRead($server) == "" Then
$server = $ListServer
Endif
if GUICtrlRead($server) == 0 Then
$server = $ListServer
Endif
if GUICtrlRead($server) == "Server" Then
$server = $ListServer
Endif
if GUICtrlRead($server) == "0" Then
$server = $ListServer
Endif
if GUICtrlRead($server) == "XXX" Then
$server = $ListServer
Endif
; Msgbox(4096,'Record:' & GUICtrlRead($ListServer), "Test XXXX>"&GUICtrlRead($ListServer)&" Test2>"&GUICtrlRead($server))

        if GUICtrlRead($RadioRestart) = $GUI_CHECKED Then
            ; restart
                        $message1 = Msgbox(1,'Server Restart:', "Restart >"&GUICtrlRead($server))
                        if ($message1 == 1) Then
                             Run(@ComSpec & " /c " & "psshutdown \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password)&" -r", "", @SW_HIDE);shutdown a pc
                Endif
        EndIf
        if GUICtrlRead($RadioShutdown) = $GUI_CHECKED Then
            ; shutdown
                  $message2 = Msgbox(1,'Server Shutdown:', "Shutdown >"&GUICtrlRead($server))
                  if ($message2 == 1) Then
                     Run(@ComSpec & " /c " & "psshutdown \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password), "", @SW_HIDE);shutdown a pc
            EndIf
        EndIf
; Else
        
; EndIf
EndFunc

But the mouse doesn't work???

Why ???

Please I need some help !!!!!

Thanks a lot

surfer

Edited by surfer

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