微软的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
这一句遇到某些中文名就出错!!!

解决方案 »

  1.   

    自己顶一下。是因为转换vbUnicode才出错的吗?
      

  2.   

    Option ExplicitPrivate Sub Command1_Click()
        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
      

  3.   

    谢谢高手指点,这种方法我用过没有问题。但是我这边电脑上的FSO WSH全部被禁用了。所以你的方法用不了。微软的那个是用API搞的,不怕WSH被禁用。
      

  4.   

    再顶一下,有不通过WSH那些来解决的方法吗?微软的例子怎么也有问题,晕呀。
      

  5.   

    应该是长度问题.你将你的程序用到len的改为这样:比如你有buffLen = Len(Description),就改为这样:buffLen = LenB(StrConv(Description, vbFromUnicode))
    全部都改
      

  6.   

    还到不了长度那里,在cPersistFile.Load StrConv(LnkFile, vbUnicode), STGM_DIRECT这里就直接出错了。