检查是否有服务器共享设备
#include <NetShare.au3>
_Net_Share_ShareCheck($sServer, $sShare)
$sServer | 指定 DNS 或 NetBIOS 远程服务器上执行函数的名称 如果此参数为空, 在本地计算机上使用. |
$sShare | 指定检查共享访问的设备名称. |
成功: | 共享的设备类型. 可以是一个组合: |
$STYPE_DISKTREE - 打印队列 | |
$STYPE_PRINTQ - 磁盘驱动器 | |
$STYPE_DEVICE - 通讯设备 | |
$STYPE_IPC - IPC (工控机) | |
$STYPE_SPECIAL - 为 IPC$ 或服务器的远程管理保留的专用共享 | |
$STYPE_TEMPORARY - 临时共享 | |
失败: | 返回 -1 - 共享不存在 |
在MSDN中搜索
#include <GUIConstantsEx.au3>
#include <NetShare.au3>
#include <WindowsConstants.au3>
Global $iMemo
_Main()
Func _Main()
Local $iI, $aInfo
Local Const $sShareName = "AutoIt Share"
; 创建 GUI
GUICreate("NetShare", 400, 300)
; 创建 memo 控件
$iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
; See if the share exists
If _Net_Share_ShareCheck(@ComputerName, $sShareName) = -1 Then
; Create a share on the local computer
_Net_Share_ShareAdd(@ComputerName, $sShareName, 0, "C:\", "AutoIt Share Comment")
If @error Then MsgBox(4096, "信息", "Share add error : " & @error)
MemoWrite("Share added")
Else
MemoWrite("Share exists")
EndIf
; Show information about all local shares
$aInfo = _Net_Share_ShareEnum(@ComputerName)
MemoWrite("Entries read ............: " & $aInfo[0][0])
For $iI = 1 To $aInfo[0][0]
MemoWrite("Share name ..............: " & $aInfo[$iI][0])
MemoWrite("Share type...............: " & _Net_Share_ResourceStr($aInfo[$iI][1]))
MemoWrite("Comment .................: " & $aInfo[$iI][2])
MemoWrite("Permissions .............: " & _Net_Share_PermStr($aInfo[$iI][3]))
MemoWrite("Maximum connections .....: " & $aInfo[$iI][4])
MemoWrite("Current connections .....: " & $aInfo[$iI][5])
MemoWrite("Local path ..............: " & $aInfo[$iI][6])
MemoWrite("Password ................: " & $aInfo[$iI][7])
MemoWrite()
Next
; Delete the share
_Net_Share_ShareDel(@ComputerName, $sShareName)
If @error Then MsgBox(4096, "信息", "Share delete error : " & @error)
MemoWrite("Share deleted")
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; 写入消息到 memo
Func MemoWrite($sMessage = "")
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite