Bkay8686 Posted May 13, 2014 Share Posted May 13, 2014 Hello All, Very new to AutoIT and scripting in general. I am having a difficult time finding any relevant help to the simple task I need to execute. Essentially, I have a text file that is an output of WMIC that shows all software installed on a machine. I need to search for a specific product name. If it exists, I will do X, if not do Y. However, I cannot figure out the best way to do so. I've looked into FileOpenFileRead and FileReadLine but I can't seem to figure out how to use them for what I need. I would love something that functions like ControlGetText but I am obviously not opening a window, I am searching in a text file. Any and all help would be greatly appreciated. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 13, 2014 Moderators Share Posted May 13, 2014 Bkay8686,First, welcome to the AutoIt forums. What you want to do is very easy - read the file into a variable and check if the required text is present:If StringInStr(FileRead("FileName"), "AppName") Then ; Code if app name found Else ; Code if not found EndIfPlease ask if you have any questions. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Bkay8686 Posted May 13, 2014 Author Share Posted May 13, 2014 Melba23, Thank you SO much. I have spent about day and a half trying to find the best way to do this. I appreciate the quick and thorough response. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 13, 2014 Moderators Share Posted May 13, 2014 Bkay8686,Glad I could help. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Bkay8686 Posted May 13, 2014 Author Share Posted May 13, 2014 Since I was helped so quickly, I figured I would post the lines that do exactly what I needed: 1. Export all installed software on a machine into a text file 2. Search for a specific software nameversion 3. Create a "results" file that displays if what I needed was installed or not The purpose behind this is to allow for less-technical folks to see if our servers are setup properly before our stores open. Hope this helps someone else... ;Run WMIC.exe to export all software to a text file RunWait("C:\WINDOWS\System32\wbem\wmic.exe /output:C:\software.txt product get Name, Version" , "C:\WINDOWS\System32\wbem" , @SW_HIDE) ;Assign a variable to the results file that will need to be created Global $results = FileOpen("C:\Results.txt" , $FO_APPEND) ;Search for specific text line in the WMIC.exe output file and write the success\failure to the results.txt file If StringInStr(FileRead("C:\software.txt"), "My Software Example") Then FileWriteLine($results , "My Software Example is installed") Else FileWriteLine($results , "ATTENTION My Software Example is NOT installed") EndIf FileClose($results) Thanks again Melba Link to comment Share on other sites More sharing options...
jdelaney Posted May 13, 2014 Share Posted May 13, 2014 (edited) If you use an INI, or XML file, it will be easier to create, and then re-read, later. ; once you have the collection of apps: Local $aApplications[5][2]=[ _ ["app1","1.1.2.3"], _ ["app2","2.1.2.3"], _ ["app3","3.1.2.3"], _ ["app4","4.1.2.3"], _ ["app5","5.1.2.3"]] $sXMLOutput = @DesktopDir & "\Test.xml" ; output to xml $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.loadXML("<Applications></Applications>") $oApplications = $oXML.documentelement For $i = 0 To UBound($aApplications)-1 $oApplication = $oXML.createElement("Application") $oApplication.setAttribute("name",$aApplications[$i][0]) $oApplication.setAttribute("version",$aApplications[$i][1]) $oApplications.appendChild($oApplication) Next ConsoleWrite($oXML.xml) $oXML.save($sXMLOutput) ; example of querying later $oApplications = $oXML.SelectNodes("//Application") For $oApplication In $oApplications ConsoleWrite("Application Name=" & $oApplication.getAttribute("name") & ", version=" & $oApplication.getAttribute("version") & @CRLF) Next ConsoleWrite(@CRLF) ; example of querying specific application $oApplication = $oXML.SelectSingleNode("//Application[@name='app3']") ConsoleWrite("Application Name=" & $oApplication.getAttribute("name") & ", version=" & $oApplication.getAttribute("version") & @CRLF) output, example: Application Name=app1, version=1.1.2.3 Application Name=app2, version=2.1.2.3 Application Name=app3, version=3.1.2.3 Application Name=app4, version=4.1.2.3 Application Name=app5, version=5.1.2.3 Application Name=app3, version=3.1.2.3 But regexp's would work too, as long as you had some sort of naming convention durring the writing. Edited May 13, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now