NetShare = {}; -- Shares a server resource. -- 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 -- nType - Contains the type of the shared resource. -- 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 - [optional] String that contains an comment about the shared resource -- nMaxUses - [optional] The maximum number of concurrent connections that the shared resource can accommodate. The -- number of connections is unlimited if the value specified is –1. -- Return: Success: True -- Failure: False NetShare.Add = function (sServer, sShare, nType, sPath, sComment, nMaxUses) sComment = sComment or ""; nMaxUses = nMaxUses or -1; local pServer = Memory.Allocate(512); local pShare = Memory.Allocate(512); local pPath = Memory.Allocate(512); local pPwd = Memory.Allocate(512); if sServer == "" then sServer = "127.0.0.1"; end if String.Left(sServer, 2) ~= "\\\\" then sServer = "\\\\" .. sServer; end local pComment = 0; if sComment ~= "" then local pComment = Memory.Allocate(512); pComment = Memory.PutString(pComment, sComment, -1, "Unicode"); end local pInfo = Memory.CreateStructure("int, int, int, int, int, int, int, int"); Memory.PutString(pServer, sServer, -1, "Unicode"); Memory.PutString(pShare, sShare, -1, "Unicode"); Memory.PutString(pPath, sPath, -1, "Unicode"); Memory.PutString(pPwd, "", -1, "Unicode"); Memory.SetStructureData(pInfo, 1, 0, pShare, ""); Memory.SetStructureData(pInfo, 2, 0, nType, ""); Memory.SetStructureData(pInfo, 3, 0, pComment, ""); Memory.SetStructureData(pInfo, 4, 0, 258, ""); Memory.SetStructureData(pInfo, 7, 0, pPath, ""); Memory.SetStructureData(pInfo, 5, 0, nMaxUses, ""); Memory.SetStructureData(pInfo, 6, 0, 0, ""); Memory.SetStructureData(pInfo, 8, 0, pPwd, ""); local sRes = DLL.CallFunction("netapi32.dll", "NetShareAdd", pServer..", 2,"..pInfo..",0", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL); Memory.Free(pServer); Memory.Free(pPwd); Memory.Free(pShare); Memory.Free(pPath); if pComment ~= 0 then Memory.Free(pComment); end Memory.FreeStructure(pInfo); return sRes == "0"; end -- Deletes a share name from a server's list of shared resources. -- 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 - Specifies the name of the share to delete -- Return: Success: True -- Failure: False NetShare.Del = function (sServer, sShare) if sServer == "" then sServer = "127.0.0.1"; end if String.Left(sServer, 2) ~= "\\\\" then sServer = "\\\\" .. sServer; end local pServer = Memory.Allocate(512); local pShare = Memory.Allocate(512); Memory.PutString(pServer, sServer, -1, "Unicode"); Memory.PutString(pShare, sShare, -1, "Unicode"); local sRes = DLL.CallFunction("netapi32.dll", "NetShareDel", pServer..", "..pShare..",0", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL); Memory.Free(pServer); Memory.Free(pShare); return sRes == "0"; end |