Sign in to follow this  
Followers 0
Saymaad Mansoor

Through variables into a text file

10 posts in this topic

Someone please help me with this script, I need the variables returned from the script in a text file the script is :

dim $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 !

Share this post


Link to post
Share on other sites



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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

A text file with the result I previously mentioned like

username1

username2

etc

1 user per line and thats all

Share this post


Link to post
Share on other sites

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

but where is the file saved and how to change files location and name ??

Share this post


Link to post
Share on other sites

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I am using script

dim $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 ?

Share this post


Link to post
Share on other sites

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)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Welcome

8)


NEWHeader1.png

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  
Followers 0