It is currently Tue Jul 16, 2019 6:13 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Network Share Management
PostPosted: Sun Dec 28, 2014 4:44 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
-----------------------------------------------------------------------------------

Download Network Share Management from My PureBasic Stuff

-----------------------------------------------------------------------------------

Tricks 'n' Tips
PureBasic Interface to OpenCV
PureBasic Interface to WinDivert
PureBasic Interface to WinRAR
PureBasic Interface to 7-Zip
PureBasic Interface to ImDisk
Windows Services & Other Stuff
Invading Space Aliens
Death Star vs Asteroids
GIF Toolkit
LSB File Embedding
Spider Web Drawing
Deform Image: MLS
Video Snipping Tool
Image Waves: LUT
HTML5 YouTube Player
HTML5 MP4 Player
Barcode Generator
Embed JS into PureBasic
Geolocation: Google Maps
Book & Viewer & Magnify
Video for Windows: VfW
Alternate Console
Network Share Management

-----------------------------------------------------------------------------------

Network Share Management Functions
- additional functions handling permissions
-- AllocateAndInitializeSid
-- InitializeAcl
-- InitializeSecurityDescriptor
-- SetEntriesInAcl
-- SetSecurityDescriptorDacl
-- GetNamedSecurityInfo
-- BuildExplicitAccessWithName
-- SetNamedSecurityInfo

-----------------------------------------------------------------------------------

INCLUDES:
- constants.pbi
- procedures.pbi
- structures.pbi

EXAMPLES:
- NetFile Functions:
-- NetFileClose.pb
-- NetFileEnum.pb
-- NetFileGetInfo.pb

- Session Functions:
-- NetSessionDel.pb
-- NetSessionEnum.pb
-- NetSessionGetInfo.pb

- Network Share Functions:
-- NetConnectionEnum.pb
-- NetShareAdd.pb
--- add permissions: SID / Name
-- NetShareCheck.pb
-- NetShareDel.pb
-- NetShareDelEx.pb
-- NetShareEnum.pb
-- NetShareGetInfo.pb
-- NetShareSetInfo_1.pb
--- replace permissions
-- NetShareSetInfo_2.pb
--- update permissions

- Statistics Function:
-- NetStatisticsGet.pb

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Thu Jun 06, 2019 7:06 am, edited 57 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Network Share Management Functions
PostPosted: Tue Dec 30, 2014 8:49 am 
Offline
Enthusiast
Enthusiast

Joined: Fri May 21, 2004 3:31 pm
Posts: 167
really nice work JHPJHP thanks for that!

here the NetConnectionEnum function part of the Network Share Management Functions.


Code:
EnableExplicit


#MAX_PREFERRED_LENGTH = -1
#NERR_SUCCESS=0
#ERROR_MORE_DATA = 234
#LB_SETTABSTOPS= 402
#STYPE_DISKTREE = 0   
#STYPE_PRINTQ = 1
#STYPE_DEVICE = 2
#STYPE_IPC = 3

Structure CONNECTION_INFO_1
  coni1_id.i
  coni1_type.i
  coni1_num_opens.i
  coni1_num_users.i
  coni1_time.i
  coni1_username.i
  coni1_netname.i
EndStructure

Structure CONNECTION_INFO_1_Container
  coni1_id.l
  coni1_type.s
  coni1_num_opens.l
  coni1_num_users.l
  coni1_time.s
  coni1_username.s
  coni1_netname.s
EndStructure

Global NewList NetConnectEnum.CONNECTION_INFO_1_Container()


Procedure.s GetConnectionType(dwSessionType.i)
 
  Select  Val(Hex(dwSessionType))
    Case #STYPE_DISKTREE
      ProcedureReturn  "Disk drive"
    Case #STYPE_PRINTQ
      ProcedureReturn  "Print queue"
    Case #STYPE_DEVICE
      ProcedureReturn   "Communication device"
    Case #STYPE_IPC
      ProcedureReturn "(IPC)"
    Default
      ProcedureReturn ""
  EndSelect
 
EndProcedure


#SIZEOF_WORD = 2


;  _____________________________________________________________________________
;  |                                                                           |
;  |                            Ansi2Uni                                       |
;  |                            ________                                       |
;  |                                                                           |
;  |___________________________________________________________________________|
;{ Ansi2Uni                                   
;/ BackupUser
; part of the Droopy Library.. 

Procedure Ansi2Uni(string.s) ; Converts normal (Ansi) string To Unicode
  Protected  *out
  *out = AllocateMemory(Len(string)*2 * #SIZEOF_WORD)
  MultiByteToWideChar_(#CP_ACP, 0, string, -1, *out, Len(string)) 
  ProcedureReturn *out 
EndProcedure

Procedure NetConnectionEnum(sServer.s = "",sShare.s);Command1_Click()
 
  Protected dwEntriesread.l,dwTotalentries.l,dwResumehandle.l,success.l,nStructSize.l,cnt.l
  Protected pServer, pShare
  Protected *buffer, *ci1.CONNECTION_INFO_1
  dwEntriesread=#Null
  dwTotalentries=#Null
  dwResumehandle=#Null
  nStructSize = SizeOf(CONNECTION_INFO_1)
 
  If sServer <> ""
    sServer=RemoveString(sServer, "\" );[, Modus])
    sServer="\\"+sServer
  Else
    sServer="\\"+ComputerName() 
  EndIf
 
  CompilerIf #PB_Compiler_Unicode
    success = NetConnectionEnum_(@sServer, @sShare,1,@*buffer,#MAX_PREFERRED_LENGTH, @dwEntriesread,@dwTotalentries,@dwResumehandle)
  CompilerElse
    pServer= Ansi2Uni(sServer)
    pShare= Ansi2Uni(sShare)
    success = NetConnectionEnum_(pServer, pShare,1,@*buffer,#MAX_PREFERRED_LENGTH, @dwEntriesread,@dwTotalentries,@dwResumehandle)
  CompilerEndIf
 
  If success = #NERR_SUCCESS And success <> #ERROR_MORE_DATA And dwEntriesread <>0
   
    For cnt = 0 To dwEntriesread - 1
      *ci1.CONNECTION_INFO_1=*buffer +nStructSize*cnt
      AddElement(NetConnectEnum())
      NetConnectEnum()\coni1_username=PeekS(*ci1\coni1_username, -1, #PB_Unicode)
      NetConnectEnum()\coni1_netname=PeekS(*ci1\coni1_netname, -1, #PB_Unicode)
      NetConnectEnum()\coni1_time=FormatDate("%hh:%ii:%ss",*ci1\coni1_time)
      NetConnectEnum()\coni1_num_users=*ci1\coni1_num_users
      NetConnectEnum()\coni1_num_opens=*ci1\coni1_num_opens
      NetConnectEnum()\ coni1_id=*ci1\coni1_id
      NetConnectEnum()\coni1_type=GetConnectionType(*ci1\coni1_type)
     
    Next
  EndIf
  NetApiBufferFree_(*buffer)
 
 
  Debug "Enumconnect: "+Str(success)+" Entry Nr: "+Str(dwEntriesread)
 
EndProcedure


; Usage NetConnectionEnum(Computername,Sharename) if computername omissed then the local computername is used

NetConnectionEnum("C$")

ForEach NetConnectEnum()
  Debug "ConnectionID: " + NetConnectEnum()\coni1_id
  Debug "Connection Name: " + NetConnectEnum()\coni1_netname
  Debug "Open Connection: " + NetConnectEnum()\coni1_num_opens
  Debug "Nr. Connected Users: " + NetConnectEnum()\coni1_num_users
  Debug "Connection Time: " + NetConnectEnum()\coni1_time
  Debug "Connection Type: " + NetConnectEnum()\coni1_type
  Debug "Connected User: " + NetConnectEnum()\coni1_username
Next



br
jpd

_________________
PB 5.10 Windows 7 x64 SP1


Top
 Profile  
Reply with quote  
 Post subject: Re: Network Share Management Functions
PostPosted: Tue Apr 26, 2016 1:22 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
Hi jpd,

Thanks for the heads-up and example, I didn't realize I missed that one.

------------------------------------

Updated:
- added example: NetConnectionEnum.pb

------------------------------------

Updated:
- added support for x64

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye