找回密码
 加入
搜索
楼主: ppaiyy520

[AU3基础] 访问共享文件夹相关[已解决]

 火.. [复制链接]
发表于 2015-7-21 11:44:58 | 显示全部楼层
#include <GUIConstantsEx.au3>
#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[1][1]
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[0][0])

                For $iI = 1 To $aInfo[0][0]
                        Local $yes = 0
                        For $x = 1 To $bInfo[0][0]
                                If $aInfo[$iI][0] = $bInfo[$x][0] Then
                                        $yes = 1
                                        $bInfo[$x][0] = ""
                                        $bInfo[$x][1] = ""
                                        $bInfo[$x][2] = ""
                                        $bInfo[$x][3] = ""
                                        $bInfo[$x][4] = ""
                                        $bInfo[$x][5] = ""
                                        $bInfo[$x][6] = ""
                                        ExitLoop
                                EndIf
                        Next
                        If Not $yes Then
                                MemoWrite("登入")
                                MemoWrite("Connection ID ...........: " & $aInfo[$iI][0])
                                MemoWrite("Connection type..........: " & _Net_Share_ResourceStr($aInfo[$iI][1]))
                                MemoWrite("Number of files open ....: " & $aInfo[$iI][2])
                                MemoWrite("Number of users .........: " & $aInfo[$iI][3])
                                MemoWrite("Connection time .........: " & $aInfo[$iI][4])
                                MemoWrite("User name ...............: " & $aInfo[$iI][5])
                                MemoWrite("Computer name ...........: " & $aInfo[$iI][6])
                                MemoWrite("************************************************************")
                        EndIf
                Next
                For $x = 1 To $bInfo[0][0]
                        If $bInfo[$x][0] <> "" then
                                        MemoWrite("退出")
                                        MemoWrite("Connection ID ...........: " & $bInfo[$x][0])
                                        MemoWrite("Connection type..........: " & _Net_Share_ResourceStr($bInfo[$x][1]))
                                        MemoWrite("Number of files open ....: " & $bInfo[$x][2])
                                        MemoWrite("Number of users .........: " & $bInfo[$x][3])
                                        MemoWrite("Connection time .........: " & $bInfo[$x][4])
                                        MemoWrite("User name ...............: " & $bInfo[$x][5])
                                        MemoWrite("Computer name ...........: " & $bInfo[$x][6])
                                        MemoWrite("************************************************************")
                                EndIf
                Next
        $bInfo = $aInfo
        EndFunc

Func MemoWrite($message="")
        FileWriteLine($LogFile, _NowCalc() & "        " & $message & @CRLF)
EndFunc

Func Onexit()
        MemoWrite("程序正常退出")
EndFunc
发表于 2015-7-21 11:51:42 | 显示全部楼层
以上程序在两台电脑访问共享文件夹时测试通过,更多的电脑没有测试过。增加了长期运行时自动保存当日的日志为单独的文件的功能,如不需要可以删除;增加了我在15楼说的判断功能,只有在登入或退出时写入日志文件;另外把测试时发现 _FileWriteLog处理的日期有时候会丢失或多出部分字符串,所以改成了FileWriteLine。
 楼主| 发表于 2015-7-21 13:49:43 | 显示全部楼层
回复 17# luren666


    谢谢~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-17 12:43 , Processed in 0.065876 second(s), 15 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表