Jump to content

Need Help w/ DOS to Array


Casey
 Share

Recommended Posts

On an ever evolving GUI that our support shop uses for system builds, I have a chained install and some canned Bitlocker commands. I was asked to write a QA routine to check to make sure that everything was getting done and display it in a condensed form.

I have been attempting to place the results of the check in a 2D array and displaying it. I can't seem to grasp two concepts. First, most of how arrays work and second how to capture the output of a DOS window and place it in column 2 of the 2D array without creating an endless loop. Here is what I have so far that works but not the way I would like:

#include <Array.au3>
#include <file.au3>
#RequireAdmin

Local $CheckArray[9][2]

;ApproveIt 5.9
$Check_Approv = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{29EB04A2-633C-40BE-9673-12DE7360C04E}", "DisplayVersion")
                $CheckArray[0][0] = "ApproveIt 5.9"
            If $Check_Approv == "5.90.167.1000" Then
                $CheckArray[0][1] = "Pass"
            ElseIf $Check_Approv <> "5.90.167.1000" Then
                $CheckArray[0][1] = "FAIL"
            EndIf
;Belarc 8.0.9.0
$Check_Belarc = FileGetVersion("C:\Program Files\Belarc\BelMonitor\BANTMonitorSvc.exe")
                $CheckArray[1][0] = "Belarc 8.0.9.0"
            If $Check_Belarc == "8.0.9.0" Then
                $CheckArray[1][1] = "Pass"
            ElseIf $Check_Belarc <> "8.0.9.0" Then
                $CheckArray[1][1] = "FAIL"
            EndIf
;A.Flash 10.0.32.18
$Check_Flash = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B7B3E9B3-FB14-4927-894B-E9124509AF5A}", "DisplayVersion")
                $CheckArray[2][0] = "A.Flash 10.0.32.18"
            If $Check_Flash == "10.0.32.18" Then
                $CheckArray[2][1] = "Pass"
            ElseIf $Check_Flash <> "10.0.32.18" Then
                $CheckArray[2][1] = "FAIL"
            EndIf
;A.Reader 9.2.0
$Check_Reader = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A92000000001}", "DisplayVersion")
                $CheckArray[3][0] = "A.Reader 9.2.0"
            If $Check_Reader == "9.2.0" Then
                $CheckArray[3][1] = "Pass"
            ElseIf $Check_Reader <> "9.2.0" Then
                $CheckArray[3][1] = "FAIL"
            EndIf
;A.Shockwave 11.5.2.602
$Check_Shock = FileGetVersion("C:\WINDOWS\system32\Adobe\Shockwave 11\SwInit.exe")
                $CheckArray[4][0] = "A.Shockwave 11.5.2.602"
            If $Check_Shock == "11.5.2.602" Then
                $CheckArray[4][1] = "Pass"
            ElseIf $Check_Shock <> "11.5.2.602" Then
                $CheckArray[4][1] = "FAIL"
            EndIf
;JRE6 Update 17
$Check_Java = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83216017FF}", "DisplayVersion")
                $CheckArray[5][0] = "JRE6 Update 17"
            If $Check_Java == "6.0.170" Then
                $CheckArray[5][1] = "Pass"
            ElseIf $Check_Java <> "6.0.170" Then
                $CheckArray[5][1] = "FAIL"
            EndIf
;PureEdge 6.5
$Check_Pure = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C07D2510-3FB9-411F-B3A4-E93AC17BE3A4}", "DisplayVersion")
                $CheckArray[6][0] = "PureEdge 6.5"
            If $Check_Pure == "1.0" Then
                $CheckArray[6][1] = "Pass"
            ElseIf $Check_Pure <> "1.0" Then
                $CheckArray[6][1] = "FAIL"
            EndIf
;DPI Scaling 96
$Check_DPI = RegRead("HKEY_CURRENT_CONFIG\Software\Fonts", "LogPixels")
                $CheckArray[7][0] = "DPI Scaling 96"
            If $Check_DPI == "96" Then
                $CheckArray[7][1] = "Pass"
            ElseIf $Check_DPI <> "96" Then
                $CheckArray[7][1] = "FAIL"
            EndIf
;Hibernation Off
$Check_Hiber = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\VolumeCaches\Hibernation File", "Folder")
                $CheckArray[8][0] = "Hibernation Off"
            If $Check_Hiber == "?:\hiberfil.sys" Then
                $CheckArray[8][1] = "Pass"
            ElseIf $Check_Hiber <> "?:\hiberfil.sys" Then
                $CheckArray[8][1] = "FAIL"
            EndIf

_ArrayDisplay($CheckArray, "QC Check")
;-----------------------------------------------------------
$Command=@ComSpec & " /c " & "cscript C:\Windows\System32\manage-bde.wsf -status"
RunWait($command & ">" & @scriptdir & "\output.txt","",@sw_hide)
$OutPut = FileRead( @scriptdir & "\output.txt")
FileDelete( @scriptdir & "\output.txt")
MsgBox(0,"",$OutPut)

I borrowed the last 5 lines from the web in order to at least get some output for the moment. I attempted to use ConsoleRead but all I end up with is a loop that continues to respawn the array. This is probably because I am not understanding something fundamental about arrays. Mind you that I understand that the array is still there once run because if I remove that section of code, recompile and only run the following I still have the array appearing endlessly. Here is the replacement code that fails which was run @compiled.

------------------------------------------------------------
$Command=@ComSpec & " /c " & "cscript C:\Windows\System32\manage-bde.wsf -status"
Run($command & " | QC_Check_Test.exe","",@sw_hide)
Local $data
While True
    $data &= ConsoleRead()
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "", "Received: " & @CRLF & @CRLF & $data)

I also attempted to use StdoutRead which caused the same behavior. I anyone has a moment, could you identify where I am going wrong. In the end I was expecting something conseptually like this which I can't sort out. Everything in one arraydisplay neatly ordered.

#include <Array.au3>
#include <file.au3>
#RequireAdmin

Local $CheckArray[9][2]

;ApproveIt 5.9
$Check_Approv = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{29EB04A2-633C-40BE-9673-12DE7360C04E}", "DisplayVersion")
                $CheckArray[0][0] = "ApproveIt 5.9"
            If $Check_Approv == "5.90.167.1000" Then
                $CheckArray[0][1] = "Pass"
            ElseIf $Check_Approv <> "5.90.167.1000" Then
                $CheckArray[0][1] = "FAIL"
            EndIf
;Belarc 8.0.9.0
$Check_Belarc = FileGetVersion("C:\Program Files\Belarc\BelMonitor\BANTMonitorSvc.exe")
                $CheckArray[1][0] = "Belarc 8.0.9.0"
            If $Check_Belarc == "8.0.9.0" Then
                $CheckArray[1][1] = "Pass"
            ElseIf $Check_Belarc <> "8.0.9.0" Then
                $CheckArray[1][1] = "FAIL"
            EndIf
;A.Flash 10.0.32.18
$Check_Flash = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B7B3E9B3-FB14-4927-894B-E9124509AF5A}", "DisplayVersion")
                $CheckArray[2][0] = "A.Flash 10.0.32.18"
            If $Check_Flash == "10.0.32.18" Then
                $CheckArray[2][1] = "Pass"
            ElseIf $Check_Flash <> "10.0.32.18" Then
                $CheckArray[2][1] = "FAIL"
            EndIf
;A.Reader 9.2.0
$Check_Reader = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A92000000001}", "DisplayVersion")
                $CheckArray[3][0] = "A.Reader 9.2.0"
            If $Check_Reader == "9.2.0" Then
                $CheckArray[3][1] = "Pass"
            ElseIf $Check_Reader <> "9.2.0" Then
                $CheckArray[3][1] = "FAIL"
            EndIf
;A.Shockwave 11.5.2.602
$Check_Shock = FileGetVersion("C:\WINDOWS\system32\Adobe\Shockwave 11\SwInit.exe")
                $CheckArray[4][0] = "A.Shockwave 11.5.2.602"
            If $Check_Shock == "11.5.2.602" Then
                $CheckArray[4][1] = "Pass"
            ElseIf $Check_Shock <> "11.5.2.602" Then
                $CheckArray[4][1] = "FAIL"
            EndIf
;JRE6 Update 17
$Check_Java = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83216017FF}", "DisplayVersion")
                $CheckArray[5][0] = "JRE6 Update 17"
            If $Check_Java == "6.0.170" Then
                $CheckArray[5][1] = "Pass"
            ElseIf $Check_Java <> "6.0.170" Then
                $CheckArray[5][1] = "FAIL"
            EndIf
;PureEdge 6.5
$Check_Pure = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C07D2510-3FB9-411F-B3A4-E93AC17BE3A4}", "DisplayVersion")
                $CheckArray[6][0] = "PureEdge 6.5"
            If $Check_Pure == "1.0" Then
                $CheckArray[6][1] = "Pass"
            ElseIf $Check_Pure <> "1.0" Then
                $CheckArray[6][1] = "FAIL"
            EndIf
;DPI Scaling 96
$Check_DPI = RegRead("HKEY_CURRENT_CONFIG\Software\Fonts", "LogPixels")
                $CheckArray[7][0] = "DPI Scaling 96"
            If $Check_DPI == "96" Then
                $CheckArray[7][1] = "Pass"
            ElseIf $Check_DPI <> "96" Then
                $CheckArray[7][1] = "FAIL"
            EndIf
;Hibernation Off
$Check_Hiber = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\VolumeCaches\Hibernation File", "Folder")
                $CheckArray[8][0] = "Hibernation Off"
            If $Check_Hiber == "?:\hiberfil.sys" Then
                $CheckArray[8][1] = "Pass"
            ElseIf $Check_Hiber <> "?:\hiberfil.sys" Then
                $CheckArray[8][1] = "FAIL"
            EndIf

$CheckArray[9][0] = "Bitlocker Status"

;Begin what doesn't work 
$Command=@ComSpec & " /c " & "cscript C:\Windows\System32\manage-bde.wsf -status"
Run($command & " | QC_Check_Test.exe","",@sw_hide)
Local $data
While True
    $data &= ConsoleRead()
    ;Something here that will appeand the data to the end of column 2 in subsequent rows until end of DOS ouput
    If @error Then ExitLoop
    Sleep(25)
WEnd

_ArrayDisplay($CheckArray, "QC Check")
Link to comment
Share on other sites

I am not 100% sure what you need but I think what you want is to use this code

$Command=@ComSpec & " /c " & "cscript C:\Windows\System32\manage-bde.wsf -status"
Run($command & " | QC_Check_Test.exe","",@sw_hide)
Local $data
While True
    $data &= ConsoleRead()
    ;Something here that will appeand the data to the end of column 2 in subsequent rows until end of DOS ouput
    If @error Then ExitLoop
    Sleep(25)
WEnd

and take the data recieved each time add a new row in the array and drop that data in column 2?

if I am right here is how I would do it

$Command=@ComSpec & " /c " & "cscript C:\Windows\System32\manage-bde.wsf -status"
Run($command & " | QC_Check_Test.exe","",@sw_hide)
Local $data
While True
    Local $dataAdd = ConsoleRead()
    $data &= $dataAdd
    ReDim $CheckArray[UBound($CheckArray)+1][2]
    $CheckArray[UBound($CheckArray)-1][1]=$dataAdd
    If @error Then ExitLoop
    Sleep(25)
WEnd

that should theoretically do what you want I cannot test it but let me know if that does what you want ;)

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

Sorry, no love. I think I have a problem elsewhere in the script that I can't identify. Something causes cmd.exe and the compiled.exe to spawn an ever growing quantity of those processes. Is it something basic that I am overlooking? I don't see how cmd which is outside of the while is being triggered endlessly.

If there isn't anything the only thing that I can add is that when compiling this I have been seeing a file with a .UPX extension appear for a while then disappearing. Something executing the exe returns a compilation error. Sometimes everything is fine. I uninstalled and reinstalled autoit-v3-setup and autoit-v3.3.1.1-beta-setup but still get the behavior.

BTW, looking at your code your right on the mark for what I was going for. I will study it to advance my understanding. If only I could lick the out of control behavior.

Thanks again.

Link to comment
Share on other sites

The only reason I can think that multiple processes are opened is from the cmd your running not your code.

The UPX is something that AutoIt does after compiling to compress the exe(make it smaller) you can turn this off if you have AutoIt3Wrapper.

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

The only reason I can think that multiple processes are opened is from the cmd your running not your code.

The UPX is something that AutoIt does after compiling to compress the exe(make it smaller) you can turn this off if you have AutoIt3Wrapper.

Strange, the first code sending it to a file works but sending it to the compiled exe doesn't and creates the behavior. I am sorry to say that we will be onto the next OS before I can understand why that is. Moving to Vista now and 7 in 2 years. I guess I will try to figure out a way to operate from the text file and get that into the array. Thanks for your insight. I might have been chasing this endlessly. I have a habit of not letting go.

Thanks again everyone.

Link to comment
Share on other sites

Vista and 7 handle it all the same way the code will still work.

You can use my code very similarly for a file as I provided the way to append to the array you now just need to do it for each line may I suggest StringSplit look it up in the help file.

This is my personal opinion if you have anyway to skip vista and go right to 7... DO IT! ever wonder why they made 7 RIGHT after vista? its because vista didn't work the way they intended and it failed miserably.

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

LOL, Oh, how I wish that was possible. The folks I work for felt that since they had invested the time in testing and validation for a couple hundred thousand systems and having changed the whole associated IA process that we still had to go. They start beta testing 7 in 8 months. Mind you that they also banned Autoit because of its licensing model. Go figure that KIX, VBScript and the like are not banned. Needless to say neither of the other option can compete with this community and the product especially since I can extend SCCMs capabilities with it. Guess that is why I am still here, at least until the evil known as McAfee HIPS is unleashed. I am so looking forward to loosing 90% of my processor.

Thanks again for your help.

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...