Jump to content
Sign in to follow this  
allSystemsGo

Organizing an array

Recommended Posts

allSystemsGo

I would like to produce an array where one column holds the username and the other column holds the client name for that user. So far, I have all of the data (as well as what I call "junk data", which in this case is the SID of the user) and the two columns. I just don't know how to split the data into the columns. Any help is appreciated.

Here is the code

#include <Array.au3>
#include <File.au3>
Local $aArray
For $i=1 to 50
Global $sID= RegEnumKey("HKEY_USERS\",$i)
$len= StringLen($sID)

If $len < 9 Then
$file="c:\temp\junk.txt"
FileOpen($file,1)
FileWrite($file,$sID & @CRLF)
FileClose($file)
FileDelete($file)
Else

If $len < 51 Then
$sUser=RegRead("HKEY_USERS\"&$sID&"\"&"Volatile Environment","USERNAME")
$sVenv=RegEnumKey("HKEY_USERS\"&$sID&"\"&"Volatile Environment\",1)
;~ Msgbox(1,"",$sUser)
;~ MsgBox(1,"",$sVenv)
$cClient=RegRead("HKEY_USERS\"&$sID&"\"&"Volatile Environment\"&$sVenv,"CLIENTNAME")
;~ MsgBox(1,"",$cClient)

$file="c:\temp\sid.txt"
FileOpen($file,1)
FileWrite($file,$sID & @CRLF)
FileWrite($file,"Username: "&$sUser & @CRLF)
FileWrite($file,"Computer Name: " &$cClient & @CRLF)
FileClose($file)
Endif
Endif

Next



$file="c:\temp\sid.txt"
Local $aArray
_FileReadToArray($file,$aArray)
_FileWriteFromArray($file,$aArray)
_ArrayDisplay($aArray)
_1Dto2DArray($aArray, 1)
_ArrayDisplay($aArray)

Func _1Dto2DArray(ByRef $aArray, Const $iAdditionalColumns = 1)
    Local Const $iSize = UBound($aArray, 1)

    Local $aReturn[$iSize][$iAdditionalColumns + 1]

    For $A = 0 To $iSize - 1
        $aReturn[$A][0] = $aArray[$A]
    Next

    $aArray = $aReturn

    Return $aReturn
EndFunc   ;==>_1Dto2DArray
FileDelete($file)

Share this post


Link to post
Share on other sites
kylomas

AllSystemsGo,

I would use a technique similar to this (not tested)

#include <Array.au3>
#include <File.au3>

Local $aArray[51][3]
For $i = 1 To 50
    Global $sID = RegEnumKey("HKEY_USERS\", $i)
    $len = StringLen($sID)
    If $len < 9 Then
        $aarray[$i][0] = $sID
    Else
        If $len < 51 Then
            $sUser = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment", "USERNAME")
            $sVenv = RegEnumKey("HKEY_USERS\" & $sID & "\" & "Volatile Environment\", 1)
            $cClient = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment\" & $sVenv, "CLIENTNAME")
            $aarray[$i][0] = $sID
            $aArray[$i][1] = $sUser
            $aArray[$i][2] = $cClient
        EndIf
    EndIf
Next

_arraydisplay($aArray)

Also, your "if..." logic looks suspect. What are you trying to do?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
allSystemsGo

The If logic throws out keys that don't include the subkey that I want, which is "Volatile Environment." If they are less than nine, I throw the data into a junk file and delete it. If the length of the key is not greater than 51, then this is the key I want because each "good" key also gets assigned a second key which is the same name with "_Classes" appended to it. The point of this script is so that when we initially set up a site that uses terminal server, we can run this and know originally what user was being used and where at. So when the customer calls and says "well this is out [blank] computer" we can have a better idea of what they are talking about. Also for documentation.

Share this post


Link to post
Share on other sites
kylomas

Try this (move var def's outside of loop)

#include <Array.au3>
#include <File.au3>

Local $aArray[51][3], $sid, $sUser, $sVenv, $cClient
For $i = 1 To 50
    $sID = RegEnumKey("HKEY_USERS\", $i)
    $len = StringLen($sID)
    If $len < 9 Then
    Else
        If $len < 51 Then
            $sUser = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment", "USERNAME")
            $sVenv = RegEnumKey("HKEY_USERS\" & $sID & "\" & "Volatile Environment\", 1)
            $cClient = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment\" & $sVenv, "CLIENTNAME")
            $aarray[$i][0] = $sID
            $aArray[$i][1] = $sUser
            $aArray[$i][2] = $cClient
        EndIf
    EndIf
Next

_arraydisplay($aArray)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
kylomas

AllSystemsGo,

Corrected code

#include <Array.au3>
#include <File.au3>

Local $aArray[51][3], $sid, $sUser, $sVenv, $cClient
For $i = 1 To 50
    $sID = RegEnumKey("HKEY_USERS\", $i)
    $len = StringLen($sID)
    If $len > 9 and $len < 51 then
        $sUser = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment", "USERNAME")
        $sVenv = RegEnumKey("HKEY_USERS\" & $sID & "\" & "Volatile Environment\", 1)
        $cClient = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment\" & $sVenv, "CLIENTNAME")
        $aarray[$i][0] = $sID
        $aArray[$i][1] = $sUser
        $aArray[$i][2] = $cClient
    EndIf
Next

_arraydisplay($aArray)

kylomas

edit:

another version

#include <Array.au3>
#include <File.au3>

Local $aArray[51][2], $sid, $sUser, $sVenv, $cClient
For $i = 1 To 50
    $sID = RegEnumKey("HKEY_USERS\", $i)
    $len = StringLen($sID)
    If $len > 9 and $len < 51 then
        $sVenv = RegEnumKey("HKEY_USERS\" & $sID & "\" & "Volatile Environment\", 1)
        $aarray[$i][0] = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment", "USERNAME")
        $aArray[$i][1] = RegRead("HKEY_USERS\" & $sID & "\" & "Volatile Environment\" & $sVenv, "CLIENTNAME")
    EndIf
Next

_arraydisplay($aArray)
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
allSystemsGo

Thanks for your help.

So far this is working for me, other than some formatting that I am trying to work out.

#include <Array.au3>
#include <File.au3>
Local $aArray[51][2]
$aArray[0][0]="Username"
$aArray[0][1]="Client Name"
For $i=1 to 50
Global $sID= RegEnumKey("HKEY_USERS\",$i)
$len= StringLen($sID)

If $len < 9 Then
$file="c:\temp\junk.txt"
FileOpen($file,1)
FileWrite($file,$sID & @CRLF)
FileClose($file)
FileDelete($file)
Else

If $len < 51 Then
$sUser=RegRead("HKEY_USERS\"&$sID&"\"&"Volatile Environment","USERNAME")
$sVenv=RegEnumKey("HKEY_USERS\"&$sID&"\"&"Volatile Environment\",1)
;~ Msgbox(1,"",$sUser)
;~ MsgBox(1,"",$sVenv)
$cClient=RegRead("HKEY_USERS\"&$sID&"\"&"Volatile Environment\"&$sVenv,"CLIENTNAME")
;~ MsgBox(1,"",$cClient)
$aArray[$i][0] = $sUser
$aArray[$i][1] = $cClient

$file="c:\temp\sid.txt"
;~ FileOpen($file,1)
;~ FileWrite($file,$sID & @CRLF)
;~ FileWrite($file,"Username: "&$sUser & @CRLF)
;~ FileWrite($file,"Computer Name: " &$cClient & @CRLF)
;~ FileClose($file)
Endif
Endif

Next

Share this post


Link to post
Share on other sites
kylomas

OK, but why use the interim files and variables?

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
allSystemsGo

Need the file so that I can document it.

Share this post


Link to post
Share on other sites
kylomas

Post the full code that does not work, please.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
guinness

Try this version >>


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
allSystemsGo

I had this problem before lol. Just need to use a different UDF.

Thought that error looked familiar.. :sweating:

edit

Thanks for the reminder guinness!

Edited by allSystemsGo

Share this post


Link to post
Share on other sites
guinness

I didn't pay attention to who was in that thread. Normally I don't recommend this normally ... so either remember in the future OR replace the UDF with this newer version.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
allSystemsGo

Don't recommend what?

Share this post


Link to post
Share on other sites
guinness

I normally don't recommend overwriting the stable UDF version, because what tends to happen is people either forget or they modify it and don't tell.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
allSystemsGo

Oh right. Yeah, just need to keep it in mind.

Share this post


Link to post
Share on other sites
allSystemsGo

How can I delete fields in an array that have no data in them?

Share this post


Link to post
Share on other sites
allSystemsGo

_ArrayDelete

I am aware of _ArrayDelete. When I use this function with my code, it doesn't write the rest of the data, so I am guess my logic is flawed.

Share this post


Link to post
Share on other sites
czardas

I'm not entirely sure what you are doing. Here's what I think you might want to do: Create a 2D array large enough to hold all entries. Enter some values (but not all of them) into the array. Delete the elements that are empty. If this is true, then only fill the first part of the array and leave the last elements empty. Resize using Redim. I might have misunderstood.

Edited by czardas

Share this post


Link to post
Share on other sites
kylomas

One way delete empty elements

;
;
;

#include <array.au3>

local $source_array[5] = [1,'',3,4,5]
local $target_array[ubound($source_array)]

_arraydisplay($source_array,'Before')

for $1 = ubound($source_array)-1 to 0 step -1
    if $source_array[$1] = '' then _arraydelete($source_array,$1)
Next

_arraydisplay($source_array,'After')

kylomas

edit:

what do you mean by this?

it doesn't write the rest of the data,

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  

×