Jump to content

grabbing dos output and processing


gcue
 Share

Recommended Posts

it's actuallly a hard return, because if i put text after the value it comes on the next line

im using stringtrimright($RegArray[$u], 1) for both values in the for loop - and they look good.

what syntax can i use outside of the loop to get rid of the trailing value on each variable ($RegArray and $SerArray)?

Link to comment
Share on other sites

it's actuallly a hard return, because if i put text after the value it comes on the next line

im using stringtrimright($RegArray[$u], 1) for both values in the for loop - and they look good.

what syntax can i use outside of the loop to get rid of the trailing value on each variable ($RegArray and $SerArray)?

Thats the thing, is I put a stringtrimright() in the function and it dropped the last character from each entry which was not a space, so I am unsure where you are seeing the space.... can you show me? Post a piece of code that shows the space and I will try to help.
Link to comment
Share on other sites

when i do the for loop here:

For $u = 1 To $RegArray[0]
    RegRead("\\d0075931\hklm\system\controlset001\enum\" & $RegArray[$u] & "\control", "")

    If @error <> 1 Then
        MsgBox(0, "", $SerArray[$u] & " is a monitor in use.")
    EndIf
Next

the path was not found, so i did this:

For $u = 1 To $RegArray[0]

msgbox(0, "", $RegArray[u] & "\control")
msgbox(0, "", $SerArray[u] & "\control")

Next

and saw that "\control" was starting on a new line with both values

Edited by gcue
Link to comment
Share on other sites

I am sorry, but I am still unable to see a space or break in there anywhere...

Here is my reproducer of me NOT seeing it:

#include<array.au3>
#include<file.au3>
Local $array

RunWait(@ComSpec & ' /c ' & FileGetShortName(@ScriptDir & '\dumpedid.exe') & ' > "' & @TempDir & '\dumpedidTEMP.txt"', @SystemDir, @SW_HIDE)
$RegArray = DumpedidFileToArray(@TempDir & '\dumpedidTEMP.txt', "Registry Key             : ")
$SerArray = DumpedidFileToArray(@TempDir & '\dumpedidTEMP.txt', "Serial Number            : ")

$teststring = ''
For $u = 1 To $RegArray[0]
    $teststring &= "\\d0075931\hklm\system\controlset001\enum\" & $RegArray[$u] & "\control"
    If $u <> $RegArray[0] Then $teststring &= @CRLF
Next
If FileExists( @TempDir & "\teststring.txt" ) Then FileDelete( @TempDir & "\teststring.txt" )
FileWrite( @TempDir & "\teststring.txt", $teststring )
ShellExecute( "notepad", @TempDir & "\teststring.txt" )

Func DumpedidFileToArray($file, $searchstring)
    Dim $temparray, $filterarray[1]
    _FileReadToArray( $file, $temparray)
    For $a = 1 To UBound($temparray) - 1
        If StringInStr($temparray[$a], $searchstring) Then _ArrayAdd( $filterarray, StringReplace($temparray[$a], $searchstring, '') )
    Next
    $filterarray[0] = UBound($filterarray) - 1
    Return $filterarray
EndFunc   ;==>DumpedidFileToArray

Can you please post a reproducer of you seeing it?

Link to comment
Share on other sites

not sure what u mean by reproducer..

would you be able to tell me where i can do the stringtrim outside of the for loop?

otherwise i can just leave it in the for loop (didnt want to cause its definitely dirtier)

hehe

thanks!

Link to comment
Share on other sites

entire script

many thanks!

i think bc our outputs are different.. the file i sent before was my output

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=clipboard.ico
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <array.au3>
#include <file.au3>

Local $array
$file = (@TempDir & '\dumpedidTEMP.txt')

RunWait(@ComSpec & ' /c ' & FileGetShortName(@ScriptDir & '\dumpedid.exe \\d0075931') & ' > "' & $file);, @SystemDir);, @SW_HIDE)

$RegArray = DumpedidFileToArray($file, "Registry Key             : ")
_ArrayDisplay($RegArray)

$SerArray = DumpedidFileToArray($file, "Serial Number           : ")
_ArrayDisplay($SerArray)


Func DumpedidFileToArray($file, $searchstring)
    Dim $temparray, $filterarray[1]
    _FileReadToArray( $file, $temparray)
    For $a = 1 To UBound($temparray) - 1
        If StringInStr($temparray[$a], $searchstring) Then _ArrayAdd( $filterarray, StringReplace($temparray[$a], $searchstring, '') )
    Next
    $filterarray[0] = UBound($filterarray) - 1
    Return $filterarray
EndFunc  ;==>DumpedidFileToArray


For $u = 1 To $RegArray[0]

$reg = StringTrimRight($RegArray[$u], 1)
$serial = StringTrimRight($SerArray[$u], 1)

;RegRead("\\d0075931\hklm\system\controlset001\enum\" & $RegArray[$u] & "\control", "")
    RegRead("\\d0075931\hklm\system\controlset001\enum\" & $reg & "\control", "")
    
    
;~  If @error <> 1 Then
;~      MsgBox(0, "", $SerArray[$u] & " is a monitor in use.")
;~  EndIf

    If @error <> 1 Then
        MsgBox(0, "", $serial & " is a monitor in use.")
    EndIf
    
Next
Link to comment
Share on other sites

This was working for me on a local machine... try it out for your remote d0075931 machine

#include <array.au3>
#include <file.au3>

Local $array
$file = (@TempDir & '\dumpedidTEMP.txt')
RunWait(@ComSpec & ' /c ' & FileGetShortName(@ScriptDir & '\dumpedid.exe \\d0075931') & ' > "' & $file);, @SystemDir);, @SW_HIDE)
$RegArray = DumpedidFileToArray($file, "Registry Key             : ")
$SerArray = DumpedidFileToArray($file, "Serial Number            : ")

For $u = 1 To $RegArray[0]
    If MonInUse("\\d0075931\hklm\system\controlset001\enum\" & $RegArray[$u]) Then MsgBox(0, "", $SerArray[$u] & " is a monitor in use.")
Next

Func MonInUse($RegKey)
    $a = 1
    While 1
        $key = RegEnumKey($RegKey, $a)
        If @error Then ExitLoop
        If $key = "Control" Then Return True
        $a += 1
    WEnd
    Return False
EndFunc   ;==>MonInUse

Func DumpedidFileToArray($file, $searchstring)
    Dim $temparray, $filterarray[1]
    _FileReadToArray( $file, $temparray)
    For $a = 1 To UBound($temparray) - 1
        If StringInStr($temparray[$a], $searchstring) Then _ArrayAdd( $filterarray, StringReplace($temparray[$a], $searchstring, '') )
    Next
    $filterarray[0] = UBound($filterarray) - 1
    Return $filterarray
EndFunc  ;==>DumpedidFileToArray

EDIT: I still do not see a trailing space, but I think I know where you were hitting a brick wall:

RegRead("\\d0075931\hklm\system\controlset001\enum\" & $reg & "\control", "")

You were reading a default value that had no value set.... I am not sure if this is expected behavior or not but it was causing RegRead to error out.

I will be posting a thread on this to find out if it's a bug or not.

Let me know how it goes for you :)

Edited by danwilli
Link to comment
Share on other sites

ya the script above still doesnt work..

its a combination of that + the trailing space or hard return

help file says:

"To access the (Default) value use "" (a blank string) for the valuename."

Failure: Returns "" and sets the @error flag:

1 if unable to open requested key

2 if unable to open requested main key

3 if unable to remote connect to the registry

-1 if unable to open requested value

-2 if value type not supported

so i check the existance of the "control" subkey.. that passes but i get an error for the value "control" which is expected and i handle with the if @error <> 1

many thanks again for your help.

Link to comment
Share on other sites

Ok, updated Autoit to latest version... now I see the issue, sorry about that.

When I ran on my old version, the key string did not contain a CR like it does now. Anyways, I just used StringStripCR() to solve the issue (i hope)

#include <array.au3>
#include <file.au3>

Local $array
$file = (@TempDir & '\dumpedidTEMP.txt')
RunWait(@ComSpec & ' /c ' & FileGetShortName(@ScriptDir & '\dumpedid.exe \\d0075931') & ' > "' & $file);, @SystemDir);, @SW_HIDE)
$RegArray = DumpedidFileToArray($file, "Registry Key             : ")
$SerArray = DumpedidFileToArray($file, "Serial Number            : ")

For $u = 1 To $RegArray[0]
    If MonInUse("\\d0075931\hklm\system\controlset001\enum\" & $RegArray[$u]) Then MsgBox(0, "", $SerArray[$u] & " is a monitor in use.")
Next

Func MonInUse($RegKey)
    $a = 1
    While 1
        $key = RegEnumKey(StringStripCR($RegKey), $a)
        If @error Then ExitLoop
        If $key = "Control" Then Return True
        $a += 1
    WEnd
    Return False
EndFunc   ;==>MonInUse

Func DumpedidFileToArray($file, $searchstring)
    Dim $temparray, $filterarray[1]
    _FileReadToArray( $file, $temparray)
    For $a = 1 To UBound($temparray) - 1
        If StringInStr($temparray[$a], $searchstring) Then _ArrayAdd( $filterarray, StringReplace($temparray[$a], $searchstring, '') )
    Next
    $filterarray[0] = UBound($filterarray) - 1
    Return $filterarray
EndFunc  ;==>DumpedidFileToArray
Link to comment
Share on other sites

OK, last one then :) (again, I hope LOL)

I put the StringStripCR() into the 'DumpedidFileToArray' function

#include <array.au3>
#include <file.au3>

Local $array
$file = (@TempDir & '\dumpedidTEMP.txt')
RunWait(@ComSpec & ' /c ' & FileGetShortName(@ScriptDir & '\dumpedid.exe \\d0075931') & ' > "' & $file);, @SystemDir);, @SW_HIDE)
$RegArray = DumpedidFileToArray($file, "Registry Key             : ")
$SerArray = DumpedidFileToArray($file, "Serial Number            : ")

For $u = 1 To $RegArray[0]
    If MonInUse("\\d0075931\hklm\system\controlset001\enum\" & $RegArray[$u]) Then MsgBox(0, "", $SerArray[$u] & " is a monitor in use.")
Next

Func MonInUse($RegKey)
    $a = 1
    While 1
        $key = RegEnumKey($RegKey, $a)
        If @error Then ExitLoop
        If $key = "Control" Then Return True
        $a += 1
    WEnd
    Return False
EndFunc   ;==>MonInUse

Func DumpedidFileToArray($file, $searchstring)
    Dim $temparray, $filterarray[1]
    _FileReadToArray( $file, $temparray)
    For $a = 1 To UBound($temparray) - 1
        If StringInStr($temparray[$a], $searchstring) Then _ArrayAdd( $filterarray, StringStripCR(StringReplace($temparray[$a], $searchstring, '')))
    Next
    $filterarray[0] = UBound($filterarray) - 1
    Return $filterarray
EndFunc  ;==>DumpedidFileToArray
Link to comment
Share on other sites

Any time, sorry it took this long... first I was on a different version so I wasn't on the same page as you with the @CR issue, then I started asking all kinds of questions to myself about reading a regkey's default value with no data in it to see if it existed.

Glad we got it working correctly though, and thanks for not giving up on me LOL :)

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