Sign in to follow this  
Followers 0
Cigar Jack

My first Script

2 posts in this topic

I've been working with AutoIt for a total of two days.

All I'm using this GUI for is a front for setting up the PSExec Command that calls a batch file and a list of servers and outputs the command to a command prompt.

Since I'm still learning I was curious if you see anything that I could do better. I'm still learning the ropes and just kind of hacked this together by reading the help files and forums.

#include <GUIConstants.au3>
#include <File.au3>
#Include <Array.au3>
Opt("GUICoordMode", 2 )
GUICreate("WSUS Reboot Script")
GUICtrlCreateLabel("Enter or Select Data Location", 10, 10)
$share = GUICtrlCreateCombo( "", -1, 1, 200)
GUICtrlSetData( -1, "\\SERVERNAME\WindowsUpdate", "\\SERVERNAME\WindowsUpdate")
$mapbutton = GUICtrlCreateButton("Map Drive", 2, -20, 60, 20)
$driveinfo = GUICtrlCreateLabel( "No Mapped Drive", 8, -15, 120, 20)
$serverlist = GUICtrlCreateCombo( "", -390, 1, 200 )
GUICtrlCreateLabel( "Server List", 5, -15, 200 )
$batchlist = GUICtrlCreateCombo( "", -405, 1, 200 )
GUICtrlCreateLabel( "Batch File", 5, -15, 200 )
$username = GUICtrlCreateInput( "na\username", -405, 20, 150)
GUICtrlCreateLabel( "Domain User Account", 5, -15, 200 )
$password = GUICtrlCreateInput( "password", -355, 2, 150, 0, $ES_PASSWORD)
GUICtrlCreateLabel( "Domain User Password", 5, -15, 200 )
$fire = GUICtrlCreateButton("Patch Servers", -100, 30, 100, 20)
GUISetState()

While 1
  $msg = GUIGetMsg()

  Select
;~    Maps a drive to the specified path and generates a list of text files and batch files
;~    for the Combo Boxes.
    Case $msg = $mapbutton
      $drive = DriveMapAdd( "*", GUICtrlRead($share), 8)
      GUICtrlSetData( $driveinfo, "Mapped to " & $drive)
      $txtList = _FileListToArray($drive, "*.txt")
      If IsArray($txtList) Then
        GUICtrlSetData($serverlist, "|" & _ArrayToString($txtList, "|", 1))
      Else
        MsgBox(0, "Error", "Error: " & @Error)
      EndIf
      $batList = _FileListToArray($drive, "*.bat")
      If IsArray($txtList) Then
        GUICtrlSetData($batchlist, "|" & _ArrayToString($batList, "|", 1))
      Else
        MsgBox(0, "Error", "Error: " & @Error)
      EndIf 
;~     Launches Command Prompt and PSExec Process
    Case $msg = $fire
      Run("cmd.exe", $drive)
      WinWaitActive("C:\WINDOWS\system32\cmd.exe")
      Send("psexec @" & GUICtrlRead($serverlist) & " -u " & GUICtrlRead($username) & " -p " & GUICtrlRead($password) & " -c " & GUICtrlRead($batchlist) & @CR)
    Case $msg = $GUI_EVENT_CLOSE
      DriveMapDel($drive)
      ExitLoop
  EndSelect
WEnd

Share this post


Link to post
Share on other sites



I've been working with AutoIt for a total of two days.

All I'm using this GUI for is a front for setting up the PSExec Command that calls a batch file and a list of servers and outputs the command to a command prompt.

Since I'm still learning I was curious if you see anything that I could do better. I'm still learning the ropes and just kind of hacked this together by reading the help files and forums.

Welcome to the forums!

I can't exactly test your code, but if it works to the standards that you want it to, There are no problems.

Unfortunately, If you have no questions other then how can i improve what is already working how you like it, it should be in Scripts and Scraps.

Don't make another thread, perhaps a mod can be so kind as to move it for you.

Glad to see you have had success with Autoit!

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