#include <NetShare.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Date.au3>
$day = @MDAY
$sLogPath=@ScriptDir
$LogFile = FileOpen($sLogPath & "\" & @MON & "月" & @MDAY & "日" & ".txt",1+8)
Global $bInfo
OnAutoItExitRegister("Onexit" )
MemoWrite("程序启动")
While 1
If $day <> @MDAY Then
FileClose($sLogPath & "\" & @MON & "月" & $day & "日" & ".txt")
$LogFile = FileOpen($sLogPath & "\" & @MON & "月" & @MDAY & "日" & ".txt",1+8)
$day = @MDAY
EndIf
Example()
Sleep(1000)
WEnd
Func Example()
Local $aInfo
$server=("\\homepc")
$share=("e")
$aInfo=_Net_Share_ConnectionEnum($server,$share)
If @error Then MemoWrite("Error ...................: " & @error)
;MemoWrite("Entries read ............: " & $aInfo)
For $iI = 1 To $aInfo
Local $yes = 0
For $x = 1 To $bInfo
If $aInfo[$iI] = $bInfo[$x] Then
$yes = 1
$bInfo[$x] = ""
$bInfo[$x] = ""
$bInfo[$x] = ""
$bInfo[$x] = ""
$bInfo[$x] = ""
$bInfo[$x] = ""
$bInfo[$x] = ""
ExitLoop
EndIf
Next
If Not $yes Then
MemoWrite("登入")
MemoWrite("Connection ID ...........: " & $aInfo[$iI])
MemoWrite("Connection type..........: " & _Net_Share_ResourceStr($aInfo[$iI]))
MemoWrite("Number of files open ....: " & $aInfo[$iI])
MemoWrite("Number of users .........: " & $aInfo[$iI])
MemoWrite("Connection time .........: " & $aInfo[$iI])
MemoWrite("User name ...............: " & $aInfo[$iI])
MemoWrite("Computer name ...........: " & $aInfo[$iI])
MemoWrite("************************************************************")
EndIf
Next
For $x = 1 To $bInfo
If $bInfo[$x] <> "" then
MemoWrite("退出")
MemoWrite("Connection ID ...........: " & $bInfo[$x])
MemoWrite("Connection type..........: " & _Net_Share_ResourceStr($bInfo[$x]))
MemoWrite("Number of files open ....: " & $bInfo[$x])
MemoWrite("Number of users .........: " & $bInfo[$x])
MemoWrite("Connection time .........: " & $bInfo[$x])
MemoWrite("User name ...............: " & $bInfo[$x])
MemoWrite("Computer name ...........: " & $bInfo[$x])
MemoWrite("************************************************************")
EndIf
Next
$bInfo = $aInfo
EndFunc
Func MemoWrite($message="")
FileWriteLine($LogFile, _NowCalc() & " " & $message & @CRLF)
EndFunc
Func Onexit()
MemoWrite("程序正常退出")
EndFunc 以上程序在两台电脑访问共享文件夹时测试通过,更多的电脑没有测试过。增加了长期运行时自动保存当日的日志为单独的文件的功能,如不需要可以删除;增加了我在15楼说的判断功能,只有在登入或退出时写入日志文件;另外把测试时发现 _FileWriteLog处理的日期有时候会丢失或多出部分字符串,所以改成了FileWriteLine。 回复 17# luren666
谢谢~~
页:
1
[2]