ioliver Posted February 22, 2005 Posted February 22, 2005 Here's my code... It's well documented, maybe to well documented, but that was for my benefit, so that I could follow it. CODE; Conventions: ; -> = The comment explains the code below it ; Variables: ; $folder = Folder or File Name | $intfolder = Number of Characters for the Folder or File Name ; $intfolder1 = Value of $intfolder + 1 | $caclsresult = The message to be displayed in the text box ; $caclstxt = The output from the CACLS command ; $line = Each line in the $caclstext variable ; $line2notexist = Set to True if the vairable $line cannot be split by a ':' ; $line[1] & $line [2] = The first and second part of $line split by a ':' $folder = "C:\Program Files" $intfolder = StringLen($folder) $intfolder1 = $intfolder + 1 ; $caclsresult = "Key:" & @CR & "(CI) - Container Inherit" & @CR & "(OI) - Object Inherit" &_ ; @CR & "(IO) - Inherit Only" & @CR & "----------" & @CR & "" Dim $caclsresult ; -> Executes the CACLS command on the selected folder or file and writes the results to c:\cacls.txt RunWait(@comspec & ' /c ' & 'cacls ' & '"' & $folder & '"' & ' > c:\cacls.txt', '', @SW_HIDE) ; -> Opens c:\cacls.txt $caclstxt = FileOpen("c:\cacls.txt", 0) While 1 $line2notexist = "False" ; -> Reads a line from c:\cacls.txt $line = FileReadLine($caclstxt) If @error = -1 Then ExitLoop ; -> Removes the folder are file name from the line $line = StringTrimLeft($line, $intfolder1) ; -> Removes any additional Whitespace from the line $line = StringStripWS($line, 1) ; 1 = Strip Leading Whitespace ; -> Splits the line using ':' $line = StringSplit($line, ":") ; -> Checks to make sure ':' exists in the line ; -> if ':' does not exist sets the variable $line2notexist ; -> to True If @error = 1 Then $line2notexist = "True" ;MsgBox(0, "Line[1] read:", $line[1]) If StringInStr($line[1], "GENERIC") Then $line[2] = $line[1] $line[1] = "" EndIf If $line2notexist = "False" Then ;MsgBox(0, "Line[2] read:", $line[2]) ; -> Checks to see if $line[2] = 'special access' If StringInStr($line[2], "special access") Then ; -> If $line[2] contains 'special access', ; -> addes '' to correctly format it $line[2] = $line[2] & "" EndIf ;MsgBox(0, "Line[2] read:", $line[2]) EndIf If $line2notexist = "False" Then If StringLen($line[1]) < 15 Then $caclsresult = $caclsresult & $line[1] & @TAB & @TAB & $line[2] & @CR Else $caclsresult = $caclsresult & $line[1] & @TAB & $line[2] & @CR EndIf Else $caclsresult = $caclsresult & $line[1] & @CR EndIf Wend FileClose($caclstxt) MsgBox(0, "CACLS Results for " & $folder, $caclsresult) Here is the part I'm having trouble with: If StringInStr($line[1], "GENERIC") Then $line[2] = $line[1] $line[1] = "" EndIf When running CACLS, it sometimes comes up with Special Permissions, ie. GENERIC_READ, GENERIC_EXECUTE. When I do my StringSplit these Special Permissions end up in the first column, $line[1], but I need them to be in the 2nd column, $line[2]. That's what the above code is supposed to do, but there's a problem. All suggestions are welcome. Thanks in advance, Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
Developers Jos Posted February 22, 2005 Developers Posted February 22, 2005 When running CACLS, it sometimes comes up with Special Permissions, ie. GENERIC_READ, GENERIC_EXECUTE. When I do my StringSplit these Special Permissions end up in the first column, $line[1], but I need them to be in the 2nd column, $line[2]. That's what the above code is supposed to do, but there's a problem.All suggestions are welcome.Thanks in advance,Ian<{POST_SNAPBACK}>Could you explain whats not working ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioliver Posted February 22, 2005 Author Posted February 22, 2005 Sorry. Here is the error message from Scite:C:\Scripts...\_displaycacls.au3 (49) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $line[2]= $line[1] ^ ERROR>Exit code: 0 Time: 0.319The part of the code that I'm having trouble with:If StringInStr($line[1], "GENERIC") Then $line[2] = $line[1] $line[1] = "" EndIfIt will not set $line[2] to $line[1]I'm trying here, but I'm having trouble describing the problem. Please let me know if you need more information.Thanks,Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
Developers Jos Posted February 22, 2005 Developers Posted February 22, 2005 Sorry. Here is the error message from Scite:The part of the code that I'm having trouble with:If StringInStr($line[1], "GENERIC") Then $line[2] = $line[1] $line[1] = "" EndIfIt will not set $line[2] to $line[1]I'm trying here, but I'm having trouble describing the problem. Please let me know if you need more information.Thanks,Ian<{POST_SNAPBACK}>What about doing a redim $line[3] when ubound($line) < 3 before this line: $line[2] = $line[1]? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioliver Posted February 22, 2005 Author Posted February 22, 2005 Thanks JdeB, but I'm not following what you are saying? There is no $line[3], and if I create one, it will effect the results of the script later on. Thanks, Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
Blue_Drache Posted February 22, 2005 Posted February 22, 2005 (edited) Thanks JdeB, but I'm not following what you are saying? There is no $line[3], and if I create one, it will effect the results of the script later on.Thanks,Ian<{POST_SNAPBACK}>Then you could always redim it back down to [2] if necessary, or set [3] to a null.Remember, when you Dim $variable[n], your actual containers are n-1 as they are numbered from zero first. Dim $variable[3] $variable[0] $variable[1] $variable[2]that's why I always Dim $vairable[n+1] and leave $variable[0] empty. Edited February 22, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
Developers Jos Posted February 22, 2005 Developers Posted February 22, 2005 Thanks JdeB, but I'm not following what you are saying? There is no $line[3], and if I create one, it will effect the results of the script later on.Thanks,Ian<{POST_SNAPBACK}>Well, redim $line[3] means:1. $line[0]2. $line[1]3. $line[2]agree ?? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioliver Posted February 22, 2005 Author Posted February 22, 2005 Then you could always redim it back down to [2] if necessary, or set [3] to a null.Remember, when you Dim $variable[n], your actual containers are n-1 as they are numbered from zero first. that's why I always Dim $vairable[n+1] and leave $variable[0] empty.<{POST_SNAPBACK}>Thanks Blue. But I thought, that when you did a StringSplit(), that $variable[0] contained the number of elements in the array?Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
Developers Jos Posted February 22, 2005 Developers Posted February 22, 2005 this is what should work (i think..) If @error = 1 Then $line2notexist = "True" ;MsgBox(0, "Line[1] read:", $line[1]) If UBound($line) < 3 then ReDim $line[3] If StringInStr($line[1], "GENERIC") Then $line[2] = $line[1] $line[1] = "" EndIf SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Blue_Drache Posted February 22, 2005 Posted February 22, 2005 this is what should work (i think..)If @error = 1 Then $line2notexist = "True" ;MsgBox(0, "Line[1] read:", $line[1]) If UBound($line) < 3 then ReDim $line[3] If StringInStr($line[1], "GENERIC") Then $line[2] = $line[1] $line[1] = "" EndIf<{POST_SNAPBACK}>You'll probably need to set the [0] array counter to "2" since he's using StringSplit to get the initial values. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
Developers Jos Posted February 22, 2005 Developers Posted February 22, 2005 You'll probably need to set the [0] array counter to "2" since he's using StringSplit to get the initial values.<{POST_SNAPBACK}>Nah... not needed because its not used in the script .... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioliver Posted February 22, 2005 Author Posted February 22, 2005 @JdeB, Thanks. It works. But I don't understand why. When you have time, can you explain it to me? Thanks, Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
Developers Jos Posted February 22, 2005 Developers Posted February 22, 2005 @JdeB, Thanks. It works. But I don't understand why. When you have time, can you explain it to me?Thanks,Ian<{POST_SNAPBACK}>I guess you missed this post ??? Well, redim $line[3] means:1. $line[0]2. $line[1]3. $line[2]agree ??<{POST_SNAPBACK}> SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioliver Posted February 22, 2005 Author Posted February 22, 2005 (edited) Thanks JdeB. I did miss that. So, redim(), resizes the array, but keeps the values intact. But why does it need to be redim()ed, didn't the StringSplit() already create the $line[2]. ... Ok, I get it. $line(2) was not created b/c there was no ':' char. So the StringSplit() didn't work. Am I on the right track? Ian Edited February 22, 2005 by ioliver "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
Developers Jos Posted February 22, 2005 Developers Posted February 22, 2005 Thanks JdeB. I did miss that.So, redim(), resizes the array, but keeps the values intact. But why does it need to be redim()ed, didn't the StringSplit() already create the $line[2].... Ok, I get it. $line(2) was not created b/c there was no ':' char. So the StringSplit() didn't work.Am I on the right track?Ian<{POST_SNAPBACK}>correct... stringsplit recreates the array with the number of splitted partitions + 1 (0=number of occurences 1=first part.....etc)The If UBound($line) < 3 then ReDim $line[3] statement just ensures that $line[2] exists and can be used even when the stringsplit didn't create it...Isn't scripting fun SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ioliver Posted February 22, 2005 Author Posted February 22, 2005 Isn't scripting funSure is, thanks.Ian "Blessed be the name of the Lord" - Job 1:21Check out Search IMF
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