↑  ←  Описание функции


_Net_Share_ShareAdd

Shares a server resource

#include <NetShare.au3>
_Net_Share_ShareAdd($sServer, $sShare, $iType, $sPath [, $sComment = "" [, $iMaxUses = -1]])

Параметры

$sServer Specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If
    this parameter is blank, the local computer is used.
$sShare Share name of a resource
$iType Contains the type of the shared resource. Can be a combination of:
    $STYPE_DISKTREE - Disk drive
    $STYPE_PRINTQ - Print queue
    $STYPE_DEVICE - Communication device
    $STYPE_IPC - IPC
    $STYPE_SPECIAL - Special share reserved for IPC$ or remote administration of the server
    $STYPE_TEMPORARY - A temporary share
$sPath Local path for the shared resource. For disks, this is the path being shared. For print queues,
    this is the name of the print queue being shared.
$sComment [необязательный] String that contains an comment about the shared resource
$iMaxUses [необязательный] The maximum number of concurrent connections that the shared resource can accommodate. The
    number of connections is unlimited if the value specified is –1.

Возвращаемое значение

Успех:Возвращает True
Ошибка:Возвращает False

Примечания

Only members of the Administrators, System Operators, or Power Users local group can add file shares with a
call to this function. The Print Operator can add printer shares.

См. также

_Net_Share_ShareCheck, _Net_Share_ShareDel

См. также

Искать NetApiBufferFree в библиотеке MSDN

Пример

#include <GUIConstantsEx.au3>
#include <NetShare.au3>
#include <WindowsConstants.au3>

Global $iMemo

_Main()

Func _Main()
    Local $hGUI, $iI, $aInfo
    Local Const $sShareName = "AutoIt Share"

    ; Создаёт GUI
    $hGUI = GUICreate("NetShare", 400, 300)

    ; Создаёт элемент для заметок
    $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, "Information", "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, "Information", "Share delete error : " & @error)
    MemoWrite("Share deleted")

    ; Цикл выполняется, пока окно не будет закрыто
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

; Записывает строку в элемент для заметок
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite