dcoggie Posted December 16, 2015 Share Posted December 16, 2015 (edited) Hi there.I run a script on a remote computer. The script prints out to a text file on the desktop of the remote computer.I want to get a list of all the programs installed on that computer and their versions, and add some of them to the script I use regularly.Using Adobe REader as an example:I want it to print out:eitherAdobe Reader XI - Up to Date!orAdobe Reader XI - Out of Date!So far I have managed to get a list of the program names and print them to a text file on the desktop.Maybe a silly question but how do I store data within the script so I can write some of it to the output file. Such as FileWrite(-----$file = FileOpen("Scan.txt", 2) Const $NODE = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" Local $i = 1 While 1 $var = RegEnumKey($NODE, $i) If @error <> 0 then ExitLoop FileWrite($File, $i, & $var & @CRLF) $i+=1 WEnd Edited December 16, 2015 by dcoggie Link to comment Share on other sites More sharing options...
JohnOne Posted December 16, 2015 Share Posted December 16, 2015 You already doing it, $var holds the data which you are writing to file. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 16, 2015 Moderators Share Posted December 16, 2015 @dcoggie, I typical use WMI for this, just change the $sPC variable to the machine name you're targeting. You could write the array to a file, or to Excel, pretty easily:#include <Array.au3> Local $aApps[1][2] = [["Name", "Version"]] $sPC = @ComputerName If Ping($sPC) Then $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sPC & "\root\cimv2") $aSystem = $oWMI.ExecQuery("Select * from Win32_Product") For $sApp In $aSystem _ArrayAdd($aApps, $sApp.Name & "|" & $sApp.Version) Next Else ConsoleWrite("Unable to Ping " & $sPC & @CRLF) EndIf _ArrayDisplay($aApps) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
dcoggie Posted December 16, 2015 Author Share Posted December 16, 2015 (edited) Boy that was quick! You guys are great. Thanks a heap for your super replies. They were a big help to get me headed on the right path.@JohnOne.I'm sorry I will try to explain myself more clearly. I'm beginning to think that I'm pretty dumb when it comes to scripting.The situation is:I want (you for example) to download my program.Double click it and it will run and output a log file on the desktop.The printout will show you a list of your computer information, including certain programs, but not all of them.In my script I intend to get the list of program names and versions, thenset up a loop:If $var = "Adobe XI" ThenFileWrite($File, $var & "is up to date" & @CRLF)ElseFileWrite($File, $var & "is out of date" & @CRLF) Also, I need the version numbers as well.=============================@JLogan3013I tried using WMI and found that it only output 6 program files apart from the Microsoft files. I have also tried to add "version" to my script but I can't get it to work at all.Func _PGRAMS() Local $PName $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\localhost\root\CIMV2") $colItems = $oWMI.ExecQuery("Select * from Win32_Product") For $objWin32_Product In $colItems $PName = $objWin32-Product.Name Next Return $PName EndFunc ;==>_PGRAMSI have found scripts on the site here but they give too much information and I am not good enough to edit them down. This is 1 of them.expandcollapse popup#include <Array.au3> Global $asApplications $asApplications = _PC_GetProgramList(@ComputerName) If Not @error Then _ArraySort($asApplications, 0, 0, 0, 4) For $i = UBound($asApplications) - 1 To 0 Step - 1 If Not StringLen($asApplications[$i][4]) Then _ArrayDelete($asApplications, $i) Endif Next _ArrayDisplay($asApplications) EndIf Func _PC_GetProgramList($sRPC) Local $sRegUninstallPath = "\\" & $sRPC & "\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" Local $asRegKeys, $asSearchKeys, $asInstalledApps[1][1] $asSearchKeys = StringSplit("DisplayName,DisplayVersion,Publisher,UninstallString,QuietUninstallString,URLInfoAbout", ",") $asRegKeys = _PC_GetRegistryKeys($sRegUninstallPath) If Not @error Then ReDim $asInstalledApps[$asRegKeys[0]][$asSearchKeys[0] + 1] For $i = 1 To $asRegKeys[0] $asInstalledApps[$i - 1][0] = $asRegKeys[$i] For $n = 1 To $asSearchKeys[0] $asInstalledApps[$i - 1][$n] = StringStripWS(RegRead($sRegUninstallPath & $asRegKeys[$i], $asSearchKeys[$n]), 3) Next Next Return $asInstalledApps Else Return SetError(1,0,0) ; Error 1 - unable to read registry. EndIf EndFunc Func _PC_GetRegistryKeys($sRegPath) Local $var, $sResult Local $i = 1 While 1 $var = RegEnumKey($sRegPath, $i) If @error Then If @error <> -1 Then SetError(1) Return 0 EndIf ExitLoop EndIf $sResult &= $var & Chr(128) $i += 1 WEnd Return StringSplit(StringTrimRight($sResult, 1), Chr(128)) EndFunc Edited December 16, 2015 by dcoggie left out a line. Link to comment Share on other sites More sharing options...
jguinch Posted December 16, 2015 Share Posted December 16, 2015 You can use _UninstallList for this job, look at the link in my signature. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
dcoggie Posted December 16, 2015 Author Share Posted December 16, 2015 Hi jguinch. That's a great program however, it's way too much for what I want. All I need is the name and version number of each program. Thanks anyway. Link to comment Share on other sites More sharing options...
dcoggie Posted December 17, 2015 Author Share Posted December 17, 2015 (edited) no answer Edited April 9, 2016 by dcoggie Link to comment Share on other sites More sharing options...
dcoggie Posted December 20, 2015 Author Share Posted December 20, 2015 (edited) no answer Edited April 9, 2016 by dcoggie Link to comment Share on other sites More sharing options...
dcoggie Posted December 23, 2015 Author Share Posted December 23, 2015 Can someone tell me why this is not working? Local $File = FileOpen("scan.txt", 128 + 2) $java_vers = FileGetVersion("C:\Program Files\Java\jre6\bin\java.dll") If FileExists("C:\Program Files\Java\jre6\bin\java.dll") and $java_vers = "[8.0.660.18]" Then FileWrite($File, "Java 8u66" & @CRLF) Else FileWrite($File, "Java out of date" & @CRLF) EndIf FileClose($File) Link to comment Share on other sites More sharing options...
BrewManNH Posted December 23, 2015 Share Posted December 23, 2015 What part of it isn't working? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
dcoggie Posted December 23, 2015 Author Share Posted December 23, 2015 It only ever prints out the second FileWrite command: "Java out of date". It doesn't matter which program I name or how I stack the If commands. Obviously the programs are installed and running. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 24, 2015 Share Posted December 24, 2015 My guess, the version number returned by FileGetVersion doesn't include the brackets around it, so your check fails.BTW, you don't need to see if the file exists, because if it doesn't exist then the FileGetVersion won't return a value. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
dcoggie Posted December 24, 2015 Author Share Posted December 24, 2015 My guess, the version number returned by FileGetVersion doesn't include the brackets around it, so your check fails.BTW, you don't need to see if the file exists, because if it doesn't exist then the FileGetVersion won't return a value.Thanks I'll go and check to see if that fixes it, and if it does I'll kick myself from here to Sunday and back again. Link to comment Share on other sites More sharing options...
dcoggie Posted December 24, 2015 Author Share Posted December 24, 2015 Removing the brackets didn't help. It is outputing the opposite to what it should be. If the program is up to date it returns an out of date message and if the program is out of date it returns the message up to date. Link to comment Share on other sites More sharing options...
jguinch Posted December 24, 2015 Share Posted December 24, 2015 This works for me :$java_vers = FileGetVersion("C:\Program Files (x86)\Java\jre1.8.0_66\bin\java.dll") If $java_vers = "8.0.660.18" Then MsgBox(0, "", "ok")Are you sure about the path ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
dcoggie Posted December 25, 2015 Author Share Posted December 25, 2015 This works for me :$java_vers = FileGetVersion("C:\Program Files (x86)\Java\jre1.8.0_66\bin\java.dll") If $java_vers = "8.0.660.18" Then MsgBox(0, "", "ok")Are you sure about the path ? Thanks, that works for me too. Your uninstall script doesn't give the version so I'm trying different scenarios to get it.To use "fileExist" with your uninstall script would the path be - (@Scriptdir ,_UninstallList)? Link to comment Share on other sites More sharing options...
jguinch Posted December 25, 2015 Share Posted December 25, 2015 Try this :#Include <Array.au3> ; Just for _ArrayDisplay Local $aList = _UninstallList("", "","Publisher|InstallLocation|DisplayVersion") _ArrayDisplay($aList, "All uninstall keys", Default, Default, Default, "RergistryPath|Key|DisplayName|InstallationDate|Publisher|InstallLocation|DisplayVersion") Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
dcoggie Posted December 26, 2015 Author Share Posted December 26, 2015 Try this :#Include <Array.au3> ; Just for _ArrayDisplay Local $aList = _UninstallList("", "","Publisher|InstallLocation|DisplayVersion") _ArrayDisplay($aList, "All uninstall keys", Default, Default, Default, "RergistryPath|Key|DisplayName|InstallationDate|Publisher|InstallLocation|DisplayVersion") Thank you, that is so much easier than trying to track down individual program paths.I still think it was weird how it was printing out the if loops back to front so to speak. Link to comment Share on other sites More sharing options...
dcoggie Posted December 27, 2015 Author Share Posted December 27, 2015 (edited) no answer Edited April 9, 2016 by dcoggie Link to comment Share on other sites More sharing options...
dcoggie Posted December 29, 2015 Author Share Posted December 29, 2015 (edited) no answer Edited April 9, 2016 by dcoggie 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