我用vb来实现程序自动升级时,碰到下面的问题:局域网中有些机器不需要密码就能访问存放更新文件的服务器,但有的机器访问时会出现登录对话框(这种密码登录框出现过一次下次访问时就不出现)。用函数 filedatetime()来判断服务器上存放的文件修改时间时,不需要密码登录的机器就能成功,出现密码登录框的就不能成功。我用了 Shell ("net use \\server\update h:"" /u:Guest")试图来解决这个问题,但仍然不成功。请教大家问题出在哪?详细代码如下:
Private Const App_Name = "Storage"
Private Const ExePath = "\\Server\Update\"
Private Const MidExeName = "FastCopy"Private Sub ExeRefresh()
Dim s1, s2, s3, s4 As String
On Error Resume Next
Shell ("net use \\server\update h:"" /u:Guest")
s1 = "TNT"
If Len(App.Path) > 3 Then
s1 = App.Path + "\" + Trim(App_Name) + ".exe" 'S1 客户端程序文件
s3 = App.Path + "\" + MidExeName + ".exe" 'S3 客户端Fastcopy.EXE
Else
s1 = App.Path + Trim(App_Name) + ".exe"
s3 = App.Path + MidExeName + ".exe"
End If
s4 = "TNT"
s4 = FileDateTime(s1) 'S4 客户端程序文件修改时间
s2 = "TNT"
s2 = FileDateTime(ExePath + App_Name + ".exe") 'S2 服务器更新文件夹最新文件修改时间
If s2 = "TNT" Then
MsgBox ("无法获得服务器端程序版本信息,不能完成本次程序更新!") '该对话框在需要密码访问的机器上会出现
End If
If s2 = "TNT" Or s4 = "TNT" Then Exit Sub
If CDate(s2) > CDate(s4) Then
FileCopy ExePath + MidExeName + ".exe", s3
s1 = Shell(s3 + " " + ExePath + "," + App_Name + ".EXE", vbNormalFocus)
End
End If
Shell ("net use /delete")
End Sub
Private Const App_Name = "Storage"
Private Const ExePath = "\\Server\Update\"
Private Const MidExeName = "FastCopy"Private Sub ExeRefresh()
Dim s1, s2, s3, s4 As String
On Error Resume Next
Shell ("net use \\server\update h:"" /u:Guest")
s1 = "TNT"
If Len(App.Path) > 3 Then
s1 = App.Path + "\" + Trim(App_Name) + ".exe" 'S1 客户端程序文件
s3 = App.Path + "\" + MidExeName + ".exe" 'S3 客户端Fastcopy.EXE
Else
s1 = App.Path + Trim(App_Name) + ".exe"
s3 = App.Path + MidExeName + ".exe"
End If
s4 = "TNT"
s4 = FileDateTime(s1) 'S4 客户端程序文件修改时间
s2 = "TNT"
s2 = FileDateTime(ExePath + App_Name + ".exe") 'S2 服务器更新文件夹最新文件修改时间
If s2 = "TNT" Then
MsgBox ("无法获得服务器端程序版本信息,不能完成本次程序更新!") '该对话框在需要密码访问的机器上会出现
End If
If s2 = "TNT" Or s4 = "TNT" Then Exit Sub
If CDate(s2) > CDate(s4) Then
FileCopy ExePath + MidExeName + ".exe", s3
s1 = Shell(s3 + " " + ExePath + "," + App_Name + ".EXE", vbNormalFocus)
End
End If
Shell ("net use /delete")
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货