Jump to content

Recommended Posts

Posted

hmm sometimes i run it and i get "status" as the top result - which is the column heading of the first column.. if i run it again ont he same computer 1 second later without making any changes - it looks good..

weeeeird... could it be that the output is captured too quickly?

still shouldnt capture that heading tho:

bc of this

If $line <> "" And StringInStr($line, "") <> @error Then
Posted

I have the same issue when I run it sometimes. I put an _ArrayDisplay after the While...Wend loop and I see in $array that some of the lines that have been read are in the same element with other lines instead of in their own element, that's why the check fails because the "" is in the string returned, it's just in the wrong place. The lines aren't being split correctly when doing the StdOutRead for some reason.

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 Gude
How 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

Posted

tried this.. seems to be faster

havent seen the issue anymore..

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

$std_output = Run(@ComSpec & " /c net use", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

Local $line, $array[1], $array2[1]
$temp_file = @TempDir & "differentiate_mappings.txt"

If FileExists($temp_file) Then
    FileDelete($temp_file)
EndIf

While 1
    $line = StdoutRead($std_output)
    If @error Then ExitLoop

    If $line <> "" Then
        FileWriteLine($temp_file, $line)
    EndIf
WEnd

$line_count = _FileCountLines($temp_file)

For $x = 1 To $line_count
    $line = FileReadLine($temp_file, $x)

    If StringInStr($line, "") <> 0 Then
        ReDim $array[UBound($array) + 1]
        $array[UBound($array) - 1] = $line
    EndIf
Next

If FileExists($temp_file) Then
    FileDelete($temp_file)
EndIf

For $x = 1 To UBound($array) - 1
    $line = StringStripWS($array[$x], 1 + 4)

    $split = StringSplit($line, Chr(32))

    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $split[2] = ' & $split[2] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    If StringInStr($split[2], ":") <> 0 Then
        ReDim $array2[UBound($array2) + 1][2]

        $array2[UBound($array2) - 1][0] = $split[2]
        $array2[UBound($array2) - 1][1] = "CUSTOM MAPPING"
    Else
        ReDim $array2[UBound($array2) + 1][2]

        $array2[UBound($array2) - 1][0] = $split[1]
        $array2[UBound($array2) - 1][1] = "GPO MAPPING"
    EndIf
Next

_ArrayDisplay($array2)
Posted

Below is some modified code that will greatly speed up the file read process. Change the section of your script that uses FileReadLine with this and see if it's any faster for you.

;~ $line_count = _FileCountLines($temp_file) ; VERY slow with large files or slow drives
$File = FileOpen($temp_file) ; Open file in read mode
While 1
    $line = FileReadLine($File) ; reads the next line in the file, instead of opening the file every time and reading each line until it gets to the line you want
    If @error = -1 Then ExitLoop
    If StringInStr($line, "") <> 0 Then
        ReDim $array[UBound($array) + 1]
        $array[UBound($array) - 1] = $line
    EndIf
WEnd
FileClose($File)

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 Gude
How 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

Posted

the file is never that large and @tempdir is local

i measured both processes and both were under 1 second =)

Posted

Seeing as I already commented on this thread I thought I'd add my version to the mix. :) Main difference is there is no external file.

#include <Constants.au3>
#include <array.au3>

$netUsePID = Run(@ComSpec & " /c net use", @SystemDir, @SW_HIDE, $STDOUT_CHILD)

Local $cmdOut, $cmdoutlast, $buffer, $aLines, $aMappings[1]

;Collect ALL output from Net Use
While 1
    $cmdOut = StdoutRead($netUsePID)
    If @error Then ExitLoop

    If $cmdOut <> $cmdoutlast And $cmdOut <> "" Then
        $cmdoutlast = $buffer
        $buffer &= $cmdOut ; Stores all data for processing
    EndIf

    Sleep(10) ; allows the program to return some characters
WEnd

;Split into lines
$aLines = StringSplit($buffer, @CRLF)
_ArrayDisplay($aLines) ; if you're interested uncomment this line

For $x = 1 To $aLines[0]
    $line = StringStripWS($aLines[$x], 1 + 4)
    If StringInStr($line, "") <> 0 Then
        ;Line contains mapping
        $split = StringSplit($line, Chr(32))
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $split[2] = ' & $split[2] & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
        If StringInStr($split[2], ":") <> 0 Then
            ReDim $aMappings[UBound($aMappings) + 1][2]

            $aMappings[UBound($aMappings) - 1][0] = $split[2]
            $aMappings[UBound($aMappings) - 1][1] = "CUSTOM MAPPING"
        Else
            ReDim $aMappings[UBound($aMappings) + 1][2]

            $aMappings[UBound($aMappings) - 1][0] = $split[1]
            $aMappings[UBound($aMappings) - 1][1] = "GPO MAPPING"
        EndIf
    EndIf
Next

_ArrayDisplay($aMappings) ; if you're interested uncomment this line

Have Fun!

John Morrison

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...