微软的vb里带的例子,shelllink读取快捷方式是中文名的时候老是读取不了。不是所有中文名的快捷方式都这样。很晕。哪位高手帮忙看看,到底怎么回事情。比如你随便弄个程序创建一个快捷方式,名字叫“梦幻西游.lnk”,那就读取不了快捷方式里的信息了。微软例子里读取信息的类模块:
Public Enum STGM
STGM_DIRECT = &H0&
STGM_TRANSACTED = &H10000
STGM_SIMPLE = &H8000000
STGM_READ = &H0&
STGM_WRITE = &H1&
STGM_READWRITE = &H2&
STGM_SHARE_DENY_NONE = &H40&
STGM_SHARE_DENY_READ = &H30&
STGM_SHARE_DENY_WRITE = &H20&
STGM_SHARE_EXCLUSIVE = &H10&
STGM_PRIORITY = &H40000
STGM_DELETEONRELEASE = &H4000000
STGM_CREATE = &H1000&
STGM_CONVERT = &H20000
STGM_FAILIFTHERE = &H0&
STGM_NOSCRATCH = &H100000
End EnumPublic Function GetShellLinkInfo(LnkFile As String, ExeFile As String, WorkDir As String, _
ExeArgs As String, IconFile As String, IconIdx As Long, _
ShowCmd As Long) As Long
'---------------------------------------------------------------
Dim pidl As Long ' Item id list
Dim wHotKey As Long ' Hotkey to shortcut...
Dim fd As WIN32_FIND_DATA
Dim Description As String
Dim buffLen As Long
Dim cShellLink As ShellLinkA ' An explorer IShellLink instance
Dim cPersistFile As IPersistFile ' An explorer IPersistFile instance
'---------------------------------------------------------------
If (LnkFile = "") Then Exit Function ' Validate min. input requirements.
Set cShellLink = New ShellLinkA ' Create new IShellLink interface
Set cPersistFile = cShellLink ' Implement cShellLink's IPersistFile interface
' Load Shortcut file...(must do this UNICODE hack!)
'On Error GoTo ErrHandler
cPersistFile.Load StrConv(LnkFile, vbUnicode), STGM_DIRECT
With cShellLink
' Get command line exe name & path of shortcut
ExeFile = Space(MAX_PATH)
buffLen = Len(ExeFile)
.GetPath ExeFile, buffLen, fd, SLGP_UNCPRIORITY
Dim s As String
s = fd.cFileName ' Not returned to calling function
' Get working directory of shortcut
WorkDir = Space(MAX_PATH)
buffLen = Len(WorkDir)
.GetWorkingDirectory WorkDir, buffLen
' Get command line arguments of shortcut
ExeArgs = Space(MAX_PATH)
buffLen = Len(ExeArgs)
.GetArguments ExeArgs, buffLen
' Get description of shortcut
Description = Space(MAX_PATH)
buffLen = Len(Description)
.GetDescription Description, buffLen ' Not returned to calling function
' Get the HotKey for shortcut
.GetHotkey wHotKey ' Not returned to calling function
' Get shortcut icon location & index
IconFile = Space(MAX_PATH)
buffLen = Len(IconFile)
.GetIconLocation IconFile, buffLen, IconIdx
' Get Item ID List...
.GetIDList pidl ' Not returned to calling function
' Set shortcut's startup mode (min,max,normal)
.GetShowCmd ShowCmd
End With GetShellLinkInfo = True ' Return Success
'---------------------------------------------------------------
ErrHandler:
'---------------------------------------------------------------
Set cPersistFile = Nothing ' Destroy Object
Set cShellLink = Nothing ' Destroy Object
'---------------------------------------------------------------
End Function
'----------------//////////////////////////////
cPersistFile.Load StrConv(LnkFile, vbUnicode), STGM_DIRECT
这一句遇到某些中文名就出错!!!
Public Enum STGM
STGM_DIRECT = &H0&
STGM_TRANSACTED = &H10000
STGM_SIMPLE = &H8000000
STGM_READ = &H0&
STGM_WRITE = &H1&
STGM_READWRITE = &H2&
STGM_SHARE_DENY_NONE = &H40&
STGM_SHARE_DENY_READ = &H30&
STGM_SHARE_DENY_WRITE = &H20&
STGM_SHARE_EXCLUSIVE = &H10&
STGM_PRIORITY = &H40000
STGM_DELETEONRELEASE = &H4000000
STGM_CREATE = &H1000&
STGM_CONVERT = &H20000
STGM_FAILIFTHERE = &H0&
STGM_NOSCRATCH = &H100000
End EnumPublic Function GetShellLinkInfo(LnkFile As String, ExeFile As String, WorkDir As String, _
ExeArgs As String, IconFile As String, IconIdx As Long, _
ShowCmd As Long) As Long
'---------------------------------------------------------------
Dim pidl As Long ' Item id list
Dim wHotKey As Long ' Hotkey to shortcut...
Dim fd As WIN32_FIND_DATA
Dim Description As String
Dim buffLen As Long
Dim cShellLink As ShellLinkA ' An explorer IShellLink instance
Dim cPersistFile As IPersistFile ' An explorer IPersistFile instance
'---------------------------------------------------------------
If (LnkFile = "") Then Exit Function ' Validate min. input requirements.
Set cShellLink = New ShellLinkA ' Create new IShellLink interface
Set cPersistFile = cShellLink ' Implement cShellLink's IPersistFile interface
' Load Shortcut file...(must do this UNICODE hack!)
'On Error GoTo ErrHandler
cPersistFile.Load StrConv(LnkFile, vbUnicode), STGM_DIRECT
With cShellLink
' Get command line exe name & path of shortcut
ExeFile = Space(MAX_PATH)
buffLen = Len(ExeFile)
.GetPath ExeFile, buffLen, fd, SLGP_UNCPRIORITY
Dim s As String
s = fd.cFileName ' Not returned to calling function
' Get working directory of shortcut
WorkDir = Space(MAX_PATH)
buffLen = Len(WorkDir)
.GetWorkingDirectory WorkDir, buffLen
' Get command line arguments of shortcut
ExeArgs = Space(MAX_PATH)
buffLen = Len(ExeArgs)
.GetArguments ExeArgs, buffLen
' Get description of shortcut
Description = Space(MAX_PATH)
buffLen = Len(Description)
.GetDescription Description, buffLen ' Not returned to calling function
' Get the HotKey for shortcut
.GetHotkey wHotKey ' Not returned to calling function
' Get shortcut icon location & index
IconFile = Space(MAX_PATH)
buffLen = Len(IconFile)
.GetIconLocation IconFile, buffLen, IconIdx
' Get Item ID List...
.GetIDList pidl ' Not returned to calling function
' Set shortcut's startup mode (min,max,normal)
.GetShowCmd ShowCmd
End With GetShellLinkInfo = True ' Return Success
'---------------------------------------------------------------
ErrHandler:
'---------------------------------------------------------------
Set cPersistFile = Nothing ' Destroy Object
Set cShellLink = Nothing ' Destroy Object
'---------------------------------------------------------------
End Function
'----------------//////////////////////////////
cPersistFile.Load StrConv(LnkFile, vbUnicode), STGM_DIRECT
这一句遇到某些中文名就出错!!!
解决方案 »
- VB6.0中调用SQL server2000中的存储过程
- 这个代码怎么把它输入到TXT中
- MSHFlexGrid1问题,“上一页”无效,如何写这个呢?
- 数据更新出现问题
- 字段名模糊查询
- VB里有什么函数能返回当前文件目录,不是My Document的。
- 大虾们注意:
- 有一个字段‘职称’,值为:初级,中级,高级,怎么样在查找时使记录按职称的升序(初、中、高)或降序(高、中、初)排列??(解决完马
- 水晶的打印纸张大小能自动变化吗?我的客户使用了各种各样的打印机型号。
- 请问,我现在有两个日期变量,我想得出一个datetime是第一个日期的date,第二个日期的time?
- 求一取得汉字拼音缩写的函数!
- 祝自己好运,也祝VB版的兄弟好运.
Shell GetTargetPath("C:\Documents and Settings\MyUserName\桌面\RealOne.lnk")
End SubFunction GetTargetPath(ByVal FileName As String)
Dim Obj As Object
Dim Shortcut As Object
Set Obj = CreateObject("WScript.Shell")
Set Shortcut = Obj.CreateShortcut(FileName)
GetTargetPath = Shortcut.TargetPath
Shortcut.Save
End Function
全部都改