aguynamedray Posted November 5, 2012 Share Posted November 5, 2012 Hello Gurus, Just one question. How do i pull or output the current domain username in the GUI? I have a file monitoring script and I want to add the username who deleted/modified/moved the file/folder in a specific monitored drive. Thanks in advance. Any help is much appreciated. Regards, Ray Link to comment Share on other sites More sharing options...
careca Posted November 5, 2012 Share Posted November 5, 2012 (edited) Hi, you can use the macro @UserName to get the current username. Do you have any code to work with? Would be easier to look at the code and understand where/when/how you want to output. MsgBox(0, '', @UserName) MsgBox(0, '', @LogonDomain) Edited November 5, 2012 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
water Posted November 5, 2012 Share Posted November 5, 2012 If you want the Firstname, Lastname etc. from the Active Directory then you could use my AD UDF. Function _AD_GetObjectAttribute is what you need. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 5, 2012 Author Share Posted November 5, 2012 (edited) Hi, you can use the macro @UserName to get the current username. Do you have any code to work with? Would be easier to look at the code and understand where/when/how you want to output. MsgBox(0, '', @UserName) MsgBox(0, '', @LogonDomain) Here's the code from zorphnog (M. Mims): expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.10.0 Author: zorphnog (M. Mims) Script Function: Monitors the user defined directories for file activity. #ce ---------------------------------------------------------------------------- #include #include #include #include #include #include Global Const _ $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000, _ $FILE_FLAG_OVERLAPPED = 0x40000000 Global Const _ $FILE_NOTIFY_CHANGE_ALL = 0x17F, _ $FILE_NOTIFY_CHANGE_FILE_NAME = 0x001, _ $FILE_NOTIFY_CHANGE_DIR_NAME = 0x002, _ $FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x004, _ $FILE_NOTIFY_CHANGE_SIZE = 0x008, _ $FILE_NOTIFY_CHANGE_LAST_WRITE = 0x010, _ $FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x020, _ $FILE_NOTIFY_CHANGE_CREATION = 0x040, _ $FILE_NOTIFY_CHANGE_SECURITY = 0x100 Global Const _ $FILE_ACTION_ADDED = 0x1, _ $FILE_ACTION_REMOVED = 0x2, _ $FILE_ACTION_MODIFIED = 0x3, _ $FILE_ACTION_RENAMED_OLD_NAME = 0x4, _ $FILE_ACTION_RENAMED_NEW_NAME = 0x5 Global Const _ $MWMO_ALERTABLE = 0x0002, _ $MWMO_INPUTAVAILABLE = 0x0004, _ $MWMO_WAITALL = 0x0001 Global Const $FILE_LIST_DIRECTORY = 0x0001 Global Const $QS_ALLINPUT = 0x04FF Global Const $INFINITE = 0xFFFF Global Const $tagFNIIncomplete = "dword NextEntryOffset;dword Action;dword FileNameLength" Global $bMonitorDone, $bSelected, $bMonitor AutoItSetOption("GUIOnEventMode", 1) $gFileMon = GUICreate("BMC Server Monitoring", 731, 385, 194, 126) GUISetOnEvent($GUI_EVENT_CLOSE, "_OnEvent_Close") GUICtrlCreateGroup("Monitored Directories", 8, 0, 713, 105) $btAdd = GUICtrlCreateButton("Add", 16, 24, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Add") $btRemove = GUICtrlCreateButton("Remove", 16, 56, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Remove") GUICtrlSetState(-1, $GUI_DISABLE) $lbDirectories = GUICtrlCreateList("", 104, 16, 506, 71) $btMonitor = GUICtrlCreateButton("Start Monitor", 632, 24, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Monitor") GUICtrlSetState(-1, $GUI_DISABLE) $btClear = GUICtrlCreateButton("Clear", 632, 56, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Clear") GUICtrlCreateGroup("", -99, -99, 1, 1) $lvNotifications = GUICtrlCreateListView("Action|Time|File|User", 8, 112, 718, 260) GUICtrlSendMsg(-1, 0x101E, 0, Int(.1*710)) GUICtrlSendMsg(-1, 0x101E, 1, Int(.2*710)) GUICtrlSendMsg(-1, 0x101E, 2, Int(.5*710)-20) GUICtrlSendMsg(-1, 0x101E, 2, Int(.50*780)-50) GUISetState(@SW_SHOW) _Main() Func _DisplayFileMessages($hBuffer, $sDir) Local $hFileNameInfo, $pBuffer, $hTime Local $nFileNameInfoOffset = 12, $nOffset = 0, $nNext = 1 Global $sT3_UserName $pBuffer = DllStructGetPtr($hBuffer) $sT3_UserName = GUICtrlRead(@UserName) While $nNext <> 0 $hFileNameInfo = DllStructCreate($tagFNIIncomplete, $pBuffer + $nOffset) $hFileName = DllStructCreate("wchar FileName[" & DllStructGetData($hFileNameInfo, "FileNameLength")/2 & "]", $pBuffer + $nOffset + $nFileNameInfoOffset) $hTime = _Date_Time_GetSystemTime() Switch DllStructGetData($hFileNameInfo, "Action") Case $FILE_ACTION_ADDED _GUICtrlListView_InsertItem($lvNotifications, "Created", 0) Case $FILE_ACTION_REMOVED _GUICtrlListView_InsertItem($lvNotifications, "Deleted", 0) Case $FILE_ACTION_MODIFIED _GUICtrlListView_InsertItem($lvNotifications, "Modified", 0) Case $FILE_ACTION_RENAMED_OLD_NAME _GUICtrlListView_InsertItem($lvNotifications, "Rename-", 0) Case $FILE_ACTION_RENAMED_NEW_NAME _GUICtrlListView_InsertItem($lvNotifications, "Rename+", 0) Case Else _GUICtrlListView_InsertItem($lvNotifications, "Unknown", 0) EndSwitch _GUICtrlListView_AddSubItem($lvNotifications, 0, _Date_Time_SystemTimeToDateTimeStr($hTime), 1) _GUICtrlListView_AddSubItem($lvNotifications, 0, $sDir & DllStructGetData($hFileName, "FileName"), 2) _GUICtrlListView_AddSubItem($lvNotifications, 0, ($sT3_UserName), 3) $nNext = DllStructGetData($hFileNameInfo, "NextEntryOffset") $nOffset += $nNext WEnd EndFunc Func _GetBufferHandle () Return DllStructCreate("ubyte[2048]") EndFunc Func _GetDirectoryChanges($aDirHandles, $hBuffer, $aOverlapped, $hEvents, $aDirs, $bAsync = Default, $nTimeout = Default) Local $aMsg, $i, $nBytes = 0 If $nTimeout = -1 Or IsKeyword($nTimeout) Then $nTimeout = 250 If Not $bAsync Then $nTimeout = $INFINITE $aMsg = DllCall("User32.dll", "dword", "MsgWaitForMultipleObjectsEx", _ "dword", UBound($aOverlapped), _ "ptr", DllStructGetPtr($hEvents), _ "dword", $nTimeout, _ "dword", 0, _ "dword", 0x6) $i = $aMsg[0] Switch $i Case 0 To UBound($aDirHandles)-1 If Not _WinAPI_GetOverlappedResult($aDirHandles[$i], DllStructGetPtr($aOverlapped[$i]), $nBytes, True) Then ConsoleWrite("!> GetOverlappedResult Error(" & @error & "): " & _WinAPI_GetLastErrorMessage() & @LF) Return 0 EndIf DllCall("Kernel32.dll", "Uint", "ResetEvent", "uint", DllStructGetData($aOverlapped[$i], "hEvent")) _DisplayFileMessages($hBuffer, $aDirs[$i]) _SetReadDirectory($aDirHandles[$i], $hBuffer, $aOverlapped[$i],False,True) Return $nBytes EndSwitch Return 0 EndFunc Func _GetDirHandle($sDir) Local $aResult $aResult = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sDir, _ "int", $FILE_LIST_DIRECTORY, _ "int", BitOR($FILE_SHARE_DELETE,$FILE_SHARE_READ,$FILE_SHARE_WRITE), _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", BitOR($FILE_FLAG_BACKUP_SEMANTICS,$FILE_FLAG_OVERLAPPED), _ "int", 0) If $aResult[0] = 0 Then ConsoleWrite("!> CreateFile Error (" & @error & "): " & _WinAPI_GetLastErrorMessage() & @LF) Exit EndIf Return $aResult[0] EndFunc Func _GetEventHandles ($aOverlapped) Local $i, $hEvents $hEvents = DllStructCreate("hwnd hEvent[" & UBound($aOverlapped) & "]") For $i=1 To UBound($aOverlapped) DllStructSetData($hEvents, "hEvent", DllStructGetData($aOverlapped[$i-1], "hEvent"), $i) Next Return $hEvents EndFunc Func _GetOverlappedHandle () Local $hOverlapped = DllStructCreate($tagOVERLAPPED) For $i=1 To 5 DllStructSetData($hOverlapped, $i, 0) Next Return $hOverlapped EndFunc Func _Main () $bSelected = False $bMonitorDone = True $bMonitor = False While 1 If Not $bMonitorDone Then _MonitorDirs() If $bMonitor And _GUICtrlListBox_GetCount($lbDirectories) = 0 Then $bMonitor = Not $bMonitor GUICtrlSetState($btMonitor, $GUI_DISABLE) ElseIf Not $bMonitor And _GUICtrlListBox_GetCount($lbDirectories) > 0 Then $bMonitor = Not $bMonitor GUICtrlSetState($btMonitor, $GUI_ENABLE) EndIf If $bSelected And _GUICtrlListBox_GetCurSel($lbDirectories) = -1 Then $bSelected = Not $bSelected GUICtrlSetState($btRemove, $GUI_DISABLE) ElseIf Not $bSelected And _GUICtrlListBox_GetCurSel($lbDirectories) <> -1 Then $bSelected = Not $bSelected GUICtrlSetState($btRemove, $GUI_ENABLE) EndIf WEnd EndFunc Func _MonitorDirs () Local $i, $nMax, $hBuffer, $hEvents $nMax = _GUICtrlListBox_GetCount($lbDirectories) Local $aDirHandles[$nMax], $aOverlapped[$nMax], $aDirs[$nMax] $hBuffer = _GetBufferHandle() For $i = 0 To $nMax-1 $aDirs[$i] = _GUICtrlListBox_GetText($lbDirectories, $i) $aDirHandles[$i] = _GetDirHandle($aDirs[$i]) $aOverlapped[$i] = _GetOverlappedHandle() _SetReadDirectory($aDirHandles[$i], $hBuffer, $aOverlapped[$i], True, True) Next $hEvents = _GetEventHandles($aOverlapped) While Not $bMonitorDone _GetDirectoryChanges($aDirHandles, $hBuffer, $aOverlapped, $hEvents, $aDirs) WEnd EndFunc Func _OnEvent_Add () Local $sDir, $nMax, $i $sDir = FileSelectFolder("Select directory to monitor", "") If $sDir <> "" Then If StringRight($sDir, 1) <> "" Then $sDir &= "" $nMax = _GUICtrlListBox_GetCount($lbDirectories)-1 For $i = 0 To $nMax If _GUICtrlListBox_GetText($lbDirectories, $i) = $sDir Then Return Next _GUICtrlListBox_AddString($lbDirectories, $sDir) EndIf EndFunc Func _OnEvent_Clear () _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lvNotifications)) EndFunc Func _OnEvent_Close () Exit EndFunc Func _OnEvent_Monitor () If $bMonitorDone Then $bMonitorDone = False GUICtrlSetData($btMonitor, "Stop Monitor") GUICtrlSetState($btAdd, $GUI_DISABLE) GUICtrlSetState($btRemove, $GUI_DISABLE) GUICtrlSetState($lbDirectories, $GUI_DISABLE) $bSelected = False Else $bMonitorDone = True GUICtrlSetState($lbDirectories, $GUI_ENABLE) GUICtrlSetState($btAdd, $GUI_ENABLE) GUICtrlSetData($btMonitor, "Start Monitor") EndIf EndFunc Func _OnEvent_Remove () _GUICtrlListBox_DeleteString($lbDirectories, _GUICtrlListBox_GetCurSel($lbDirectories)) EndFunc Func _SetReadDirectory($hDir, $hBuffer, $hOverlapped, $bInitial = False, $bSubtree = False) Local $hEvent, $pBuffer, $nBufferLength, $pOverlapped $pBuffer = DllStructGetPtr($hBuffer) $nBufferLength = DllStructGetSize($hBuffer) $pOverlapped = DllStructGetPtr($hOverlapped) If $bInitial Then $hEvent = DllCall("Kernel32.dll", "hwnd", "CreateEvent", _ "uint", 0, _ "int", True, _ "int", False, _ "uint", 0) If $hEvent[0] = 0 Then ConsoleWrite("!> CreateEvent Failed (" & _WinAPI_GetLastError() & "): " & _WinAPI_GetLastErrorMessage() & @LF) Exit EndIf DllStructSetData($hOverlapped, "hEvent", $hEvent[0]) EndIf $aResult = DllCall("Kernel32.dll", "int", "ReadDirectoryChangesW", _ "hwnd", $hDir, _ "ptr", $pBuffer, _ "dword", $nBufferLength, _ "int", $bSubtree, _ "dword", BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, _ $FILE_NOTIFY_CHANGE_SIZE,$FILE_NOTIFY_CHANGE_DIR_NAME), _ "uint", 0, _ "uint", $pOverlapped, _ "uint", 0) If $aResult[0] = 0 Then ConsoleWrite("!> ReadDirectoryChangesW Error(" & @error & "): " & _WinAPI_GetLastErrorMessage() & @LF) Exit EndIf Return $aResult[0] EndFunc I need to output the domain username whom modified the file/directory. Edited November 5, 2012 by aguynamedray Link to comment Share on other sites More sharing options...
water Posted November 5, 2012 Share Posted November 5, 2012 I'm not going to analyze the code to understand your problem. What do you have so far (accountname ...) and what do you want to get (Full username or domain account name ...). My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 5, 2012 Author Share Posted November 5, 2012 Thanks for the quick reply water. Yes, much better if the full username is being displayed. Link to comment Share on other sites More sharing options...
water Posted November 5, 2012 Share Posted November 5, 2012 What do you have at the moment? Does your script provide any information that can be "translated" to a username? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 5, 2012 Author Share Posted November 5, 2012 I'm using the macro to pull out the @username but number 0 is displayed. Link to comment Share on other sites More sharing options...
water Posted November 5, 2012 Share Posted November 5, 2012 @UserName: ID of the currently logged on user If you need the name of the user who modified the file/directory then this should be an information returned by your function. What do you get in the ListView in column 4 ("Username")? This line in your script doesn't make sense. Did you modify the script? $sT3_UserName = GUICtrlRead(@UserName) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 5, 2012 Author Share Posted November 5, 2012 @UserName: ID of the currently logged on user If you need the name of the user who modified the file/directory then this should be an information returned by your function. What do you get in the ListView in column 4 ("Username")? This line in your script doesn't make sense. Did you modify the script? $sT3_UserName = GUICtrlRead(@UserName) Yes, I have modified the script. And the last column on my ListView is Username. If I'm going to use the @UserName, probably my username will be displayed. Link to comment Share on other sites More sharing options...
water Posted November 5, 2012 Share Posted November 5, 2012 I assume that the ListView contains all modified files with Action, Time, File and User. I further assume that you monitor a network file share. Could you run the unmodified script, let someone change/create a file and then tell us what you get in column "User". My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 5, 2012 Author Share Posted November 5, 2012 Here is the original script: expandcollapse popup#include <Constants.au3> #include <WinAPI.au3> #include <Date.au3> #include <GUIConstants.au3> #include <GuiListBox.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> Global Const _ $FILE_FLAG_BACKUP_SEMANTICS = 0x02000000, _ $FILE_FLAG_OVERLAPPED = 0x40000000 Global Const _ $FILE_NOTIFY_CHANGE_ALL = 0x17F, _ $FILE_NOTIFY_CHANGE_FILE_NAME = 0x001, _ $FILE_NOTIFY_CHANGE_DIR_NAME = 0x002, _ $FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x004, _ $FILE_NOTIFY_CHANGE_SIZE = 0x008, _ $FILE_NOTIFY_CHANGE_LAST_WRITE = 0x010, _ $FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x020, _ $FILE_NOTIFY_CHANGE_CREATION = 0x040, _ $FILE_NOTIFY_CHANGE_SECURITY = 0x100 Global Const _ $FILE_ACTION_ADDED = 0x1, _ $FILE_ACTION_REMOVED = 0x2, _ $FILE_ACTION_MODIFIED = 0x3, _ $FILE_ACTION_RENAMED_OLD_NAME = 0x4, _ $FILE_ACTION_RENAMED_NEW_NAME = 0x5 Global Const _ $MWMO_ALERTABLE = 0x0002, _ $MWMO_INPUTAVAILABLE = 0x0004, _ $MWMO_WAITALL = 0x0001 Global Const $FILE_LIST_DIRECTORY = 0x0001 Global Const $QS_ALLINPUT = 0x04FF Global Const $INFINITE = 0xFFFF Global Const $tagFNIIncomplete = "dword NextEntryOffset;dword Action;dword FileNameLength" Global $bMonitorDone, $bSelected, $bMonitor AutoItSetOption("GUIOnEventMode", 1) $gFileMon = GUICreate("BMC Server Monitoring v1.0 - Ray Anthony Leong", 731, 385, 194, 126) GUISetOnEvent($GUI_EVENT_CLOSE, "_OnEvent_Close") GUICtrlCreateGroup("Monitored Directories", 8, 0, 713, 105) $btAdd = GUICtrlCreateButton("Add", 16, 24, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Add") $btRemove = GUICtrlCreateButton("Remove", 16, 56, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Remove") GUICtrlSetState(-1, $GUI_DISABLE) $lbDirectories = GUICtrlCreateList("", 104, 16, 506, 71) $btMonitor = GUICtrlCreateButton("Start Monitor", 632, 24, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Monitor") GUICtrlSetState(-1, $GUI_DISABLE) $btClear = GUICtrlCreateButton("Clear", 632, 56, 75, 25, 0) GUICtrlSetOnEvent(-1, "_OnEvent_Clear") GUICtrlCreateGroup("", -99, -99, 1, 1) $lvNotifications = GUICtrlCreateListView("Action|Time|File", 10, 112, 710, 260) GUICtrlSendMsg(-1, 0x101E, 0, Int(.1*710)) GUICtrlSendMsg(-1, 0x101E, 1, Int(.2*710)) GUICtrlSendMsg(-1, 0x101E, 2, Int(.5*710)-20) GUISetState(@SW_SHOW) _Main() Func _DisplayFileMessages($hBuffer, $sDir) Local $hFileNameInfo, $pBuffer, $hTime Local $nFileNameInfoOffset = 12, $nOffset = 0, $nNext = 1 $pBuffer = DllStructGetPtr($hBuffer) While $nNext <> 0 $hFileNameInfo = DllStructCreate($tagFNIIncomplete, $pBuffer + $nOffset) $hFileName = DllStructCreate("wchar FileName[" & DllStructGetData($hFileNameInfo, "FileNameLength")/2 & "]", $pBuffer + $nOffset + $nFileNameInfoOffset) $hTime = _Date_Time_GetSystemTime() Switch DllStructGetData($hFileNameInfo, "Action") Case $FILE_ACTION_ADDED _GUICtrlListView_InsertItem($lvNotifications, "Created", 0) Case $FILE_ACTION_REMOVED _GUICtrlListView_InsertItem($lvNotifications, "Deleted", 0) Case $FILE_ACTION_MODIFIED _GUICtrlListView_InsertItem($lvNotifications, "Modified", 0) Case $FILE_ACTION_RENAMED_OLD_NAME _GUICtrlListView_InsertItem($lvNotifications, "Rename-", 0) Case $FILE_ACTION_RENAMED_NEW_NAME _GUICtrlListView_InsertItem($lvNotifications, "Rename+", 0) Case Else _GUICtrlListView_InsertItem($lvNotifications, "Unknown", 0) EndSwitch _GUICtrlListView_AddSubItem($lvNotifications, 0, _Date_Time_SystemTimeToDateTimeStr($hTime), 1) _GUICtrlListView_AddSubItem($lvNotifications, 0, $sDir & DllStructGetData($hFileName, "FileName"), 2) $nNext = DllStructGetData($hFileNameInfo, "NextEntryOffset") $nOffset += $nNext WEnd EndFunc Func _GetBufferHandle () Return DllStructCreate("ubyte[2048]") EndFunc Func _GetDirectoryChanges($aDirHandles, $hBuffer, $aOverlapped, $hEvents, $aDirs, $bAsync = Default, $nTimeout = Default) Local $aMsg, $i, $nBytes = 0 If $nTimeout = -1 Or IsKeyword($nTimeout) Then $nTimeout = 250 If Not $bAsync Then $nTimeout = $INFINITE $aMsg = DllCall("User32.dll", "dword", "MsgWaitForMultipleObjectsEx", _ "dword", UBound($aOverlapped), _ "ptr", DllStructGetPtr($hEvents), _ "dword", $nTimeout, _ "dword", 0, _ "dword", 0x6) $i = $aMsg[0] Switch $i Case 0 To UBound($aDirHandles)-1 If Not _WinAPI_GetOverlappedResult($aDirHandles[$i], DllStructGetPtr($aOverlapped[$i]), $nBytes, True) Then ConsoleWrite("!> GetOverlappedResult Error(" & @error & "): " & _WinAPI_GetLastErrorMessage() & @LF) Return 0 EndIf DllCall("Kernel32.dll", "Uint", "ResetEvent", "uint", DllStructGetData($aOverlapped[$i], "hEvent")) _DisplayFileMessages($hBuffer, $aDirs[$i]) _SetReadDirectory($aDirHandles[$i], $hBuffer, $aOverlapped[$i],False,True) Return $nBytes EndSwitch Return 0 EndFunc Func _GetDirHandle($sDir) Local $aResult $aResult = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sDir, _ "int", $FILE_LIST_DIRECTORY, _ "int", BitOR($FILE_SHARE_DELETE,$FILE_SHARE_READ,$FILE_SHARE_WRITE), _ "ptr", 0, _ "int", $OPEN_EXISTING, _ "int", BitOR($FILE_FLAG_BACKUP_SEMANTICS,$FILE_FLAG_OVERLAPPED), _ "int", 0) If $aResult[0] = 0 Then ConsoleWrite("!> CreateFile Error (" & @error & "): " & _WinAPI_GetLastErrorMessage() & @LF) Exit EndIf Return $aResult[0] EndFunc Func _GetEventHandles ($aOverlapped) Local $i, $hEvents $hEvents = DllStructCreate("hwnd hEvent[" & UBound($aOverlapped) & "]") For $i=1 To UBound($aOverlapped) DllStructSetData($hEvents, "hEvent", DllStructGetData($aOverlapped[$i-1], "hEvent"), $i) Next Return $hEvents EndFunc Func _GetOverlappedHandle () Local $hOverlapped = DllStructCreate($tagOVERLAPPED) For $i=1 To 5 DllStructSetData($hOverlapped, $i, 0) Next Return $hOverlapped EndFunc Func _Main () $bSelected = False $bMonitorDone = True $bMonitor = False While 1 If Not $bMonitorDone Then _MonitorDirs() If $bMonitor And _GUICtrlListBox_GetCount($lbDirectories) = 0 Then $bMonitor = Not $bMonitor GUICtrlSetState($btMonitor, $GUI_DISABLE) ElseIf Not $bMonitor And _GUICtrlListBox_GetCount($lbDirectories) > 0 Then $bMonitor = Not $bMonitor GUICtrlSetState($btMonitor, $GUI_ENABLE) EndIf If $bSelected And _GUICtrlListBox_GetCurSel($lbDirectories) = -1 Then $bSelected = Not $bSelected GUICtrlSetState($btRemove, $GUI_DISABLE) ElseIf Not $bSelected And _GUICtrlListBox_GetCurSel($lbDirectories) <> -1 Then $bSelected = Not $bSelected GUICtrlSetState($btRemove, $GUI_ENABLE) EndIf WEnd EndFunc Func _MonitorDirs () Local $i, $nMax, $hBuffer, $hEvents $nMax = _GUICtrlListBox_GetCount($lbDirectories) Local $aDirHandles[$nMax], $aOverlapped[$nMax], $aDirs[$nMax] $hBuffer = _GetBufferHandle() For $i = 0 To $nMax-1 $aDirs[$i] = _GUICtrlListBox_GetText($lbDirectories, $i) $aDirHandles[$i] = _GetDirHandle($aDirs[$i]) $aOverlapped[$i] = _GetOverlappedHandle() _SetReadDirectory($aDirHandles[$i], $hBuffer, $aOverlapped[$i], True, True) Next $hEvents = _GetEventHandles($aOverlapped) While Not $bMonitorDone _GetDirectoryChanges($aDirHandles, $hBuffer, $aOverlapped, $hEvents, $aDirs) WEnd EndFunc Func _OnEvent_Add () Local $sDir, $nMax, $i $sDir = FileSelectFolder("Select directory to monitor", "") If $sDir <> "" Then If StringRight($sDir, 1) <> "" Then $sDir &= "" $nMax = _GUICtrlListBox_GetCount($lbDirectories)-1 For $i = 0 To $nMax If _GUICtrlListBox_GetText($lbDirectories, $i) = $sDir Then Return Next _GUICtrlListBox_AddString($lbDirectories, $sDir) EndIf EndFunc Func _OnEvent_Clear () _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($lvNotifications)) EndFunc Func _OnEvent_Close () Exit EndFunc Func _OnEvent_Monitor () If $bMonitorDone Then $bMonitorDone = False GUICtrlSetData($btMonitor, "Stop Monitor") GUICtrlSetState($btAdd, $GUI_DISABLE) GUICtrlSetState($btRemove, $GUI_DISABLE) GUICtrlSetState($lbDirectories, $GUI_DISABLE) $bSelected = False Else $bMonitorDone = True GUICtrlSetState($lbDirectories, $GUI_ENABLE) GUICtrlSetState($btAdd, $GUI_ENABLE) GUICtrlSetData($btMonitor, "Start Monitor") EndIf EndFunc Func _OnEvent_Remove () _GUICtrlListBox_DeleteString($lbDirectories, _GUICtrlListBox_GetCurSel($lbDirectories)) EndFunc Func _SetReadDirectory($hDir, $hBuffer, $hOverlapped, $bInitial = False, $bSubtree = False) Local $hEvent, $pBuffer, $nBufferLength, $pOverlapped $pBuffer = DllStructGetPtr($hBuffer) $nBufferLength = DllStructGetSize($hBuffer) $pOverlapped = DllStructGetPtr($hOverlapped) If $bInitial Then $hEvent = DllCall("Kernel32.dll", "hwnd", "CreateEvent", _ "uint", 0, _ "int", True, _ "int", False, _ "uint", 0) If $hEvent[0] = 0 Then ConsoleWrite("!> CreateEvent Failed (" & _WinAPI_GetLastError() & "): " & _WinAPI_GetLastErrorMessage() & @LF) Exit EndIf DllStructSetData($hOverlapped, "hEvent", $hEvent[0]) EndIf $aResult = DllCall("Kernel32.dll", "int", "ReadDirectoryChangesW", _ "hwnd", $hDir, _ "ptr", $pBuffer, _ "dword", $nBufferLength, _ "int", $bSubtree, _ "dword", BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, _ $FILE_NOTIFY_CHANGE_SIZE,$FILE_NOTIFY_CHANGE_DIR_NAME), _ "uint", 0, _ "uint", $pOverlapped, _ "uint", 0) If $aResult[0] = 0 Then ConsoleWrite("!> ReadDirectoryChangesW Error(" & @error & "): " & _WinAPI_GetLastErrorMessage() & @LF) Exit EndIf Return $aResult[0] EndFunc Link to comment Share on other sites More sharing options...
water Posted November 5, 2012 Share Posted November 5, 2012 Fine. But how does the ListView look like after you changed a file? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 5, 2012 Author Share Posted November 5, 2012 (edited) Fine. But how does the ListView look like after you changed a file?It should be like:Action Time File UsernameRename- 10:00 test.txt waterRename+ 10:00 test.txtx waterRename- is the old filenameRename+ is the new filename Edited November 5, 2012 by aguynamedray Link to comment Share on other sites More sharing options...
water Posted November 5, 2012 Share Posted November 5, 2012 "water" is the windows login name? If yes then use _AD_Open() ; At the top of your script _AD_GetObjectAttribute("water", "sn") ; Surname _AD_GetObjectAttribute("water", "givenName") _AD_Close() ; At the end of the script My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 6, 2012 Author Share Posted November 6, 2012 Hello Water! The script you have provided is working fine but the condition here is to display the username from a specified domain who modified/deleted/moved the file/directory. Eventually not to display the current username. Thanks! Link to comment Share on other sites More sharing options...
water Posted November 6, 2012 Share Posted November 6, 2012 What do you mean by "from a specified domain"? Is this another domain then the domain the current user is a member of? E.g. the current user is a member of domain A and a user from domain B changed the file? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 6, 2012 Author Share Posted November 6, 2012 Every server has a domain... e.g. Server A = Domain A and B; Server B with Domain C and D. Link to comment Share on other sites More sharing options...
water Posted November 6, 2012 Share Posted November 6, 2012 Do you get the domain from the ListView? To get the users from multiple domains you need to either access the domain by passing the domain parameters to _AD_Open or you query the Global Catalog. What would you prefer? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
aguynamedray Posted November 7, 2012 Author Share Posted November 7, 2012 Nope. Actually after logging in in the computer with the domain, you are already connected into the server. 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