
kor
Active Members-
Posts
611 -
Joined
-
Last visited
Everything posted by kor
-
Thanks to all for everyones help. Seeing code I better understand how to use the BitAND. It seems I was close, but not close enough. Sorry for my absence I was out of town at a tech conference. (hotels out there still exist that dont have free wifi)
-
this exactly. I know OF the bitand trick, but not much ABOUT the bitand trick. I'll read these posts from you guys carefully tonight and see if I can get it.
-
@SadBunny, thank you for the explanation. I don't understand it right now, but as I experiement more I'll keep coming back to your comment and hopefully it will click eventually. Re: your post about the comments, using the word 'between' was probably not the best. For the first code example I'll explain what I mean. ; write to console = 1, 3, 5, 7 This means that the function should 'write to console' IF the result of the BitAND(or BitOR???) would equal 1, 3, 5, or 7. console = 1 file = 2 eventlog = 4 so (console = 1), (console + file = 3), (console + eventlog = 5), (console + file + eventlog = 7) At least that's how I understand BitAND's to work?
-
I've always thought these are pretty nifty, but have never really understood how they work. I've looked in the help and even tried the BitAnd visualizer that has come up in my searching, but can't quite wrap my head around them. as I test with code I'm just getting more confused. ; Indicates write method options Global Const $L_CONSOLE = 1 Global Const $L_FILE = 2 Global Const $L_EVENT = 4 $iFlag = 4 ; write to console = 1, 3, 5, 7 ; write to file = 2, 3, 6, 7 ; write to evenlog = 4, 5, 6, 7 If BitOR($iFlag, 3) Then ConsoleWrite("yes" & @CR) ConsoleWrite(BitAND($iFlag, 1) & @CR) ConsoleWrite(BitAND($iFlag, 2) & @CR) ConsoleWrite(BitAND($iFlag, 3) & @CR) ConsoleWrite(BitAND($iFlag, 4) & @CR) ConsoleWrite(BitAND($iFlag, 8) & @CR) Basically what I'm trying to figure out is how to get BitAnd, and BitOR's to return true if the numbers are between the numbers in the code comments. The returns never seem to be true or false either, they are numbers. Which I don't quite get yet either.
-
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
Please stop accusing me of trying to get code for free. I'm trying to learn. If that is too much for you to handle then I'm not sure what to say. I already have my own code which I've posted. So I certainly don't need free code. Your code doesn't even work anyway. You have an error at line 16. It also continues to use file names rather than file handles which was the whole point of my thread. I've got code that works, it not as efficient but it seems all you're interested in is being negative so I'll be on my way.. -
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
Right, when using filenames instead of handles. I'm trying to accomplish the same thing but using file handles instead. -
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
sort of. I'm passing a 'prefix' to a put at the beginning of a log file IF and only if there are going to be multiple log files being spit out of the script. If there is only 1 log file then there is no need to add the prefix. So the log function doesn't know the exact name of the file until it creates it (with or without the prefix) EDIT: try this #include <File.au3> _Log("testing1", "HR") _Log("testing2", "HR") _Log("testing3", "Payroll") _Log("testing4", "Payroll") _Log("testing5") Func _Log($sText, $sPrefix = "") Local $sColor, $sLogPath = @ScriptDir & "\logs\", $sLogName = @MON & "-" & @MDAY & "-" & @YEAR & "--" & @HOUR & "-" & @MIN & ".log" If $sPrefix <> "" Then $sLogName = $sPrefix & "-" & $sLogName ; prefix log name with string if attempting to work with multiple log files If Not FileExists($sLogPath & $sLogName) Then ; if log file doesnt exist If Not _FileCreate($sLogPath & $sLogName) Then ; attempt to create it ConsoleWrite("! [ERROR] - Unable to create log file" & @CR) Exit(1) ; exit if unable to create log file EndIf EndIf Switch $sText ; test if text string contains keywords Case StringInStr($sText, "ERROR") > 0 $sColor = "!" ; red Case StringInStr($sText, "WARN") > 0 $sColor = "-" ; orange Case StringInStr($sText, "ACTION") > 0 $sColor = "+" ; green Case Else $sColor = ">" ; blue EndSwitch If Not _FileWriteLog($sLogPath & $sLogName, $sText) Then ; attempt to write to log file ConsoleWrite("! [ERROR] - Unable to write to log file" & @CR) Exit(1) ; exit if unable to write to log file EndIf ConsoleWrite($sColor & " " & $sText & @CRLF) ; log to console and command window (if compiled) EndFunc ;==>_Log -
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
If I wanted you to write all my code for me I wouldn't have posted my own code in the first place. (twice actually) You've also seem to take a bit personally the fact I didn't want to go with your suggestion, even when you misinterpreted what I was asking. No, I'm not trying to 'keep track of them', im trying to create them and handle them within the log function on the fly. Your series of steps makes no sense. The entire point of what I'm trying to do is deal with a situation where I don't know the file names, I don't know how many log files you might be using in a given script, and I don't know what log level you want to log for any given log file. I can't have 'static' arrays. Everything needs to be dynamic, able to handle you only ever calling 1 log file, or 10. My biggest issue is I don't know how to create a variable based on a string. If I could somehow dynamically make variables for however many different log files you might reference in the script I could assign a variable(handle) to each different log file that is referenced and I'd be fine. Problem is I have no idea how to dynamically make variables, or if that's even the best way to go about it. -
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
fair point. which is why I've posted code and asked for help. I didn't 'dismiss' anything, simply said I don't want to. -
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
@SadBunny, it is all self contained. By that I mean I don't want to have to add lines of code outside of the _Log function that make _Log() work or not. IE, variables, or fileopen's, filecloses, etc. I want every command that makes _Log work to be contained within the function. however I like your suggestions but unsure how best to implement. What do you purpose for the log level? A BitAND / BitOR ? I would like to avoid having to search the string as well, but open to better ways to handle it. @guinness, I'm not adamantly opposed to storing the handles in arrays, I just don't understand how I would pass the handle through to the function. -
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
I actually AM writing to a log file a lot and although using file names instead of handles is more resource intensive I don't see a better way to do it. I don't want to store things in an array, and I don't want to have to declare things or do other actions outside the function. I want it all self contained within the _Log function. -
best way to open multiple file handles?
kor replied to kor's topic in AutoIt General Help and Support
I switched to using file names directly rather than handles. #include <File.au3> _Log("testing", "HR") Func _Log($sText, $sPrefix = "") Local $sColor, $sLogPath = @ScriptDir & "\logs\", $sLogName = @MON & "-" & @MDAY & "-" & @YEAR & "--" & @HOUR & "-" & @MIN & ".log" If $sPrefix <> "" Then $sLogName = $sPrefix & "-" & $sLogName ; prefix log name with string if attempting to work with multiple log files If Not FileExists($sLogPath & $sLogName) Then ; if log file doesnt exist If Not _FileCreate($sLogPath & $sLogName) Then ; attempt to create it ConsoleWrite("! [ERROR] - Unable to create log file" & @CR) Exit(1) ; exit if unable to create log file EndIf EndIf Switch $sText ; test if text string contains keywords Case StringInStr($sText, "ERROR") > 0 $sColor = "!" ; red Case StringInStr($sText, "WARN") > 0 $sColor = "-" ; orange Case StringInStr($sText, "ACTION") > 0 $sColor = "+" ; green Case Else $sColor = ">" ; blue EndSwitch If Not _FileWriteLog($sLogPath & $sLogName, $sText) Then ; attempt to write to log file ConsoleWrite("! [ERROR] - Unable to write to log file" & @CR) Exit(1) ; exit if unable to write to log file EndIf ConsoleWrite($sColor & " " & $sText & @CRLF) ; log to console and command window (if compiled) EndFunc ;==>_Log -
#include <File.au3> #include <FileConstants.au3> Global $hLog _Log("testing1", "HR") ; file 1 _Log("testing2", "HR") ; file 1 _Log("testing3", "Payroll") ; file 2 _Log("testing4") ; no prefix file 3 Func _Log($sText, $sAppend = "") ; Writes script output to console, file, and command window if compiled Local $sPrefix, $sLogName = @MON & "-" & @MDAY & "-" & @YEAR & "--" & @HOUR & "-" & @MIN If $sAppend <> "" Then $sLogName = $sAppend & "-" & $sLogName ; prefix log ID when writing to multiple log files in a single script If Not $hLog Then $hLog = FileOpen(@ScriptDir & "\logs\" & $sLogName & ".log", $FO_CREATEPATH + $FO_OVERWRITE) ; open log file If $hLog = -1 Then ; confirm RW access for log file ConsoleWrite("! [ERROR] - Can't create log file" & @CR) Exit(1) EndIf EndIf Switch $sText Case StringInStr($sText, "ERROR") > 0 $sPrefix = "!" ; red Case StringInStr($sText, "WARN") > 0 $sPrefix = "-" ; orange Case StringInStr($sText, "ACTION") > 0 $sPrefix = "+" ; green Case Else $sPrefix = ">" ; blue EndSwitch ConsoleWrite($sPrefix & " " & $sText & @CRLF) ; write to console and commmand window (if compiled) _FileWriteLog($hLog, $sText) ; write to log file EndFunc ;==>_Log what would you suggest to be able to open multiple file handles within a single script based on the $sAppend value?
-
I don't believe that will work. The file path that I need to monitor is on an IBM iSeries AS400 and isn't a windows file system.
-
Maybe something like this? #include <Array.au3> #include <File.au3> #include <FileConstants.au3> While 1 Sleep(2000) ; slow things down so you can see it $aFiles = _FileListToArrayRec("C:\temp", "*", $FLTA_FILES, $FLTAR_RECUR, 0, $FLTAR_FULLPATH) If @error Then ContinueLoop If $aFiles[0] > 0 Then For $i = 1 To UBound($aFiles) - 1 FileMove($aFiles[$i], "C:\temp1", $FC_OVERWRITE) Next EndIf WEnd
-
#include <Array.au3> #include <File.au3> #include <FileConstants.au3> ;$aFiles = _FileListToArrayRec("\\express.mpsaz.org\purchasing", "*", $FLTA_FILES, $FLTAR_RECUR) ;_ArrayDisplay($aFiles) ;1246 Do $aFiles = _FileListToArrayRec("C:\temp", "*", $FLTA_FILES, $FLTAR_RECUR) Sleep(500) $iOldFiles = $aFiles[0] ConsoleWrite("old files = " & $iOldFiles & " new files = " & $aFiles[0] & @CR) Until $iOldFiles < $aFiles[0] ConsoleWrite("out of the loop" & @CR) The goal is to monitor a directory and wait. as soon as a new file appears exit the loop (need help here) then copy the file to a new directory (haven't got there yet) then continue back into the loop and keep monitoring I'm stuck on how to approach this. I'm not good with Do until loops. What I'm attempting to do in the code is list all files in a directory, count the number of files.. and if the number of files increases (by any number) then do an action... once the action is done.. continue back into the loop. get number of files in a directory if # of files in directory increases from the last time you got the # of files then copy the file to XYZ then go back to the beginning and keep getting the number of files in a directory. EDIT: I'm not even sure a Do Until loop is right for me. My biggest issue is I don't know how to compare the number of files that is in the CURRENT loop to the number of files that was in the LAST loop that just completed. So if the last time the loop finished the number of files was 105, and now in the current loop the number of files is 106, how do I have the number of files from the last loop survive the loop into the next one?
-
Active Directory UDF - Help & Support (III)
kor replied to water's topic in AutoIt General Help and Support
I calculated wrong. It's not actually doing 4.8 million checks, its still only doing 32,000 checks...BUT it has to loop through the array that matches the 2nd octet to the correct OU for each of the 32,000 checks. Much less resource intensive, but an array loop of 150 for each of the 32,000 checks none the less.- 883 replies
-
- active directory
- ad
-
(and 2 more)
Tagged with:
-
Active Directory UDF - Help & Support (III)
kor replied to water's topic in AutoIt General Help and Support
I don't know if the computer is in the wrong OU until I do an nslookup on the computer and get it's IP address. Then based on the 2nd octet of the IP I know which OU it's *supposed* to be in, then I move it. so my script does all that, but it has to check each computer to make sure its in the right OU, and if not.. move it. If it is in the right OU skip it and move on.- 883 replies
-
- active directory
- ad
-
(and 2 more)
Tagged with:
-
Active Directory UDF - Help & Support (III)
kor replied to water's topic in AutoIt General Help and Support
Question on script efficiency. If I call _AD_MoveObject what is more efficient? 1) running a check first to see where the object is, and if its already in the place I want to move it to then skip AD_MoveObject 2) dont run a check, run AD_MoveObject regardless and let it fail and move on to the next object in the loop I have a script that moves computers around to the right OU's based on certain criteria. My environment is roughly 32,000 computer objects with about 150 OU's. So basically that is 32,000*150 checks = 4.8 million checks each time the script runs.- 883 replies
-
- active directory
- ad
-
(and 2 more)
Tagged with:
-
Active Directory UDF - Help & Support (III)
kor replied to water's topic in AutoIt General Help and Support
Currently the OU that needs to be excluded contains about ~3,000 users. However it grows by about 800-1000 users every 6 month rotation.- 883 replies
-
- active directory
- ad
-
(and 2 more)
Tagged with:
-
Active Directory UDF - Help & Support (III)
kor replied to water's topic in AutoIt General Help and Support
I'm not sure that is possible. http://www.winvistatips.com/threads/ldap-filter-on-distinguishedname-wildcards-dont-work.758937/ http://stackoverflow.com/questions/2295092/ldap-using-a-filter-to-avoid-a-sub-cn-in-active-directory http://www.developerscrappad.com/1052/windows/active-directory/quick-note-unable-to-perform-ldap-wildcard-search-on-windows-active-directory/ At least using a wildcard. Were you suggesting something else?- 883 replies
-
- active directory
- ad
-
(and 2 more)
Tagged with:
-
Active Directory UDF - Help & Support (III)
kor replied to water's topic in AutoIt General Help and Support
@Water, is there a way to filter both users AND ou's in the filter for _GetObjectsInOU ?? I need to query all users in AD and exclude users that have certain attributes, but I also need to exclude outright all users in 1 particular OU. Is this possible? Here is my code but it's not working. I've been reading online and one person had some luck doing something similar with a different coding language where they did 2 separate queries, the first getting all the users, then filtering them based on the OU they are in. My particular problem is our environment is so huge either method isn't particularly practical. The original user query returns ~69,000 users (after the filter) and if I wanted to query just by OU's we have over 300 OU's to loop through and query users for. #include <AD.au3> #include <Array.au3> _AD_Open() $q1 = "" ;$q1 = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(company=stu)(!(!company=*)))" $q2 = "" $q2 = "(&(objectCategory=organizationlUnit)(!(ou=dn:=OU=Alumni,OU=Users,OU=Building1,DC=test,DC=domain,DC=ORG)))" $sStudentQuery = "(&" & $q1 & $q2 & ")" ConsoleWrite($sStudentQuery & @CR) $aUsers = _AD_GetObjectsInOU("", $sStudentQuery, 2, "sAMAccountName,physicalDeliveryOfficeName,title", "") ; query AD ; $aUsers[$i][0] = sAMAccountName (username) ; $aUsers[$i][1] = physicalDeliveryOfficeName (site) ; $aUsers[$i][2] = title (grade) _ArrayDisplay($aUsers) ;OU=Alumni,OU=Users,OU=Building1,DC=test,DC=domain,DC=ORG ;(!(ou:dn:=Alumni)) ;(!(ou=dn:=dn:=OU=Alumni,OU=Users,OU=Building1,DC=test,DC=domain,DC=ORG)) ;(!(ou:dn:OU=Alumni,OU=Users,OU=Building1,DC=test,DC=domain,DC=ORG)) _AD_Close()- 883 replies
-
- active directory
- ad
-
(and 2 more)
Tagged with:
-
Thank you so much.
-
I have a piece of data CN=308-142413,OU=Workstations,OU=Administrative,OU=Admin-Sites,DC=TEST,DC=COMPANY,DC=ORG I would like to delete everything before the first OU statement (ou=workstations) effectively getting rid of CN=308-142413, (including that pesky comma) But I'm not sure how to accomplish this deletion without accidentally deleting the rest of the string (if I based things on commas, or OU)
-
Active Directory UDF - Help & Support (III)
kor replied to water's topic in AutoIt General Help and Support
Issue with trying to query the 'lastlogon' attribute for computer objects. #include <AD.au3> #include <Array.au3> _AD_Open() Local $aResult = _AD_GetObjectsInOU("*", "(objectCategory=computer)", 2, "sAMAccountName, lastLogon") _ArrayDisplay($aResult) samaccountname populates correctly, but my second column is blank. The value is there as I can see it when I click on the attribute editor for a computer object in ADUC.- 883 replies
-
- active directory
- ad
-
(and 2 more)
Tagged with: