KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

FileOwner problem

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
nick
KiXforms Novice
KiXforms Novice


Joined: 08 Sep 2005
Posts: 1

PostPosted: Thu Sep 29, 2005 6:06 am    Post subject: FileOwner problem Reply with quote

Hello
I have a code, but it will not run. Can help me anybody? where have I save the UDF Function?


Here is my Code##########


; * Requirments DirList Function, KixForms Latest, KiXstart Latest *
; *********************************************************************************


Break On ; Break On to allow user to break out

;**********************************************************************************************************
$KiX = "C:\Kix" ; Set the KiX verable
Call $KiX+'\Functions\DirList().KIX' ;Call the DirList Function into Memory

;Type in the Drive Letters of the Home Drive and the Drive Letter if your Shared Drive
$HomeDrive = "P:"
$SharedDrive = "S:"

;**********************************************************************************************************
;Create Object to KiXstart Form
$FORM = CreateObject("Kixtart.Form")

;**********************************************************************************************************
;Main Form

$FORM.Caption = "Displays Owner of Files & Folders"
$FORM.ScaleHeight = 240
$FORM.ScaleWidth = 405
$FORM.FontSize = 8
$FORM.Center

;**********************************************************************************************************
;Current Directory Label

$ListCurrentDir = $FORM.Label
$ListCurrentDir.Left = 5
$ListCurrentDir.Top = 30
$ListCurrentDir.Width = 380
$ListCurrentDir.Height = 20
$ListCurrentDir.FontSize = 8
$ListCurrentDir.FONTNAME = "Arial"
$ListCurrentDir.Enabled = 0

$lblCurrentDir = $FORM.Label("Current Folder: ")
$lblCurrentDir.Left = 5
$lblCurrentDir.Top = 15
$lblCurrentDir.Width = 120
$lblCurrentDir.Height = 20
$lblCurrentDir.FontSize = 8
$lblCurrentDir.FONTNAME = "Arial"
$lblCurrentDir.Enabled = 0

;**********************************************************************************************************
;ListView for OwnerList

$GetOwnerListBox = $FORM.Listview
$GetOwnerListBox.Left = 5
$GetOwnerListBox.Top = 55
$GetOwnerListBox.Width = 395
$GetOwnerListBox.Height = 160
$GetOwnerListBox.FontSize = 8
$GetOwnerListBox.FONTNAME = "Arial"
$GetOwnerListBox.View = 1
$GetOwnerListBox.SmallImageList = $Form.SmallImageList
$GetOwnerListBox.OnDoubleClick = "ListView_DoubleClick()"
$=$GetOwnerListBox.Columns.Add("Name",250)
$=$GetOwnerListBox.Columns.Add("Owner",125)
$FolderRoot = $SharedDrive+"\"

;**********************************************************************************************************
;Command Button for select Drive

$SPSelect = $FORM.CommandButton
$SPSelect.Left = 280
$SPSelect.Top = 5
$SPSelect.Width = 110
$SPSelect.Height = 20
$SPSelect.FontSize = 8
$SPSelect.FONTNAME = "Arial"
$SPSelect.OnClick = "SPSelect_Click()"

;**********************************************************************************************************
;ProgressBar for DirList

$ProgressBar = $FORM.ProgressBar()
$ProgressBar.Width = 300
$ProgressBar.Height = 15
$ProgressBar.Left = 50
$ProgressBar.Top = 220
$ProgressBar.Style = 2
$ProgressBar.Minimum = 0
$ProgressBar.Enabled = 0

;**********************************************************************************************************
;Objects within Main Form

$FORM.Show ; Show Form

ListView() ; Call ListView Function

While $FORM.Visible
$=Execute($FORM.DoEvents)
Loop
:End
Exit 1

;***********************************************************************************************************
;Call Functions & UDF's ****
;***********************************************************************************************************


;***********************************************************************************************************
;ListView Function

Function ListView()

Enabled(0) ; Call Enabled Function
$ListCurrentDir.Text = $FolderRoot ; Set Current Directory Label
$DirList = DirList($FolderRoot+'*.*',1) ; Create DirList Array
$x = 1
$=$GetOwnerListBox.Items.Add("..",47) ; Create Item for ".."
If SubStr($FolderRoot,1,2) = $HomeDrive $SPSelect.Text = "Click to browse "+$SharedDrive+"\" Else $SPSelect.Text = "Click to browse "+$HomeDrive+"\" EndIf ; Modify the Drive Letter Command Button
$ProgressBar.Maximum = Ubound($DirList) +1 ; Set the maximum value of the ProgressBar to the Upper Bound of the DirList Array
For Each $Object in $DirList
$ProgressBar.Value = $x ; Set the ProgressBar Value
If InStr($Object,"\") = 0 ; If $Object contains "\"
$=$GetOwnerListBox.Items.Add($Object,0) ; Create Object within SubItem 0 of the ListView
$FileName = $FolderRoot+$Object ; Set Variable $FileName
$SIDobj = GetObject("Winmgmts:").ExecQuery("ASSOCIATORS OF {win32_LogicalFileSecuritySetting='$FileName'}WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner") ; Get Owner of $FileName
For Each $SID in $SIDobj
$GetOwnerListBox.Items($x).SubItems(1).Text = $SID.AccountName ; Add SubItem 1 to ListView
Next
Else
;The Foolowing lines are the same as above
$=$GetOwnerListBox.Items.Add($Object,1)
$ObjectSplit = Split($Object,"\")
$FileName = $FolderRoot+$ObjectSplit[0]
$SIDobj = GetObject("Winmgmts:").ExecQuery("ASSOCIATORS OF {win32_LogicalFileSecuritySetting='$FileName'}WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
For Each $SID in $SIDobj
$GetOwnerListBox.Items($x).SubItems(1).Text = $SID.AccountName
Next
EndIf
$x = $x + 1
Next
Enabled(1) ; Call the Enabled Function
EndFunction

;***********************************************************************************************************
;ListView Double Click Function

Function ListView_DoubleClick()

For Each $Item in $GetOwnerListBox.SelectedItems
$ItemName = $Item.Text
If $ItemName = $HomeDrive+"\" ; If Selected Item Contains $HomeDrive + "\"
$FolderRoot = $HomeDrive+"\" ; FolderRoot varable = $HomeDrive + "\"
$GetOwnerListBox.Items.Clear ; Clear the ListView of all Items
ListView() ; Call the ListView Function
Else
If $ItemName = $SharedDrive ; Check if ItemName = SharedDrive
$FolderRoot = $SharedDrive ; FolderRoot = $SharedDrive
$GetOwnerListBox.Items.Clear ; Clear the ListView of all Items
ListView() ; Call the ListView Function
Else
If $ItemName = ".." ; If ItemName = ".."
If Not $FolderRoot = SubStr($FolderRoot,1,2)+'\' ; If $FolderRoot does NOT Contain the 1st 2 charcters of FolderRoot
$FolderRootSplit = Split($FolderRoot,"\") ; Splits the FolderRoot into an Array on "\" charcter
ReDim PRESERVE $FolderRootSplit[Ubound($FolderRootSplit) -2] ; ReDim the FolderRootSplit Array and cut off the last 2 segments of the array but keep the data
$FolderRoot = Join($FolderRootSplit,"\")+'\' ; Re join the array and use "\" as the joining character
$GetOwnerListBox.Items.Clear ; Clear the ListView of all Items
ListView() ; Call the ListView Function
EndIf

Else
If Not InStr($ItemName,"\") = 0 ; If "\" is NOT in Selected ItemName
$FolderRoot = $FolderRoot+"$ItemName" ; Set FolderRoot
$GetOwnerListBox.Items.Clear ; Clear the ListView of all Items
ListView() ; Call the ListView Function
EndIf

EndIf
EndIf
EndIf
Next

EndFunction

;***********************************************************************************************************
;Set the FolderRoot Verable

Function SPSelect_Click()

If $SPSelect.Text = "Click to browse "+$SharedDrive+"\"
$FolderRoot = $SharedDrive+"\"
Else
$FolderRoot = $HomeDrive+"\"
EndIf
$GetOwnerListBox.Items.Clear
ListView()

EndFunction

;***********************************************************************************************************
; Set the Enabled Function

Function Enabled($Option)
$ProgressBar.Value = 0
$SPSelect.Enabled = $Option
$GetOwnerListBox.Enabled = $Option
EndFunction

and here is the UDF FUCCTION DirList#################


Function dirlist($dirname, optional $options)
Dim $filename, $counter, $filepath, $mask
Dim $list, $sublist, $subcounter

$counter=-1

$dirname=Trim($dirname)
If $dirname=''
$dirname=@CURDIR
EndIf
If Right($dirname,1)='\'
$dirname=Left($dirname,Len($dirname)-1)
EndIf
If GetFileAttr($dirname) & 16
$mask='*.*'
Else
$mask=SubStr($dirname,InStrRev($dirname,'\')+1)
$dirname=Left($dirname,Len($dirname)-Len($mask)-1)
EndIf

ReDim $list[10]
$filename=Dir($dirname+'\'+$mask)
While $filename<>'' And @ERROR=0
If $filename<>'.' And $filename<>'..'
Select
Case (GetFileAttr($dirname+'\'+$filename) & 16)
If $options & 1
$counter=$counter+1
If $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'
Else
$list[$counter]=$filename+'\'
EndIf
EndIf
If ($options & 4)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
If Ubound($sublist)+1
ReDim preserve $list[Ubound($list)+Ubound($sublist)+1]
For $subcounter=0 to Ubound($sublist)
$counter=$counter+1
If $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
Else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
EndIf
Next
EndIf
EndIf
Case ($options & 2)
$counter=$counter+1
$list[$counter]=$dirname+'\'+$filename
Case 1
$counter=$counter+1
$list[$counter]=$filename
EndSelect
If $counter mod 10
ReDim preserve $list[$counter+10]
EndIf
EndIf
$filename = Dir('')
Loop

If $counter+1
ReDim preserve $list[$counter]
Else
$list=''
EndIf

If $mask<>'*.*' And ($options & 4)
$filename=Dir($dirname+'\*.*')
While $filename<>'' And @ERROR=0
If $filename<>'.' And $filename<>'..'
If (GetFileAttr($dirname+'\'+$filename) & 16)
$sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
If Ubound($sublist)+1
ReDim preserve $list[Ubound($list)+Ubound($sublist)+1]
For $subcounter=0 to Ubound($sublist)
$counter=$counter+1
If $options & 2
$list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
Else
$list[$counter]=$filename+'\'+$sublist[$subcounter]
EndIf
Next
EndIf
EndIf
EndIf
$filename = Dir('')
Loop
EndIf

If $counter+1
ReDim preserve $list[$counter]
Else
$list=''
EndIf

$dirlist=$list
EndFunction
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group