VB6.0软件在调试时正常,生成EXE文件就不能运行了

jageme 2009-06-21 01:29:12
我最近做了一个网络切换软件,在VB6.0里在调试时正常,生成EXE文件就不能运行了
请大家帮我看看是什么原因


Option Explicit
Private Function ExcNetLinkMenu(ByVal AdapterName As String, ByVal MenuName As String) As Boolean
On Error Resume Next
Dim mShell As New Shell32.Shell
Dim NetConnection As Shell32.Folder
Dim FolderItem As Shell32.FolderItem
Dim NetConnectionItem As ShellFolderItem
Dim verb As Shell32.FolderItemVerb
Set NetConnection = mShell.NameSpace(49)
If ObjPtr(NetConnection) = 0 Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
Dim flag As Boolean
flag = False
For Each FolderItem In NetConnection.Items
If FolderItem.Name = AdapterName Then
Set NetConnectionItem = FolderItem
flag = True
Exit For
End If
Next
If flag = False Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
For Each verb In NetConnectionItem.Verbs
If verb.Name = MenuName Then
flag = True
verb.DoIt
ExcNetLinkMenu = True
GoTo exitfunction
End If
Next
If flag = False Then
ExcNetLinkMenu = False
GoTo exitfunction
End If
exitfunction:
Set mShell = Nothing
Set NetConnection = Nothing
Set FolderItem = Nothing
Set NetConnectionItem = Nothing
Set verb = Nothing
End Function



Private Sub Command1_Click()
Dim flag As Boolean
flag = ExcNetLinkMenu("外网", "启用(&A)")
flag = ExcNetLinkMenu("内网", "停用(&B)")
Unload Form1
End Sub

Private Sub Command2_Click()
Dim flag As Boolean

flag = ExcNetLinkMenu("内网", "启用(&A)")
flag = ExcNetLinkMenu("外网", "停用(&B)")
Unload Form1
End Sub

Private Sub Form_Load()
If ExcNetLinkMenu("外网", "停用(&B)") = True Then
Label1.Caption = "当前网络处于外网中"
Image3.Picture = LoadPicture(App.Path & "\img\1.gif")
Command1.Visible = False
Command2.Visible = True
Else
If ExcNetLinkMenu("内网", "停用(&B)") = True Then
Label1.Caption = "当前网络处于内网中"
Image3.Picture = LoadPicture(App.Path & "\img\2.gif")
Command1.Visible = True
Command2.Visible = False
End If
End If
End Sub

Private Sub Label2_Click()
Unload Form1
End Sub

...全文
416 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jageme 2009-06-22
  • 打赏
  • 举报
回复
这个EXE在本机就不能运行,
浅蓝马 2009-06-22
  • 打赏
  • 举报
回复
代码看得发晕,出什么样的错误请详细说明一下。
另外,我不同意楼上所说的带Shell32.dll部署的说法,
这个DLL在windows系统中是包括的。
神马都能聊 2009-06-22
  • 打赏
  • 举报
回复
要求变量声明了吗?如果代码准确无误,那么可能下面这些有VB环境用到的东西

Dim mShell As New Shell32.Shell
Dim NetConnection As Shell32.Folder
Dim FolderItem As Shell32.FolderItem
Dim NetConnectionItem As ShellFolderItem
Dim verb As Shell32.FolderItemVerb

datou985 2009-06-21
  • 打赏
  • 举报
回复
你的EXE在本机就不能运行?
还是拿到别的机器上不能运行的?
因为你的代码里面用到了Shell32.dll
因此若安装到别的机器上,最好带着该DLL一起部署

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧