ShellExecute VB声明 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 说明 查找与指定文件关联在一起的程序的文件名 返回值 Long,非零表示成功,零表示失败。会设置GetLastError 参数表 参数 类型及说明 hwnd Long,指定一个窗口的句柄,有时候,windows程序有必要在创建自己的主窗口前显示一个消息框 lpOperation String,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它 lpFile String,想用关联程序打印或打开一个程序名或文件名 lpParameters String,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数 lpDirectory String,想使用的完整路径 nShowCmd Long,定义了如何显示启动程序的常数值。参考ShowWindow函数的nCmdShow参数
Option Explicit 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 LongPrivate Sub Form_Load() ShellExecute Me.hwnd, "open", "e:\example.vbp", vbNullString, vbNullString, 0 End Sub
关于 用VB制作光盘自动运行程序: 光盘根目录得有两个文件。 autorun.inf (设置自动运行run.exe) run.exe (你编的程序) Option ExplicitPrivate Sub Form_Load() Drive1.Drive = Left(App.Path, 3) Dir1.Path = App.Path File1.Path = App.Path End Sub
谢谢你的解答,那怎么打开指定的文件夹呢,比如的d:\music
Option ExplicitPrivate Sub Command1_Click() Shell "explorer c:\windows", vbNormalFocus End Sub
还有一个问题啊,就是下面的语句,点击完就是不见fotocanvs2.exe 启动 Private Sub FotoCanvas_Click() Dim Fotocanvs As Variant Fotocanvs = Shell("C:\Program Files\ACD Systems\FotoCanvas\2.0\FotoCanvas2.exe", 1) End Sub我换了其他程序,比如 d:\download\setup.exe 就可以运行那个安装文件,当然,用卢培培的提供的这个语句,修改一下也是可以运行的但是我写的那个是因为路径中有空格的原因么,如果是又如何解决呢?
对了,顺便问一下怎么样用指定的程序打开指定的文件比如想用vb打开一个vbq文件,其中vb程序以及vbq文件所在目录如下C:\Program Files\Microsoft VB\VB98\VB6.EXE
E:\example.vbq
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
说明
查找与指定文件关联在一起的程序的文件名
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hwnd Long,指定一个窗口的句柄,有时候,windows程序有必要在创建自己的主窗口前显示一个消息框
lpOperation String,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它
lpFile String,想用关联程序打印或打开一个程序名或文件名
lpParameters String,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数
lpDirectory String,想使用的完整路径
nShowCmd Long,定义了如何显示启动程序的常数值。参考ShowWindow函数的nCmdShow参数
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 LongPrivate Sub Form_Load()
ShellExecute Me.hwnd, "open", "e:\example.vbp", vbNullString, vbNullString, 0
End Sub
光盘根目录得有两个文件。
autorun.inf (设置自动运行run.exe)
run.exe (你编的程序)
Option ExplicitPrivate Sub Form_Load()
Drive1.Drive = Left(App.Path, 3)
Dir1.Path = App.Path
File1.Path = App.Path
End Sub
Shell "explorer c:\windows", vbNormalFocus
End Sub
我真晕死~~~
哪里都有你,哪里都是你~
你就像一个救火队员,哪里有火~~~
哪里就有你的存在
升星星对你当然小事一桩~好像就是吵架的地方没有你~
今天看了一篇帖子,非常气人,等我回复的时候,已经被删除了。(这里好象没有)在我看的帖子里好象就那儿没有你~
这不算什么,当年的我(2002)也是非吵架贴必进的,以前每月一万分
可是由于 高考、电脑坏了、刚读大一,现在没机会上网
明天就得去宿舍了,可能要有一段时间不能上CSDN了。 :(
//今天看了一篇帖子,非常气人,等我回复的时候,已经被删除了。
这篇贴子我看了,打心眼里支持楼主,因为我本人就是职高毕业的,但参加高职考试直接考上了本科(虽然不是什么好学校),大家说的都很有道理啊,我还没毕业,当然没有那样的体会,所以就没回贴。 :)
Private Sub FotoCanvas_Click()
Dim Fotocanvs As Variant
Fotocanvs = Shell("C:\Program Files\ACD Systems\FotoCanvas\2.0\FotoCanvas2.exe", 1)
End Sub我换了其他程序,比如 d:\download\setup.exe 就可以运行那个安装文件,当然,用卢培培的提供的这个语句,修改一下也是可以运行的但是我写的那个是因为路径中有空格的原因么,如果是又如何解决呢?
Shell "explorer c:\windows", vbNormalFocus
这里的c:\windows,可不可以是一个相对路径?
解决空格问题
可以