1. a). App.TaskVisible = false(Maybe only used under 95/98/Me) b). Use WinAPI Private Const RSP_SIMPLE_SERVICE = 1 Private Const RSP_UNREGISTER_SERVICE = 0Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate Sub HideApp(lbValue As Boolean) Dim lProcessID As Long Dim lReturn As Long lProcessID = GetCurrentProcessId() If lbValue Then lReturn = RegisterServiceProcess(lProcessID, RSP_SIMPLE_SERVICE) Else lReturn = RegisterServiceProcess(lProcessID, RSP_UNREGISTER_SERVICE) End If End Sub
Option ExplicitPublic Declare Function GetCurrentProcessId Lib "kernel32" () As Long Public Declare Function GetCurrentProcess Lib "kernel32" () As Long Public Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long Public Const RSP_SIMPLE_SERVICE = 1 Public Const RSP_UNREGISTER_SERVICE = 0 'Option ExplicitPrivate Sub Command1_Click() '下面代码为隐藏 Dim pid As Long Dim reserv As Long pid = GetCurrentProcessId() regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE) End SubPrivate Sub Command2_Click() '恢复隐藏 Dim pid As Long Dim reserv As Long pid = GetCurrentProcessId() regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE) End Sub
以下是你的第二个问题的源代码: 添加一个按钮(Command1),一个下拉组合框(Combo1)和一个列表框(List1)。把下面的代码复制到Form中 --------------------------------------------------------------------------------Option Explicit 'Windows type used to call the Net API Private Const MAX_PREFERRED_LENGTH As Long = -1 Private Const NERR_SUCCESS As Long = 0& Private Const ERROR_MORE_DATA As Long = 234&Private Const SV_TYPE_WORKSTATION As Long = &H1 Private Const SV_TYPE_SERVER As Long = &H2 Private Const SV_TYPE_SQLSERVER As Long = &H4 Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8 Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10 Private Const SV_TYPE_TIME_SOURCE As Long = &H20 Private Const SV_TYPE_AFP As Long = &H40 Private Const SV_TYPE_NOVELL As Long = &H80 Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100 Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200 Private Const SV_TYPE_DIALIN_SERVER As Long = &H400 Private Const SV_TYPE_XENIX_SERVER As Long = &H800 Private Const SV_TYPE_SERVER_UNIX As Long = SV_TYPE_XENIX_SERVER Private Const SV_TYPE_NT As Long = &H1000 Private Const SV_TYPE_WFW As Long = &H2000 Private Const SV_TYPE_SERVER_MFPN As Long = &H4000 Private Const SV_TYPE_SERVER_NT As Long = &H8000 Private Const SV_TYPE_POTENTIAL_BROWSER As Long = &H10000 Private Const SV_TYPE_BACKUP_BROWSER As Long = &H20000 Private Const SV_TYPE_MASTER_BROWSER As Long = &H40000 Private Const SV_TYPE_DOMAIN_MASTER As Long = &H80000 Private Const SV_TYPE_SERVER_OSF As Long = &H100000 Private Const SV_TYPE_SERVER_VMS As Long = &H200000 Private Const SV_TYPE_WINDOWS As Long = &H400000 'Windows95 + Private Const SV_TYPE_DFS As Long = &H800000 'Root of a DFS tree Private Const SV_TYPE_CLUSTER_NT As Long = &H1000000 'NT Cluster Private Const SV_TYPE_TERMINALSERVER As Long = &H2000000 'Terminal Server Private Const SV_TYPE_DCE As Long = &H10000000'IBM DSS Private Const SV_TYPE_ALTERNATE_XPORT As Long = &H20000000'return alternate transport Private Const SV_TYPE_LOCAL_LIST_ONLY As Long = &H40000000'return local only Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000 Private Const SV_TYPE_ALL As Long = &HFFFFFFFFPrivate Const SV_PLATFORM_ID_OS2 As Long = 400 Private Const SV_PLATFORM_ID_NT As Long = 500Private Const PLATFORM_ID_DOS As Long = 300 Private Const PLATFORM_ID_OS2 As Long = 400 Private Const PLATFORM_ID_NT As Long = 500 Private Const PLATFORM_ID_OSF As Long = 600 Private Const PLATFORM_ID_VMS As Long = 700'Mask applied to svX_version_major in 'order to obtain the major version number Private Const MAJOR_VERSION_MASK As Long = &HFPrivate Type SERVER_INFO_101 sv101_platform_id As Long sv101_name As Long sv101_version_major As Long sv101_version_minor As Long sv101_type As Long sv101_comment As Long End TypePrivate Declare Function NetServerEnum Lib "Netapi32" _ (ByVal servername As Long, _ ByVal level As Long, _ buf As Any, _ ByVal prefmaxlen As Long, _ entriesread As Long, _ totalentries As Long, _ ByVal servertype As Long, _ ByVal domain As Long, _ resume_handle As Long) As LongPrivate Declare Function NetApiBufferFree Lib "netapi32.dll" _ (ByVal Buffer As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (pTo As Any, uFrom As Any, _ ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" _ (ByVal lpString As Long) As LongPrivate Sub Form_Load() Command1.Caption = "Net Server Enum"
With Combo1 .AddItem "All servers" .ItemData(.NewIndex) = SV_TYPE_ALL
'os-specific .AddItem "NT/2000 workstations or servers" .ItemData(.NewIndex) = SV_TYPE_NT
.AddItem "Windows 95 or later" .ItemData(.NewIndex) = SV_TYPE_WINDOWS
.AddItem "Servers running Windows for Workgroups" .ItemData(.NewIndex) = SV_TYPE_WFW
.AddItem "NT/2000 servers not domain controller" .ItemData(.NewIndex) = SV_TYPE_SERVER_NT
.AddItem "Servers maintained by the browser" .ItemData(.NewIndex) = SV_TYPE_LOCAL_LIST_ONLY
.AddItem "Primary Domain (ignore version info)" .ItemData(.NewIndex) = SV_TYPE_DOMAIN_ENUM
.ListIndex = 0
End With
End SubPrivate Sub Combo1_Click() Call GetServers(vbNullString)
End Sub Private Sub Command1_Click() Call GetServers(vbNullString)End Sub Private Function GetServers(sDomain As String) As Long 'lists all servers of the specified type 'that are visible in a domain. Dim bufptr As Long Dim dwEntriesread As Long Dim dwTotalentries As Long Dim dwResumehandle As Long Dim dwServertype As Long Dim se101 As SERVER_INFO_101 Dim success As Long Dim nStructSize As Long Dim cnt As Long nStructSize = LenB(se101) dwServertype = Combo1.ItemData(Combo1.ListIndex)
List1.Clear
'Call passing MAX_PREFERRED_LENGTH to have the 'API allocate required memory for the return values. ' 'The call is enumerating all machines on the 'network (SV_TYPE_ALL); however, by Or'ing 'specific bit masks for defined types you can 'customize the returned data. For example, a 'value of 0x00000003 combines the bit masks for 'SV_TYPE_WORKSTATION (0x00000001) and 'SV_TYPE_SERVER (0x00000002). ' 'dwServerName must be Null. The level parameter '(101 here) specifies the data structure being 'used (in this case a SERVER_INFO_101 structure). ' 'The domain member is passed as Null, indicating 'machines on the primary domain are to be retrieved. 'If you decide to use this member, pass 'StrPtr("domain name"), not the string itself. success = NetServerEnum(0&, _ 101, _ bufptr, _ MAX_PREFERRED_LENGTH, _ dwEntriesread, _ dwTotalentries, _ dwServertype, _ 0&, _ dwResumehandle) 'if all goes well If success = NERR_SUCCESS And _ success <> ERROR_MORE_DATA Then
'loop through the returned data, adding each 'machine to the list For cnt = 0 To dwEntriesread - 1
'get one chunk of data and cast 'into an SERVER_INFO_101 struct 'in order to add the name to a list CopyMemory se101, ByVal bufptr + (nStructSize * cnt), nStructSize
'clean up, regardless of success Call NetApiBufferFree(bufptr)
GetServers = dwEntriesreadEnd Function Private Function GetPlatformString(ByVal dwPlatformID As Long) As String Select Case dwPlatformID Case PLATFORM_ID_DOS: GetPlatformString = "DOS" Case PLATFORM_ID_OS2: GetPlatformString = "Windows" Case PLATFORM_ID_NT: GetPlatformString = "Windows NT" Case PLATFORM_ID_OSF: GetPlatformString = "OSF" Case PLATFORM_ID_VMS: GetPlatformString = "VMS" End Select
End Function Private Function GetPointerToByteStringW(ByVal dwData As Long) As String
Dim tmp() As Byte Dim tmplen As Long
If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp(0 To (tmplen - 1)) As Byte CopyMemory tmp(0), ByVal dwData, tmplen GetPointerToByteStringW = tmp
End If
End If
End Function
你的第三个问题,可以用connection对象的state属性判断一个连接是否已经打开。If conn1.State = adOpen then 'conn1已经连接上 else 'conn1没有联接上 end if
b). Use WinAPI
Private Const RSP_SIMPLE_SERVICE = 1
Private Const RSP_UNREGISTER_SERVICE = 0Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate Sub HideApp(lbValue As Boolean)
Dim lProcessID As Long
Dim lReturn As Long
lProcessID = GetCurrentProcessId()
If lbValue Then
lReturn = RegisterServiceProcess(lProcessID, RSP_SIMPLE_SERVICE)
Else
lReturn = RegisterServiceProcess(lProcessID, RSP_UNREGISTER_SERVICE)
End If
End Sub
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0
'Option ExplicitPrivate Sub Command1_Click()
'下面代码为隐藏
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End SubPrivate Sub Command2_Click()
'恢复隐藏
Dim pid As Long
Dim reserv As Long
pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
End Sub
竟然请我的生意!!!
后两个问题呢?怎么没人会?
添加一个按钮(Command1),一个下拉组合框(Combo1)和一个列表框(List1)。把下面的代码复制到Form中 --------------------------------------------------------------------------------Option Explicit
'Windows type used to call the Net API
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long = SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT As Long = &H1000
Private Const SV_TYPE_WFW As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER As Long = &H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long = &H20000
Private Const SV_TYPE_MASTER_BROWSER As Long = &H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long = &H80000
Private Const SV_TYPE_SERVER_OSF As Long = &H100000
Private Const SV_TYPE_SERVER_VMS As Long = &H200000
Private Const SV_TYPE_WINDOWS As Long = &H400000 'Windows95 +
Private Const SV_TYPE_DFS As Long = &H800000 'Root of a DFS tree
Private Const SV_TYPE_CLUSTER_NT As Long = &H1000000 'NT Cluster
Private Const SV_TYPE_TERMINALSERVER As Long = &H2000000 'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000'IBM DSS
Private Const SV_TYPE_ALTERNATE_XPORT As Long = &H20000000'return alternate transport
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long = &H40000000'return local only
Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000
Private Const SV_TYPE_ALL As Long = &HFFFFFFFFPrivate Const SV_PLATFORM_ID_OS2 As Long = 400
Private Const SV_PLATFORM_ID_NT As Long = 500Private Const PLATFORM_ID_DOS As Long = 300
Private Const PLATFORM_ID_OS2 As Long = 400
Private Const PLATFORM_ID_NT As Long = 500
Private Const PLATFORM_ID_OSF As Long = 600
Private Const PLATFORM_ID_VMS As Long = 700'Mask applied to svX_version_major in
'order to obtain the major version number
Private Const MAJOR_VERSION_MASK As Long = &HFPrivate Type SERVER_INFO_101
sv101_platform_id As Long
sv101_name As Long
sv101_version_major As Long
sv101_version_minor As Long
sv101_type As Long
sv101_comment As Long
End TypePrivate Declare Function NetServerEnum Lib "Netapi32" _
(ByVal servername As Long, _
ByVal level As Long, _
buf As Any, _
ByVal prefmaxlen As Long, _
entriesread As Long, _
totalentries As Long, _
ByVal servertype As Long, _
ByVal domain As Long, _
resume_handle As Long) As LongPrivate Declare Function NetApiBufferFree Lib "netapi32.dll" _
(ByVal Buffer As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pTo As Any, uFrom As Any, _
ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As LongPrivate Sub Form_Load() Command1.Caption = "Net Server Enum"
With Combo1
.AddItem "All servers"
.ItemData(.NewIndex) = SV_TYPE_ALL
'os-specific
.AddItem "NT/2000 workstations or servers"
.ItemData(.NewIndex) = SV_TYPE_NT
.AddItem "Windows 95 or later"
.ItemData(.NewIndex) = SV_TYPE_WINDOWS
.AddItem "Servers running Windows for Workgroups"
.ItemData(.NewIndex) = SV_TYPE_WFW
.AddItem "Servers running Unix"
.ItemData(.NewIndex) = SV_TYPE_SERVER_UNIX
'function-specific
.AddItem "LAN Manager workstations"
.ItemData(.NewIndex) = SV_TYPE_WORKSTATION
.AddItem "LAN Manager servers"
.ItemData(.NewIndex) = SV_TYPE_SERVER
.AddItem "NT/2000 servers not domain controller"
.ItemData(.NewIndex) = SV_TYPE_SERVER_NT
.AddItem "Servers maintained by the browser"
.ItemData(.NewIndex) = SV_TYPE_LOCAL_LIST_ONLY
.AddItem "Primary Domain (ignore version info)"
.ItemData(.NewIndex) = SV_TYPE_DOMAIN_ENUM
.ListIndex = 0
End With
End SubPrivate Sub Combo1_Click() Call GetServers(vbNullString)
End Sub
Private Sub Command1_Click() Call GetServers(vbNullString)End Sub
Private Function GetServers(sDomain As String) As Long 'lists all servers of the specified type
'that are visible in a domain.
Dim bufptr As Long
Dim dwEntriesread As Long
Dim dwTotalentries As Long
Dim dwResumehandle As Long
Dim dwServertype As Long
Dim se101 As SERVER_INFO_101
Dim success As Long
Dim nStructSize As Long
Dim cnt As Long nStructSize = LenB(se101)
dwServertype = Combo1.ItemData(Combo1.ListIndex)
List1.Clear
'Call passing MAX_PREFERRED_LENGTH to have the
'API allocate required memory for the return values.
'
'The call is enumerating all machines on the
'network (SV_TYPE_ALL); however, by Or'ing
'specific bit masks for defined types you can
'customize the returned data. For example, a
'value of 0x00000003 combines the bit masks for
'SV_TYPE_WORKSTATION (0x00000001) and
'SV_TYPE_SERVER (0x00000002).
'
'dwServerName must be Null. The level parameter
'(101 here) specifies the data structure being
'used (in this case a SERVER_INFO_101 structure).
'
'The domain member is passed as Null, indicating
'machines on the primary domain are to be retrieved.
'If you decide to use this member, pass
'StrPtr("domain name"), not the string itself.
success = NetServerEnum(0&, _
101, _
bufptr, _
MAX_PREFERRED_LENGTH, _
dwEntriesread, _
dwTotalentries, _
dwServertype, _
0&, _
dwResumehandle) 'if all goes well
If success = NERR_SUCCESS And _
success <> ERROR_MORE_DATA Then
'loop through the returned data, adding each
'machine to the list
For cnt = 0 To dwEntriesread - 1
'get one chunk of data and cast
'into an SERVER_INFO_101 struct
'in order to add the name to a list
CopyMemory se101, ByVal bufptr + (nStructSize * cnt), nStructSize
List1.AddItem GetPointerToByteStringW(se101.sv101_name) & vbTab & _
GetPlatformString(se101.sv101_platform_id) & " " & _
(se101.sv101_version_major And MAJOR_VERSION_MASK) & "." & _
se101.sv101_version_minor
Next
End If
'clean up, regardless of success
Call NetApiBufferFree(bufptr)
GetServers = dwEntriesreadEnd Function
Private Function GetPlatformString(ByVal dwPlatformID As Long) As String Select Case dwPlatformID
Case PLATFORM_ID_DOS: GetPlatformString = "DOS"
Case PLATFORM_ID_OS2: GetPlatformString = "Windows"
Case PLATFORM_ID_NT: GetPlatformString = "Windows NT"
Case PLATFORM_ID_OSF: GetPlatformString = "OSF"
Case PLATFORM_ID_VMS: GetPlatformString = "VMS"
End Select
End Function
Private Function GetPointerToByteStringW(ByVal dwData As Long) As String
Dim tmp() As Byte
Dim tmplen As Long
If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp(0 To (tmplen - 1)) As Byte
CopyMemory tmp(0), ByVal dwData, tmplen
GetPointerToByteStringW = tmp
End If
End If
End Function
'conn1已经连接上
else
'conn1没有联接上
end if
能否留下EMAIL
你的第一个问题,我只知道win9X的,我用win me,没用过nt和2000!
对不起!
第二个问题好像还是不行,我不明,我照做好像又提示 :can't find DLL enty point netserverenum in netapi32.