Click here to Skip to main content
16,003,746 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralMultipage .Tiff files Pin
Zulfikar Ali1-Nov-02 11:19
Zulfikar Ali1-Nov-02 11:19 
GeneralRe: Multipage .Tiff files Pin
Zulfikar Ali6-Nov-02 5:44
Zulfikar Ali6-Nov-02 5:44 
QuestionHow do I update the time or frames display for a video? Pin
James Williams1-Nov-02 5:34
James Williams1-Nov-02 5:34 
GeneralPrepare for extremely stupid question! Pin
Matt Philmon1-Nov-02 5:11
Matt Philmon1-Nov-02 5:11 
GeneralRe: Prepare for extremely stupid question! Pin
Pete Bassett1-Nov-02 5:52
Pete Bassett1-Nov-02 5:52 
Generalconnecting to network folder using vb.net Pin
pampatipaveen31-Oct-02 14:30
pampatipaveen31-Oct-02 14:30 
GeneralRe: connecting to network folder using vb.net Pin
mikasa1-Nov-02 2:31
mikasa1-Nov-02 2:31 
GeneralEnumerating Servers on Win9x Pin
mikasa31-Oct-02 8:17
mikasa31-Oct-02 8:17 
Ok, I understand that the NetServerEnum API functions do not work on a Win9x machine. In VB6, I had code to enumerate Servers on a Windows9x machine, however, porting it to VB.NET seems impossible. I have it working...somewhat. However, it only enumerates the Top-Level Node everytime!

If someone could please shed some light on what I am doing wrong I would greatly appreciate it! This was all guess-work on my part even though I understand Marshalling a little bit.

Here's what I have so far:

'Declarations
'API Declarations
Private Declare Auto Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Integer, ByVal dwBytes As Integer) As Integer
Private Declare Auto Function GlobalFree Lib "kernel32" (ByVal hMem As Integer) As Integer

'API Declarations for Win9x
Private Declare Ansi Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Integer, ByVal dwType As Integer, ByVal dwUsage As Integer, ByRef lpNetResource As IntPtr, ByRef lphEnum As Integer) As Integer
Private Declare Ansi Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Integer, ByRef lpcCount As Integer, ByVal lpBuffer As Integer, ByRef lpBufferSize As Integer) As Integer
Private Declare Ansi Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Integer) As Integer

'Structures
<Runtime.InteropServices.StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure NETRESOURCE
Dim Scope As Integer
Dim Type As Integer
Dim DisplayType As Integer
Dim Usage As Integer
Dim LocalName As IntPtr
Dim RemoteName As IntPtr
Dim Comment As IntPtr
Dim Provider As IntPtr
End Structure

'Constants for WNetEnum
Private Enum ResourceScopes
resConnected = &H1 'All currently connected resources (the dwUsage parameter is ignored)
resGlobalNet = &H2 'All resources on the network.
resRemembered = &H3 'All remembered (persistent) connections (dwUsage is ignored)
resRecent = &H4
resContext = &H5
End Enum
Private Enum ResourceTypes
resAny = &H0 'All resources (this value cannot be combined with RESOURCETYPE_DISK or RESOURCETYPE_PRINT).
resDisk = &H1 'All disk resources.
resPrinter = &H2 'All print resources.
resReserved = &H8
resUnknown = &HFFFF
End Enum
Private Enum ResourceUseages 'Ignored if the ResourceScope is not 'resGlobalNet'
resAll = ((&H1) Or (&H2))
resConnectable = &H1
resContainer = &H2
resNoLocalDevice = &H4
resSibling = &H8
resReserved = &H80000000
End Enum
Private Enum ResourceDisplayTypes 'Used to Determine the Resource Type of the NETRESOURCE Struct
resGeneric = &H0
resDomain = &H1
resServer = &H2
resShare = &H3
resFile = &H4
resGroup = &H5
resNetwork = &H6
resRoot = &H7
resShareAdmin = &H8
resDirectory = &H9
resTree = &HA
End Enum

'Enumerations
Public Enum ServerTypes
All = &HFFFFFFFF '/* handy for NetServerEnum2 */
Browsers = &H10000
Browser_Backup = &H20000
Browser_Master = &H40000
Domains = &H80000000
DomainController = &H8
DomainBackController = &H10
DomainMaster = &H80000
DomainMember = &H100
Novell = &H80
NTClusters = &H1000000 '/* NT Cluster */
Servers = &H2 ' All Servers
ServersDialIn = &H400
ServersLocal = &H40000000
ServersPrintQ = &H200
ServersNT = &H8000
ServersSQL = &H4 ' SQL Server
ServersXenix = &H800
ServersUnix = &H800
TimeServers = &H20
Workstations = &H1
WorkstationsNT = &H1000
WorkstationsWin9x = &H400000 '/* Windows95 and above */
End Enum





'Routine to Refresh Servers on a Win9x Machine (uses Recursion)
Private Sub RefreshServersWin9x(Optional ByVal Domain As String = Nothing)
Dim vResource As NETRESOURCE
Dim hResult, hEnum, hBuffer, hPointer, i As Integer
Dim nBufferSize As Integer = 16384, nCount As Integer = &HFFFFFFFF
Const GMEM_FIXED As Integer = &H0
Const GMEM_ZEROINIT As Integer = &H40
Const GPTR As Integer = (GMEM_FIXED Or GMEM_ZEROINIT)


'Initialize the Buffer Pointer
Dim ptrBuffer As IntPtr = IntPtr.Zero, ptrDomain As IntPtr = IntPtr.Zero
If (Not IsNothing(Domain)) AndAlso (Domain.Length > 0) Then
ptrDomain = Marshal.StringToBSTR(Domain)
ptrBuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(vResource))
vResource.RemoteName = ptrDomain
Call Marshal.StructureToPtr(vResource, ptrBuffer, True)
End If

Try
hResult = WNetOpenEnum(ResourceScopes.resGlobalNet, ResourceTypes.resAny, ResourceUseages.resContainer, ptrBuffer, hEnum)
If (hResult = 0) And (hEnum <> 0) Then 'Successful
'Enumerate the Resource
hBuffer = GlobalAlloc(GPTR, nBufferSize)
hResult = WNetEnumResource(hEnum, nCount, hBuffer, nBufferSize)

If (hResult = 0) Then 'Successful
hPointer = hBuffer
For i = 0 To nCount - 1
'Retrieve the Information for the Resource
vResource = CType(Marshal.PtrToStructure(New IntPtr(hPointer), GetType(NETRESOURCE)), NETRESOURCE)

'Recurse to Find the Servers if this is a Root or Domain Node
Select Case vResource.DisplayType
Case ResourceDisplayTypes.resDomain, ResourceDisplayTypes.resGroup, ResourceDisplayTypes.resNetwork, ResourceDisplayTypes.resRoot
Call Me.RefreshServersWin9x(Marshal.PtrToStringAnsi(vResource.RemoteName))
End Select

'Determine the Next Pointer
hPointer += Marshal.SizeOf(vResource)
Next i
End If
End If
bInitialized = True
Catch
'Call Globals.ErrorMessage("Refresh")
Finally
'Free Up Memory
Call Marshal.FreeCoTaskMem(ptrBuffer)
Call Marshal.FreeCoTaskMem(ptrDomain)

If (hEnum > 0) Then hResult = WNetCloseEnum(hEnum)
If (hBuffer > 0) Then hResult = GlobalFree(hBuffer)
End Try
End Sub
GeneralRe: Enumerating Servers on Win9x Pin
mikasa1-Nov-02 11:41
mikasa1-Nov-02 11:41 
Generalchanging cursor Pin
mariuszpopiolek31-Oct-02 6:32
mariuszpopiolek31-Oct-02 6:32 
General.NET Remoting in VB.NET Pin
Dam_f31-Oct-02 4:57
Dam_f31-Oct-02 4:57 
GeneralUpdate Registry permissions Pin
Andy H30-Oct-02 9:27
Andy H30-Oct-02 9:27 
GeneralRe: Update Registry permissions Pin
ian mariano30-Oct-02 22:06
ian mariano30-Oct-02 22:06 
GeneralApplication for all resolution Pin
Notorious SMC29-Oct-02 16:24
sussNotorious SMC29-Oct-02 16:24 
GeneralRe: Application for all resolution Pin
ian mariano30-Oct-02 1:51
ian mariano30-Oct-02 1:51 
Generalnetapi32.dll and windows 98 ? (VB.NET) Pin
Vipul Bhatt27-Oct-02 22:40
Vipul Bhatt27-Oct-02 22:40 
GeneralRe: netapi32.dll and windows 98 ? (VB.NET) Pin
ian mariano28-Oct-02 9:51
ian mariano28-Oct-02 9:51 
GeneralRe: netapi32.dll and windows 98 ? (VB.NET) Pin
Vipul Bhatt29-Oct-02 1:45
Vipul Bhatt29-Oct-02 1:45 
GeneralRe: netapi32.dll and windows 98 ? (VB.NET) Pin
ian mariano29-Oct-02 9:03
ian mariano29-Oct-02 9:03 
GeneralRe: netapi32.dll and windows 98 ? (VB.NET) Pin
mikasa31-Oct-02 7:28
mikasa31-Oct-02 7:28 
Questionhelp for Spreadsheet 10.0 component? Pin
drmzunlimited27-Oct-02 21:06
drmzunlimited27-Oct-02 21:06 
Generalvisual basic mdi form Pin
Anonymous27-Oct-02 16:08
Anonymous27-Oct-02 16:08 
GeneralRe: visual basic mdi form Pin
humera27-Oct-02 16:10
humera27-Oct-02 16:10 
GeneralRe: visual basic mdi form Pin
Nick Parker28-Oct-02 2:24
protectorNick Parker28-Oct-02 2:24 
GeneralRe: visual basic mdi form Pin
Pete Bassett1-Nov-02 5:58
Pete Bassett1-Nov-02 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.