allSystemsGo Posted May 8, 2013 Share Posted May 8, 2013 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 expandcollapse popup#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) Link to comment Share on other sites More sharing options...
kylomas Posted May 8, 2013 Share Posted May 8, 2013 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 Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 8, 2013 Author Share Posted May 8, 2013 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. Link to comment Share on other sites More sharing options...
kylomas Posted May 8, 2013 Share Posted May 8, 2013 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 Link to comment Share on other sites More sharing options...
kylomas Posted May 8, 2013 Share Posted May 8, 2013 (edited) 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 May 8, 2013 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 Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 8, 2013 Author Share Posted May 8, 2013 Thanks for your help. So far this is working for me, other than some formatting that I am trying to work out. expandcollapse popup#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 Link to comment Share on other sites More sharing options...
kylomas Posted May 8, 2013 Share Posted May 8, 2013 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 Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 8, 2013 Author Share Posted May 8, 2013 Need the file so that I can document it. Link to comment Share on other sites More sharing options...
kylomas Posted May 8, 2013 Share Posted May 8, 2013 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 Link to comment Share on other sites More sharing options...
guinness Posted May 8, 2013 Share Posted May 8, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 8, 2013 Author Share Posted May 8, 2013 (edited) I had this problem before lol. Just need to use a different UDF. Thought that error looked familiar.. edit Thanks for the reminder guinness! Edited May 8, 2013 by allSystemsGo Link to comment Share on other sites More sharing options...
guinness Posted May 8, 2013 Share Posted May 8, 2013 (edited) 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 May 8, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 8, 2013 Author Share Posted May 8, 2013 Don't recommend what? Link to comment Share on other sites More sharing options...
guinness Posted May 8, 2013 Share Posted May 8, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 8, 2013 Author Share Posted May 8, 2013 Oh right. Yeah, just need to keep it in mind. Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 9, 2013 Author Share Posted May 9, 2013 How can I delete fields in an array that have no data in them? Link to comment Share on other sites More sharing options...
czardas Posted May 9, 2013 Share Posted May 9, 2013 How can I delete fields in an array that have no data in them?_ArrayDelete operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
allSystemsGo Posted May 9, 2013 Author Share Posted May 9, 2013 _ArrayDeleteI 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. Link to comment Share on other sites More sharing options...
czardas Posted May 9, 2013 Share Posted May 9, 2013 (edited) 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 May 9, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
kylomas Posted May 9, 2013 Share Posted May 9, 2013 (edited) 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')kylomasedit:what do you mean by this? it doesn't write the rest of the data, Edited May 9, 2013 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now