Jump to content

while instead of for


gcue
 Share

Recommended Posts

im not sure what conditions to put here that will make this go faster...

i know i can decrease the for loop to a shorter number but i just want to make sure all the keys are covered...

For $i = 1 To 100

    $b = _HKCU_EnumKey("\\\" & $sComputer & "\Network", $i)
            $iProd = 1
        For $j = 1 To $b[0][0]
            $iProd *= $b[$j][2]
        Next

;If $iProd <> 0 Then ExitLoop
;If $iProd <> 0 Then MsgBox(0,"",$iProd)
If $iProd <> 0 Then ContinueLoop

_ArrayDisplay($b, $i)
    

            If $b[$i][2]=0 Then
;           $path= _HKCU_Read("\\\" & $sComputer & "\\" & $b[$i][0] & "\Network\" & $b[$i][1], "RemotePath")
            $path= _HKCU_Read("\\\" & $sComputer & "\\" & $b[$i][0] & "\Network\" & $b[$i][1], "RemotePath")
            MsgBox(0, "", "User: "  & $b[$i][0] & @CRLF & _
                          "Drive: " & $b[$i][1] & @CRLF & _
                          "Path: " & $path)
            EndIf

                          
WEnd
Link to comment
Share on other sites

im not sure what conditions to put here that will make this go faster...

i know i can decrease the for loop to a shorter number but i just want to make sure all the keys are covered...

For $i = 1 To 100

    $b = _HKCU_EnumKey("\\\" & $sComputer & "\Network", $i)
            $iProd = 1
        For $j = 1 To $b[0][0]
            $iProd *= $b[$j][2]
        Next

;If $iProd <> 0 Then ExitLoop
;If $iProd <> 0 Then MsgBox(0,"",$iProd)
If $iProd <> 0 Then ContinueLoop

_ArrayDisplay($b, $i)
    
            If $b[$i][2]=0 Then
;           $path= _HKCU_Read("\\\" & $sComputer & "\\" & $b[$i][0] & "\Network\" & $b[$i][1], "RemotePath")
            $path= _HKCU_Read("\\\" & $sComputer & "\\" & $b[$i][0] & "\Network\" & $b[$i][1], "RemotePath")
            MsgBox(0, "", "User: "  & $b[$i][0] & @CRLF & _
                          "Drive: " & $b[$i][1] & @CRLF & _
                          "Path: " & $path)
            EndIf

WEnd
You could have at least run Tidy on your demo...

DOC_FileName$:c:\temp\test_tidy.txt

c:\temp\test.au3(26) : ### Tidy Error -> "wend" is closing previous "for"

!> there were 1 error(s) encountered. look in your source for:### Tidy Error:

:P

Post a working demo that we can talk about.

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

sorry bout that

here it is

For $i = 1 To 100

    $b = _HKCU_EnumKey("\\\" & $sComputer & "\Network", $i)
    $iProd = 1
    For $j = 1 To $b[0][0]
        $iProd *= $b[$j][2]
    Next


    If $iProd <> 0 Then ExitLoop
    _ArrayDisplay($b, $i)


    If $b[$i][2] = 0 Then
        $path = _HKCU_Read("\\\" & $sComputer & "\\" & $b[$i][0] & "\Network\" & $b[$i][1], "RemotePath")
        MsgBox(0, "", "User: " & $b[$i][0] & @CRLF & _
                "Drive: " & $b[$i][1] & @CRLF & _
                "Path: " & $path)
    EndIf

    
Next
Edited by gcue
Link to comment
Share on other sites

I don't even understand what the problem is. When you are enumerating registry keys, you don't use For...Next because there is no predetermined count. You use RegEnumKey() with an incremented index until it returns an error.

$index = 1
While 1
$key = RegEnumKey()
If @ERROR Then ExitLoop
$index += 1
WEnd
Link to comment
Share on other sites

didn't work =/

here's what im trying to do using engine's UDFs:

i am trying to check a remote machine's registry for all the users' who have logged into that machine via their hkcurrent user registry entry (engine's UDF can do this!) and identify WHO has a mapped drive locally (instead of thru a logic script) and WHAT LETTER and PATH they have mapped.

here's whats currently happening with the code below:

an arraydisplay (http://www.postyourimage.com/view_image.php?img_id=JgwVTaSkXEaVMi1217861795) shows which users currently have mapped drives (indicated by the letter they have mapped and also the 3rd column of the array that has a value of 0)

the csv file produced however only shows the first user who has the mapped drive and no one else...

===

perhaps someone else who has used engine's UDFs is experiencing the same challenges?

many thanks

here is the code with some minor changes

#include <Array.au3>
#include "HKCUReg.au3"

$asset = "d0058256"

$toolsdir=@ScriptDir

$file = FileOpen($toolsdir & "\maps.csv", 1)

If $file = -1 Then
    MsgBox(0, "Local Mapped Drives", 'CSV log file is in use.'&@CRLF & _ 
                          'Please close it before continuing.')
    Return
EndIf

FileClose($file)

$file = $toolsdir & "\maps.csv"

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

FileWrite($file, "User, Drive, Path")


For $i = 1 To 10

    $b = _HKCU_EnumKey("\\\" & $asset & "\Network", $i)
    $iProd = 1
    For $j = 1 To $b[0][0]
        $iProd *= $b[$j][2]
    Next

    If $iProd <> 0 Then ExitLoop

_ArrayDisplay($b, $i)

    If $b[$i][2] = 0 Then
;$path= _HKCU_Read("\\\" & $asset & "\\" & $b[$i][0] & "\Network\" & $b[$i][1], "RemotePath")
;$path = _HKCU_Read("\\\" & $asset & "\\" & $b[$i][0] & "\Network\" & $b[$i][1], "RemotePath")
        $path = _HKCU_Read("\\\" & $asset & "\Network\" & $b[$i][1], "RemotePath")

FileWrite($file, '' &@CRLF & _
                $b[$i][0] & "," & $b[$i][1] & "," & $path)


    EndIf   
Next

ShellExecute($file)
Edited by gcue
Link to comment
Share on other sites

Hi gcue.

This code should report all mapped drives per user on the target computer.

#include <Array.au3>
#include "HKCUReg.au3"

$sComputer = @ComputerName

$a = GetProfile("", $sComputer)

Dim $k, $aUser[1]
For $i = 1 To $a[0][0]
    While 1
        $k += 1
        $b = _HKCU_EnumKey("\\\" & $sComputer & "\\" & $a[$i][0] & "\Network", $k)
        If $b[1][2] Then ExitLoop
        $iUBound = UBound($aUser)
        ReDim $aUser[$iUBound + 1]
        $aUser[$iUbound] = $b
    WEnd
    _ArrayDisplay($aUser, $a[$i][0])
Next

Please try it and report back. Since there are no mapped drives on my personal computer.

Please note that I am using an internal use only function from HKCUReg.au3 UDF, GetProfile() to determine the users that logged to that computer at least once. That way I can use _HKCU_EnumKey for each user at a time and determine all the mapped drives for that user.

Also, I am sure there are others ways to get what you need.

Regards.

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Sorry. I made a stupid mistake!

#include <Array.au3>
#include "HKCUReg.au3"

$sComputer = @ComputerName

$a = GetProfile("", $sComputer)

Dim $k, $aUser[1]
For $i = 1 To $a[0][0]
    While 1
        $k += 1
        $b = _HKCU_EnumKey("\\\" & $sComputer & "\\" & $a[$i][0] & "\Network", $k)
        If $b[1][2] Then ExitLoop
        $iUBound = UBound($aUser)
        ReDim $aUser[$iUBound + 1]
        $aUser[$iUbound] = $b[1][1]
    WEnd
    _ArrayDisplay($aUser, $a[$i][0])
Next

Please try it again.

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Try this one

#include <Array.au3>
#include "HKCUReg.au3"

$sComputer = @ComputerName

$a = GetProfile("", $sComputer)

Dim $k, $asAll[$a[0][0] + 1]
$asAll[0] = $a[0][0]
For $i = 1 To $a[0][0]
    Dim $asUser[1]
    While 1
        $k += 1
        $b = _HKCU_EnumKey("\\\" & $sComputer & "\\" & $a[$i][0] & "\Network", $k)
        If $b[1][2] <> 0 Then
            $asUser[0] = UBound($asUser) - 1
            ExitLoop
        EndIf
        $iUBound = UBound($asUser)
        ReDim $asUser[$iUBound + 1]
        $asUser[$iUbound] = $b[1][1]
        $b = 0
    WEnd
    $asAll[$i] = $asUser
    $asUser = 0
    _ArrayDisplay($asAll[$i], $a[$i][0])
Next

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

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