' 以下代码在窗体中,请在窗体中加入一个 CommandButton (Command1) Option ExplicitPrivate Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As LongPrivate Const KEY_ALL_ACCESS = &HF003F 'Permission for all types of access. Private Const KEY_QUERY_VALUE = &H1 'Permission to query subkey data. Private Const HKEY_LOCAL_MACHINE = &H80000002 Private Const REG_SZ = 1 'A string terminated by a null character. Private Const REG_EXPAND_SZ = 2 'A null-terminated string which contains unexpanded environment variables.' 启动 Photoshop 并打开传入的图像文件 Public Sub StartPhotoshop(Optional ByVal ImageFile As String)
Const RegKey_PS As String = "Software\Microsoft\Windows\CurrentVersion\App Paths\Photoshop.exe"
Dim sFile As String
If RegKeyExists(HKEY_LOCAL_MACHINE, RegKey_PS) Then
End SubPrivate Function RegKeyExists(ByVal Key As Long, ByVal SubKey As String) As Boolean
Dim hKey As Long
If RegOpenKeyEx(Key, SubKey, 0, KEY_QUERY_VALUE, hKey) = 0 Then RegKeyExists = True RegCloseKey hKey End If
End FunctionPrivate Function ReadRegString(ByVal Key As Long, ByVal SubKey As String, ByVal ValueName As String, Optional ByVal Default As String) As String
Dim hKey As Long Dim lLen As Long Dim lType As Long Dim sTmp As String
ReadRegString = Default
If RegOpenKeyEx(Key, SubKey, 0, KEY_ALL_ACCESS, hKey) = 0 Then
If RegQueryValueEx(hKey, ValueName, 0, lType, ByVal 0&, lLen) = 0 Then
If lType = REG_SZ Or lType = REG_EXPAND_SZ Then
sTmp = Space(lLen)
If RegQueryValueEx(hKey, ValueName, 0, lType, ByVal sTmp, lLen) = 0 Then ReadRegString = Left(sTmp, lLen - 1) End If
[HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Photoshop\8.0]
"ApplicationPath"="C:\\Program Files\\Adobe\\Photoshop CS\\"
而启动文件是Photoshop.exe,这样就可以找到,并启动它了。
Dim str As String
str = Registry.ReadString(RegKey_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\photoshop.exe", vbNullString)
Shell str & " c:\test.bmp"
End Sub我这没有photoshop,注册表的键值是随便写的。
给我留个Email,我明天发给你。
Option ExplicitPrivate Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As LongPrivate Const KEY_ALL_ACCESS = &HF003F 'Permission for all types of access.
Private Const KEY_QUERY_VALUE = &H1 'Permission to query subkey data.
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1 'A string terminated by a null character.
Private Const REG_EXPAND_SZ = 2 'A null-terminated string which contains unexpanded environment variables.' 启动 Photoshop 并打开传入的图像文件
Public Sub StartPhotoshop(Optional ByVal ImageFile As String)
Const RegKey_PS As String = "Software\Microsoft\Windows\CurrentVersion\App Paths\Photoshop.exe"
Dim sFile As String
If RegKeyExists(HKEY_LOCAL_MACHINE, RegKey_PS) Then
sFile = ReadRegString(HKEY_LOCAL_MACHINE, RegKey_PS, vbNullString)
If Len(sFile) > 0 Then
If Len(ImageFile) > 0 Then
ImageFile = """" & ImageFile & """"
End If
Shell sFile & " " & ImageFile, vbNormalFocus
End If
Else
MsgBox "没有安装 Photoshop ", vbInformation, App.Title
End If
End SubPrivate Function RegKeyExists(ByVal Key As Long, ByVal SubKey As String) As Boolean
Dim hKey As Long
If RegOpenKeyEx(Key, SubKey, 0, KEY_QUERY_VALUE, hKey) = 0 Then
RegKeyExists = True
RegCloseKey hKey
End If
End FunctionPrivate Function ReadRegString(ByVal Key As Long, ByVal SubKey As String, ByVal ValueName As String, Optional ByVal Default As String) As String
Dim hKey As Long
Dim lLen As Long
Dim lType As Long
Dim sTmp As String
ReadRegString = Default
If RegOpenKeyEx(Key, SubKey, 0, KEY_ALL_ACCESS, hKey) = 0 Then
If RegQueryValueEx(hKey, ValueName, 0, lType, ByVal 0&, lLen) = 0 Then
If lType = REG_SZ Or lType = REG_EXPAND_SZ Then
sTmp = Space(lLen)
If RegQueryValueEx(hKey, ValueName, 0, lType, ByVal sTmp, lLen) = 0 Then
ReadRegString = Left(sTmp, lLen - 1)
End If
End If
End If
RegCloseKey hKey
End If
End Function' 测试
Private Sub Command1_Click()
StartPhotoshop "C:\WINDOWS\Web\Wallpaper\peace.jpg"
End Sub