Saymaad Mansoor Posted March 9, 2006 Share Posted March 9, 2006 Someone please help me with this script, I need the variables returned from the script in a text file the script is : expandcollapse popupdim $SID $SID = _UserSID() ;$SID = _UserSID("UserName") ;$SID = _UserSID('UserName', 'RemoteComputerName') if IsArray($SID) Then for $x = 1 to $SID[0][0] msgbox(0, 'User SID', $SID[0][$x] & ' ====> ' & $SID[1][$x]) Next Else MsgBox(0, "", "Is not an Array.") EndIf ;=============================================================================== ; Function Name: _UserSID() ; ; Description: Return a 2 dimensional array first username second SID. ; ; Syntax: _UserSID ( [$s_UserName, $s_RemoteComputer] ) ; ; Parameter(s): $s_UserName = Username to get SID. ; $s_RemoteComputer = ComputerName on the network ; ; Requirement(s): External: = None. ; Internal: = None. ; ; Return Value(s): On Success: = Returns 2 dimensional array with UserName, SID and sets @error to 0. ; On Failure: = Returns "" and sets @error to 1. ; ; Author(s): Dan Colón ; ; Note(s): ; ; Example(s): ; _UserSID("DColon") it will return DColon SID ; _UserSID() it will return every user SID ;=============================================================================== Func _UserSID($s_UserName = "All", $s_RemoteComputer = '') If $s_UserName = '' Then $s_UserName = 'All' If $s_RemoteComputer <> '' Then If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\' EndIf EndIf Local $line, $var, $ProfilePath, $i = 1 Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" Local Const $regkeyval1 = "ProfilesDirectory" Local Const $regkeyval2 = "ProfileImagePath" $ProfilePath = RegRead($regkey, $regkeyval1) While 1 $line = RegEnumkey($regkey, $i) $var = RegRead ( $regkey & $line, $regkeyval2) If @error = 1 Or @error = -1 Then ExitLoop If $s_UserName == "All" Then If Not IsDeclared("aArray") Then Dim $aArray[1][1] ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1] $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1) $aArray[1][UBound($aArray) - 1] = $line $aArray[0][0] = UBound($aArray) - 1 ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then If Not IsDeclared("aArray") Then Dim $aArray[1][1] ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1] $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1) $aArray[1][UBound($aArray) - 1] = $line $aArray[0][0] = UBound($aArray) - 1 EndIf $i = $i + 1 WEnd If Not IsDeclared("aArray") Then SetError(1) Return("") Else SetError(0) Return($aArray) EndIf EndFunc Authors comment Then all you have to do is used a for loop for $x = 1 to $SID[0][0] _GUICtrlComboAddString($h_combobox, $SID[0][$x]) next and that will add username to the combo list The result I want in text file : username1 username2 username3 and so on.... please help me with this script ! Link to comment Share on other sites More sharing options...
Valuater Posted March 9, 2006 Share Posted March 9, 2006 there are different approaches on how to store information in a file csv files are comma delimited for use in MS Ecel... etc there are text files like you have above for simple printing and displaying there are .ini files for exact reading/updating/replacing so..... the question is how are you going to use that information in the future 8) Link to comment Share on other sites More sharing options...
Saymaad Mansoor Posted March 9, 2006 Author Share Posted March 9, 2006 A text file with the result I previously mentioned like username1 username2 etc 1 user per line and thats all Link to comment Share on other sites More sharing options...
Valuater Posted March 9, 2006 Share Posted March 9, 2006 then all you have to do is used a for loop.... again $W_File = fileOpen($FileName, 2) for $x = 1 to $SID[0][0] FileWriteLine($W_File, $SID[0][$x]) next FileClose($W_File) and that will add username to the file 8) Link to comment Share on other sites More sharing options...
Saymaad Mansoor Posted March 9, 2006 Author Share Posted March 9, 2006 but where is the file saved and how to change files location and name ?? Link to comment Share on other sites More sharing options...
Valuater Posted March 9, 2006 Share Posted March 9, 2006 above all of that.. ( ijust wrote ) put this $FileName = " C:\My_File.txt" that tells the FileOpen() the name of the file and the location you can put any location or name you want 8) Link to comment Share on other sites More sharing options...
Saymaad Mansoor Posted March 9, 2006 Author Share Posted March 9, 2006 I am using script expandcollapse popupdim $SID $SID = _UserSID() ;$SID = _UserSID("UserName") ;$SID = _UserSID('UserName', 'RemoteComputerName') if IsArray($SID) Then for $x = 1 to $SID[0][0] msgbox(0, 'User SID', $SID[0][$x] & ' ====> ' & $SID[1][$x]) Next Else MsgBox(0, "", "Is not an Array.") EndIf ;=============================================================================== ; Function Name: _UserSID() ; ; Description: Return a 2 dimensional array first username second SID. ; ; Syntax: _UserSID ( [$s_UserName, $s_RemoteComputer] ) ; ; Parameter(s): $s_UserName = Username to get SID. ; $s_RemoteComputer = ComputerName on the network ; ; Requirement(s): External: = None. ; Internal: = None. ; ; Return Value(s): On Success: = Returns 2 dimensional array with UserName, SID and sets @error to 0. ; On Failure: = Returns "" and sets @error to 1. ; ; Author(s): Dan Colón ; ; Note(s): ; ; Example(s): ; _UserSID("DColon") it will return DColon SID ; _UserSID() it will return every user SID ;=============================================================================== Func _UserSID($s_UserName = "All", $s_RemoteComputer = '') If $s_UserName = '' Then $s_UserName = 'All' If $s_RemoteComputer <> '' Then If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\' EndIf EndIf Local $line, $var, $ProfilePath, $i = 1 Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" Local Const $regkeyval1 = "ProfilesDirectory" Local Const $regkeyval2 = "ProfileImagePath" $ProfilePath = RegRead($regkey, $regkeyval1) While 1 $line = RegEnumkey($regkey, $i) $var = RegRead ( $regkey & $line, $regkeyval2) If @error = 1 Or @error = -1 Then ExitLoop If $s_UserName == "All" Then If Not IsDeclared("aArray") Then Dim $aArray[1][1] ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1] $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1) $aArray[1][UBound($aArray) - 1] = $line $aArray[0][0] = UBound($aArray) - 1 ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then If Not IsDeclared("aArray") Then Dim $aArray[1][1] ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1] $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1) $aArray[1][UBound($aArray) - 1] = $line $aArray[0][0] = UBound($aArray) - 1 EndIf $i = $i + 1 WEnd If Not IsDeclared("aArray") Then SetError(1) Return("") Else SetError(0) Return($aArray) EndIf $FileName = "C:\test.txt" $W_File = fileOpen($FileName, 2) for $x = 1 to $SID[0][0] FileWriteLine($W_File, $SID[0][$x]) next FileClose($W_File) EndFunc but still I can get the list exported to test.txt I also created an empty file there but no result what is the thing that I am doing wrong ? Link to comment Share on other sites More sharing options...
Valuater Posted March 9, 2006 Share Posted March 9, 2006 remove what you put at the bottom ( that is inside a function call... thats not what you want ) replace these lines if IsArray($SID) Then for $x = 1 to $SID[0][0] msgbox(0, 'User SID', $SID[0][$x] & ' ====> ' & $SID[1][$x]) Next Else MsgBox(0, "", "Is not an Array.") EndIf with this $FileName = "C:\test.txt" $W_File = fileOpen($FileName, 2) if IsArray($SID) Then for $x = 1 to $SID[0][0] msgbox(0, 'User SID', $SID[0][$x] & ' ====> ' & $SID[1][$x]) FileWriteLine($W_File, $SID[0][$x] & ' ====> ' & $SID[1][$x]) Next Else MsgBox(0, "", "Is not an Array.") EndIf FileClose($W_File) 8) Link to comment Share on other sites More sharing options...
Saymaad Mansoor Posted March 9, 2006 Author Share Posted March 9, 2006 Oh thnx God now I get the list working I hope it works on windows 2000 cause on XP I have another workaround mentioned before but on windows 2000 it dosent works but if this works it would be great thnx for your help Valuater topic closed Link to comment Share on other sites More sharing options...
Valuater Posted March 9, 2006 Share Posted March 9, 2006 Welcome 8) 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