我的电脑IP是192.168.0.92,我想连接到192.168.0.1,并且要得到192.168.0.1的时间。应该怎么做才是最简单的??
用VB实现此操作!!!如何完成???????
VB有关连接服务器的问题!
答案:3 悬赏:10 手机版
解决时间 2021-01-27 12:15
- 提问者网友:美人性情
- 2021-01-27 05:34
最佳答案
- 五星知识达人网友:撞了怀
- 2021-01-27 06:59
192.168.0.1设为域服务器,192.168.0.92加入该域。
全部回答
- 1楼网友:零点过十分
- 2021-01-27 09:30
'获取远程服务器当前时间的函数
Option Explicit
Private Declare Function NetRemoteTOD Lib "Netapi32.dll" (tServer As Any, pBuffer As Long) As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Private Declare Function GetTimeZoneInformation Lib "kernel32" ( _
lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long
Private Type TIME_OF_DAY_INFO
tod_elapsedt As Long
tod_msecs As Long
tod_hours As Long
tod_mins As Long
tod_secs As Long
tod_hunds As Long
tod_timezone As Long
tod_tinterval As Long
tod_day As Long
tod_month As Long
tod_year As Long
tod_weekday As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, Source As Any, ByVal Length As Long)
Public Function getRemoteTOD(ByVal strServer As String) As Date
Dim result As Date
Dim lRet As Long
Dim tod As TIME_OF_DAY_INFO
Dim lpbuff As Long
Dim tServer() As Byte
tServer = strServer & vbNullChar
lRet = NetRemoteTOD(tServer(0), lpbuff)
If lRet = 0 Then
CopyMemory tod, ByVal lpbuff, Len(tod)
NetApiBufferFree lpbuff
result = DateSerial(tod.tod_year, tod.tod_month, tod.tod_day) + _
TimeSerial(tod.tod_hours, tod.tod_mins - tod.tod_timezone, tod.tod_secs)
getRemoteTOD = result
Else
Err.Raise Number:=vbObjectError + 1001, _
Description:="cannot get remote TOD"
End If
End Function
Private Sub Command1_Click()
Dim d As Date
d = getRemoteTOD("E08-065")
MsgBox d
End Sub
- 2楼网友:洎扰庸人
- 2021-01-27 07:55
你这个地址是你局域网内的地址.外面的人是连接不上的.我给你一个连接数据库的函数.你传递对应的参数就可以了.vb6中连接数据库的方式是通过ado来实现的.ado传递的是com+的组件.需要关闭服务器的防火墙否则是连接不上的.
'******************************************************************************************
'
'功能说明
' 连接数据库
'参数说明
' condbx 必要参数,连接数据库的连接对象
' dbname 必须参数,数据库名称,当连接数据库为access时,该名称应该包括其数据库的完整路径
' mlogin 连接sql server 2000数据库的登陆名称
' mpassword 连接sql server 2000数据库的登陆密码
' dbtype 连接数据的类型,为access 或 sqlserver其他均为错误值
'返回值:true表示连接成功
' false表示连接失败
'
'******************************************************************************************
public function connectdatabase(condbx as adodb.connection, dbname as string, optional mlogin as string = "sa", optional mpassword as string = "", optional dbtype as string = "access", optional dbserver as string = ".") as boolean
dim str as string
on error resume next
with condbx
if lcase(dbtype) = "sqlserver" then '连接sql server 2000数据库
.connectionstring = "provider=sqloledb.1;password=" & trim(mpassword) & ";persist security info=true;user id=" & trim(mlogin) & ";initial catalog=" & dbname & ";data source=" & dbserver
elseif lcase(dbtype) = "access" then '连接access数据库
' .connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" & app.path & "\cha.mdb" & ";persist security info=false"
.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" & dbname & ";persist security info=false"
end if
.commandtimeout = 5000 '设置连接时间
.open '连接
end with
if err.number <> 0 then '当连接数据库失败的时候
msgbox "数据库联接失败!错误原因 :" & vbcrlf & err.description, vbcritical + vbokonly, "错误"
connectdatabase = false
else
connectdatabase = true
end if
end function
这个函数是我自己最早的一个项目中的现成代码.可以直接通过参数连数据库.你可以吧这个复制过去.
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯