ccidnet广告

新用户注册

赛迪社区

帮助

  新闻中心 | 关注 | 技术天地 | 软件特供 | IT财经 | 市场专家 | 互动学校 | DIY专区 | 新游戏客栈 | 媒体全文



相关文章

  备份和恢复[微软提供]
  也谈“SQL Server的备份和升级”







 当前页面位置: 主页: 技术天地: 模板源码: 技术文章

从指定的域中取得所有SQL服务器的清单
(作者: 2000年05月23日 09:46)


[程序语言] Microsoft Visual Basic 4.0,5.0,6.0

[运行平台] WINDOWS

[源码来源] http://codeguru.developer.com/vb/articles/1916.shtml

[功能描述]

  想知道哪些NT机器上装了SQL服务器吗? 使用NetServerEnum API时,我发现如下问题的解决方案,写出来给大家分享。该程序并不是返回服务器的清单,它只是进行 debug.print。

把下列代码贴到BAS模块中:



option Explicit

'

'

'

private Declare Function lstrlenW Lib "kernel32" (byval lpString as Long) as Long

'

private Declare Function NetServerEnum Lib "netapi32" ( _

  strServername as Any, _

  byval level as Long, _

  bufptr as Long, _

  byval prefmaxlen as Long, _

  entriesread as Long, _

  totalentries as Long, _

  byval servertype as Long, _

  strDomain as Any, _

  resumehandle as Long) as Long

'

private Declare Function NetApiBufferFree Lib "Netapi32.dll" (byval lpBuffer as Long) as Long

'

private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination as Any, Source as Any, byval Length as Long)

'

private Const SV_TYPE_SERVER as Long = &H2

private Const SV_TYPE_SQLSERVER as Long = &H4

'

private Type SV_100

  platform as Long

  name as Long

End Type

'

'

public Sub GetSQLServers()

'

' You could change this to be a function returning

' a list of the SQL servers in a ADOR Recordset or an array etc.

'

' At present, it just does a debug.print of all the

' SQL servers on the network.

'

'

  Dim l as Long

  Dim entriesread as Long

  Dim totalentries as Long

  Dim hREsume as Long

  Dim bufptr as Long

  Dim level as Long

  Dim prefmaxlen as Long

  Dim lType as Long

  Dim domain() as Byte

  Dim i as Long

  Dim sv100 as SV_100

'

  level = 100

  prefmaxlen = -1

'

  lType = SV_TYPE_SQLSERVER

  domain = "placeYourDomainNameHere" & vbNullChar

  l = NetServerEnum(byval 0&, _

      level, _

      bufptr, _

      prefmaxlen, _

      entriesread, _

      totalentries, _

      lType, _

      domain(0), _

      hREsume)

  

  If l = 0 Or l = 234& then

    for i = 0 to entriesread - 1

      CopyMemory sv100, byval bufptr, len(sv100)

      Debug.print Pointer2stringw(sv100.name)

      bufptr = bufptr + len(sv100)

    next i

  End If

  NetApiBufferFree bufptr

'

End Sub

'

private Function Pointer2stringw(byval l as Long) as string

  Dim buffer() as Byte

  Dim nLen as Long

'

  nLen = lstrlenW(l) * 2

  If nLen then

    ReDim buffer(0 to (nLen - 1)) as Byte

    CopyMemory buffer(0), byval l, nLen

    Pointer2stringw = buffer

  End If

End Function

'

'





与CCIDNET联系
webmaster@ciw.com.cn