当前位置:编程学习 > VB >>

VB中如何打开电脑中任意一个应用程序

怎么在VB中实现打开电脑中安装的任意一个应用程序,要求在所有机子上都可以实现(类似于某些游戏辅助程序中点击按钮就可以启动该游戏)。
用shell函数能否实现?是否需要搜索应用程序的安装路径?
请高手指点下,最好有详细注释,以供学习,谢谢!
追问:shell"b.exe" 中b.exe需要安装路径吗
答案:
Private Sub Command1_Click()
Dim i As Integer
Dim buf As String
CommonDialog1.Filter = "可执行文件(*.exe)|*.exe|所有文件(*.*)|*.*"
CommonDialog1.Flags = cdlOFNOverwritePrompt
CommonDialog1.ShowOpen
If CommonDialog1.CancelError Then Exit Sub
If CommonDialog1.FileName = "" Then Exit Sub
Label1.Caption = CommonDialog1.FileName
Shell Label1.Caption, vbNormalFocus
End Sub
Private Sub Command1_Click() Dim i As IntegerDim buf As StringCommonDialog1.Filter = "可执行文件(*.exe)|*.exe|所有文件(*.*)|*.*"CommonDialog1.Flags = cdlOFNOverwritePromptCommonDialog1.ShowOpenIf CommonDialog1.CancelError Then Exit SubIf CommonDialog1.FileName = "" Then Exit SubLabel1.Caption = CommonDialog1.FileNameShell Label1.Caption, vbNormalFocusEnd Sub
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()
CommonDialog1.Filter = "可执行文件(*.exe)|*.exe|所有文件(*.*)|*.*"
CommonDialog1.Flags = cdlOFNOverwritePrompt
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
Text1.Text = CommonDialog1.FileName
End Sub

Private Sub Command2_Click()

ShellExecute Me.hwnd, "open", Text1.Text, "", "", SW_SHOW
End Sub
这样就可以Private Sub Command1_Click()Shell "b.exe"End Sub给你个连接,学习下吧,呵呵 http://www.xuevb.net/modules/news/article.php?storyid=781Private Sub Form_Click() Shell "c:\windows\system32\calc.exe", vbNormalFocus '打开计算器程序逻(写上完整的路径) Shell "explorer http://www.zhaoxi.net", vbNormalFocus '打开百度首页 Shell "cmd /c dir > c:\a.txt", vbNormalFocus '执行一个DOS命令 并把显示结果存到 c盘a.txt文件中End Sub
"爱的海洋"~~下面的两个Shell你都知道在Path变量中的路径可以用相对路径~第一个Shell咋用了绝对路径呢?举个IEXPLORE的例子嘛
楼上的只会用shell函数,我提议用API函数,功能更强大。可以打开图片、歌曲、声音、程序等等。
具体用 ShellExecute 函数
楼上的可能都理解错了意思,楼主指的是安装的程式,这个可以用API枚举安装了的程式,这样就可以打开了。如果是绿色版的用这种方式就找不出咯。
ShellExecute实现的话是可以打开你那个机器可以打开的程序或文件的 如果没有就会弹出一个 找打开方式的 对话框

上一个:计算机编程c与vb
下一个:怎么样在大学里学好 VB C++ 离散数学

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,