Click here to Skip to main content
15,867,568 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to enforce db access security? Pin
James T. Johnson2-Nov-02 5:04
James T. Johnson2-Nov-02 5:04 
GeneralRe: String Methods Seem Broken Pin
David Stone1-Nov-02 11:25
sitebuilderDavid Stone1-Nov-02 11:25 
QuestionHow to notify the parent? (passing event to the parent) Pin
Zinj1-Nov-02 9:13
sussZinj1-Nov-02 9:13 
AnswerRe: How to notify the parent? (passing event to the parent) Pin
John Fisher1-Nov-02 12:35
John Fisher1-Nov-02 12:35 
GeneralRe: How to notify the parent? (passing event to the parent) Pin
Zinj2-Nov-02 9:32
sussZinj2-Nov-02 9:32 
QuestionBest way to store data? Pin
hammackj1-Nov-02 8:42
hammackj1-Nov-02 8:42 
AnswerRe: Best way to store data? Pin
TigerNinja_1-Nov-02 11:30
TigerNinja_1-Nov-02 11:30 
GeneralEnumerating Severs on Win9x Pin
mikasa1-Nov-02 7:31
mikasa1-Nov-02 7:31 
I am posting this here in case anyone has an idea or can help...

Ok, I understand that the NetServerEnum API (netapi.dll) 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 Severs on Win9x Pin
TigerNinja_1-Nov-02 11:29
TigerNinja_1-Nov-02 11:29 
GeneralRe: Enumerating Severs on Win9x Pin
mikasa1-Nov-02 11:40
mikasa1-Nov-02 11:40 
GeneralBetter RichTextBox (or custom textbox) Pin
Bog1-Nov-02 5:48
Bog1-Nov-02 5:48 
GeneralRe: Better RichTextBox (or custom textbox) Pin
Pete Bassett1-Nov-02 6:30
Pete Bassett1-Nov-02 6:30 
GeneralRe: Better RichTextBox (or custom textbox) Pin
Bog2-Nov-02 5:05
Bog2-Nov-02 5:05 
GeneralRe: Better RichTextBox (or custom textbox) Pin
Pete Bassett3-Nov-02 7:47
Pete Bassett3-Nov-02 7:47 
GeneralRe: Better RichTextBox (or custom textbox) Pin
Philip Fitzsimons1-Nov-02 6:54
Philip Fitzsimons1-Nov-02 6:54 
GeneralRe: Better RichTextBox (or custom textbox) Pin
Stephane Rodriguez.1-Nov-02 7:07
Stephane Rodriguez.1-Nov-02 7:07 
GeneralPassword in a Propertygrid Pin
Andy Hampshire1-Nov-02 4:00
Andy Hampshire1-Nov-02 4:00 
GeneralRe: Password in a Propertygrid Pin
Stephane Rodriguez.1-Nov-02 7:12
Stephane Rodriguez.1-Nov-02 7:12 
GeneralRe: Password in a Propertygrid Pin
Andy Hampshire1-Nov-02 7:23
Andy Hampshire1-Nov-02 7:23 
GeneralRe: Password in a Propertygrid - HELP !! Pin
Andy Hampshire1-Nov-02 14:22
Andy Hampshire1-Nov-02 14:22 
GeneralRe: Password in a Propertygrid - HELP !! Pin
leppie1-Nov-02 21:16
leppie1-Nov-02 21:16 
GeneralRe: Password in a Propertygrid - HELP !! Pin
Feng Qin3-Nov-02 21:24
Feng Qin3-Nov-02 21:24 
GeneralNot able to fetch first row of excel...... Pin
Saroj31-Oct-02 23:33
Saroj31-Oct-02 23:33 
GeneralRe: Not able to fetch first row of excel...... Pin
Stephane Rodriguez.1-Nov-02 1:59
Stephane Rodriguez.1-Nov-02 1:59 
Generalabout visual soucesafe6.0c Pin
Anonymous31-Oct-02 21:18
Anonymous31-Oct-02 21:18 

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.