Jump to content

Browse for txt file containing computer name


Recommended Posts

Trying to create a gui windows with a browse button to browse to a text file

Users will select the text file and then click on a RUN button, behind the scene autoit will read each line of the text file and append it to a command..

I would also like to know if there is a way to display the command prompt window within the guiwindow to show the user the progress of the commands...

Something like the attached file.. it's cheesy I know, it'll give an idea of what I'm trying to accomplish though

post-60800-0-33773500-1320010618_thumb.p

Link to comment
Share on other sites

_FileReadToArray perhaps? What is the text file content going to look like?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

_FileReadToArray perhaps? What is the text file content going to look like?

The txt file will have a list of computers and I will use DSRM command, reading the computer names line by line and removing them from AD

I will also use camcmd to remove computers from out CA IT Client Manager server... so the content of the text file isn't my main focus

CMD to Remove Computers from AD

FOR /F "tokens=1,2* delims=," %%G IN (C:\remove.txt) DO dsrm %%G OU=Computers,DC=domainname,DC=suffix

CMD to Remove Computers from CA IT Client Manager

for /f "tokens=1,2* delims=," %%G IN (C:\remove.txt) DO cadsmcmd targetcomputer action=delete name=%%G

I'll put those commands in the tool

Here's a few AutoIt functions that will probably be used here.

GUICreate

GUICtrlCreateButton

FileOpenDialog

FileReadLine

Thanks, I'll take a look at those and see what I can find out..

Edited by Elephant007
Link to comment
Share on other sites

Some advertising :D

To remove computers from the AD you could use my Active Directory UDF. The UDF provides much better error handling and a lot of features which might be useful for other scripts you write.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here is something similar I wrote quickly for someone...

#include <GUIConstants.au3>
; Program name to run
Dim $_Program = "nrg2iso.exe"
; files to search for
Dim $_File = "*.nrg"
$GUI = GUICreate("My GUI", 350, 300)
$t_label = GUICtrlCreateLabel("Ready", 10, 50, 320, 20)
$d_label = GUICtrlCreateLabel("Counter", 10, 100, 320, 20)
$Button = GUICtrlCreateButton("GO", 135, 200, 80, 30)
GUISetState()
While 1
 $msg = GUIGetMsg()
 If $msg = -3 Then Exit
 If $msg = $Button Then Runner()
WEnd

Func Runner()
 Local $numID = 0, $TnumID = 0
 GUICtrlSetData($t_label, "Searching for " & $_File & "   ...Please wait...")
 RunWait(@ComSpec & ' /c ' & 'dir "' & @HomeDrive & $_File & '" /a :h /b /s' & ' > "' & @TempDir & '\dir.txt"', '', @SW_HIDE)
 Sleep(2000)

 $hFile = FileOpen(@TempDir & "\dir.txt", 0)
 ; Check if file opened for reading OK
 If $hFile = -1 Then
  MsgBox(0, "Error", "Unable to open file.")
  Return
 EndIf
 ; Read in lines of text until the EOF is reached
 While 1
  $sLine = FileReadLine($hFile)
  If @error = -1 Then ExitLoop
  If $sLine <> "" Then
   $numID = $numID + 1
   GUICtrlSetData($t_label, "Running - " & $sLine)
   If $numID >= $TnumID + 5 Then
    $TnumID = $numID
    GUICtrlSetData($d_label, " Files Ran: " & $TnumID)
   EndIf
   If FileExists($sLine) Then RunWait($_Program & " " & $sLine); Put your command here
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
  EndIf
 WEnd
 GUICtrlSetData($t_label, "*** Complete ***")
 FileClose($hFile)
EndFunc   ;==>Runner

8)

NEWHeader1.png

Link to comment
Share on other sites

Here is a cool visual too..

#include <IE.au3>
;#include-once
Global $XT_oIE
XSkinConsole( "", 10, 10, 400, 300)
XSkinText("This is an example...")
Sleep(1000)
XSkinText("Starting tasks...")
Sleep(1000)
XSkinText() ; sends a blank line
XSkinText("... Clearing Screen")
Sleep(1000)
XSkinText("CLR") ;Clears the XSkinConsole
$Text = StringSplit("Checking System...,System Located,Checking Folders...,Folders Found,Checking Files...,Files Found, Verifying Data....,....Complete",",")
$color = StringSplit("red,brown,orange,blue,yellow,green,gray,",",")
For $i = 1 To $Text[0] -1
    Sleep(1000)
    $msg = $i & @TAB & $Text[$i]
    XSkinText($msg, $color[$i])
Next
Sleep(700)
XSkinText() ; send a blank line
XSkinText($Text[8], "Red", 6)
Sleep(5000)

Func XSkinConsole($XT_GUI, $left, $top, $width, $height)
    _IEErrorHandlerRegister()
    $XT_oIE = _IECreateEmbedded()
    If Not IsHWnd($XT_GUI) Then
        $XT_GUI = GUICreate("", $width + (2 * $left), $height + (2 * $top))
        GUISetState()
    EndIf
    $XT_ActiveX = GUICtrlCreateObj($XT_oIE, $left, $top, $width, $height)
    _IENavigate($XT_oIE, "about:blank")
    Return $XT_ActiveX
EndFunc   ;==>XSkinConsole
Func XSkinText($msg = "", $color = "black", $size = "3")
    If $msg == "CLR"  Then Return _IEDocWriteHTML($XT_oIE, "")
    Return _IEDocWriteHTML($XT_oIE, _IEDocReadHTML($XT_oIE) & '<font color="' & $color & '" size=' & $size & '>' & $msg & '</font><br>')
EndFunc   ;==>XSkinText

8)

NEWHeader1.png

Link to comment
Share on other sites

Here's something I've come up with, it's kinda dirty right now... it's going along the line of what I'm wanting to do (I haven't checked the new scripts that people put in here yet, I will thought)

The one thing I can't seem to figure out is how to get the CMD Prompt to show up inside the GUI window

I'm using a file named "Ping This.txt" the space is put in there on purpose for now and the file contains these simple lines

Ping This.txt

www.google.com
www.yahoo.com

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
Opt('MustDeclareVars', 1)
DIM $InfoFile, $PINGIT, $1Cmd, $2Cmd, $Path
$1Cmd = 'CMD /C FOR /F "usebackq tokens=1,2* delims=," %G IN ("'
$2Cmd = '") DO ping %G'
Remover()
Func Remover()
Local $Button_1, $Button_2, $msg
GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered
Opt("GUICoordMode", 2)
$Path = GUICtrlCreateInput ("", 10, 15, 200, 20 )
$Button_1 = GUICtrlCreateButton("Browse", 10, 40, 100)
;~  GUICtrlCreateInput("",10,53,367,23)
$Button_2 = GUICtrlCreateButton("Button Test", 0, -1)
GUISetState()     ; will display an  dialog box with 2 button
; Run the GUI until the dialog is closed
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $Button_1
    $InfoFile = FileOpenDialog ("Browse", "C:\", "Text Documents (*.txt)")
    GUICtrlSetData($path, $InfoFile)
   Case $msg = $Button_2
;~   MsgBox ( 0, '', $1Cmd & $InfoFile & $2Cmd )
    $PINGIT = Run ( $1Cmd & $InfoFile & $2Cmd, '', @SW_SHOW )    ; Will demonstrate Button 2 being pressed
  EndSelect
WEnd
EndFunc   ;==>Remover
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...