VBScript发送到文件AND文件夹的链接



在Windows 7中,我有一个VBScript,当你在Windows资源管理器中右键单击时,它会在Outlook中创建一封带有文件链接的电子邮件。该脚本的运行方式是创建一个快捷方式,并将其添加到%userprofile%\SendTo(右键单击文件时会显示在"发送到"中(。目标是能够发送指向文件和包含该文件的文件夹的链接,而不是将其作为附件发送。它工作得很好,只是它总是直接提供一个指向文件的链接。如何修改它,使其在第二行中也提供指向文件夹的链接?

Const olMailItem = 0
Const olFolderInbox = 6
If WScript.Arguments.Count = 0 Then
WScript.Quit
End If
Set objWMIService = GetObject("winmgmts:\.rootcimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Process Where Name = 'outlook.exe'")
If colItems.Count = 0 Then
    Set objOutlook = CreateObject("Outlook.Application")
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
objFolder.Display
End If
strFile = WScript.Arguments.Item(0)
Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.CreateItem(olMailItem)
objItem.Subject = "Here is a link to a file..."
objItem.HTMLBody = "Link to the file: <A HREF=" & Chr(34) & "file://" & strFile & Chr(34) & ">" & strFile & "</A><BR>Link to the folder: <A HREF=" & Chr(34) & "file://" & strFile & Chr(34) & ">" & strFile & "</A>"
objItem.Display

这可能是一个简单的答案,但我一直想不通。任何帮助都将不胜感激!

FileSystemObject对象及其GetParentFolderName方法可能会有所帮助。请注意,对于(在下一个脚本中(使用的任何方法,hold:方法只适用于提供的路径字符串。它不会尝试解析路径,也不会检查指定路径的存在。

option explicit
Dim strFile, FSO, oFile
If WScript.Arguments.Count > 0 Then
  strFile = WScript.Arguments.Item(0)
Else
  strFile = "D:RemotebatCOCLbu bu busomefile.ext"
End If
Set FSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo "FSO 'path' methods" & vbNewLine & "---------------------" _
   & vbNewLine & "GetAbsolutePathName: " & FSO.GetAbsolutePathName( strFile) _
   & vbNewLine & "GetParentFolderName: " & FSO.GetParentFolderName( strFile) _
   & vbNewLine & "GetDriveName: " & FSO.GetDriveName( strFile) _
   & vbNewLine & "GetBaseName: " & FSO.GetBaseName( strFile) _
   & vbNewLine & "GetExtensionName: " & FSO.GetExtensionName( strFile) _
   & vbNewLine & "GetFileName: " & FSO.GetFileName( strFile)
Set FSO = Nothing
Wscript.Quit

最新更新