好吧,我通过在资源管理器右键菜单将自身注册修改的VBS脚本和允许你右键点击一个文件来复制它对应的服务器URL到剪贴板。
'####################################################################
' If you sync files between your local PC and a web server you can use this
' script to right-click on one of those files to copy the corresponding server
' URL to your clipboard
'####################################################################
Option Explicit
'Local path to the directory that is being synchronised with the server
Const constRootWinPath = "C:\SyncedFiles"
'path to corresponding directory on the server
Const constRootServerPath = "/SyncedFiles/"
'Domain name of the server
Const constServerDomain = "http://mydomain.dom/"
'MAKE SURE TO INCLUDE LEADING AND TRAILING SLASHES ON ALL PATHS!!!!!
Dim objIE
' Parse the command line arguments
If WScript.Arguments.Count <> 1 Then Syntax
If WScript.Arguments.Named.Count = 1 Then
If WScript.Arguments.Named.Exists("Register") Then
Register
ElseIf WScript.Arguments.Named.Exists("Unregister") Then
UnRegister
Else
Syntax
End If
End If
' Check arguments. Text argument gets processed as a path.
If WScript.Arguments.UnNamed.Count = 1 Then
Dim strArgument
strArgument = WScript.Arguments.Unnamed(0)
'The file has to exist within a directory under constRootWinPath so that we know how to process the path
If instr(trim(strArgument),trim(constRootWinPath)) > 0 Then
'WScript.Echo """" & constRootWinPath & """ was found in """ & strArgument & """"
SendToClipboard(ProcessLocalPathToServerPath(WScript.Arguments.Unnamed(0)))
Else
WScript.Echo """" & constRootWinPath & """ not found in """ & strArgument & """. Please make sure to edit the Const in the VBS file"
End If
End If
Function ProcessLocalPathToServerPath(strLocalPath)
Dim strProcessedPath, strFileName, strRelPathToRoot, strFileExtension
'Get the filename
strFileName = right(strLocalPath,len(strLocalPath)-InStrRev(strLocalPath,"\"))
'WScript.Echo "strFileName: """ & strFileName & """"
'Get the relative path to the root
strRelPathToRoot = mid(strLocalPath,len(constRootWinPath),len(strLocalPath)-(len(constRootWinPath)+len(strFileName))+1) '+1 to get the trailing slash
'Swap back slash for forward slash
strRelPathToRoot = replace(strRelPathToRoot,"\","/")
'WScript.Echo "strRelPathToRoot: """ & strRelPathToRoot & """"
'Get the file extension
strFileExtension = right(strFileName,len(strFileName)-InStrRev(strFileName,"."))
'WScript.Echo "strFileExtension: """ & strFileExtension & """"
'Process the paths depending on file type
Select Case strFileExtension
'send swf files to our wrapper viewer on the server
Case "swf"
strProcessedPath = constServerDomain & "flashviewer.asp?swf=" & constRootServerPath & strRelPathToRoot & strFileName
'Use google viewer for supported file types
Case "docx","doc","xls","xlsx","ppt","pptx","pdf","pages","ai","psd","tiff","dxf","svg","eps","ps","ttf","xps","zip","rar"
strProcessedPath = "http://docs.google.com/viewer?url=" & constServerDomain & constRootServerPath & strRelPathToRoot & strFileName
'direct file path
Case else
strProcessedPath = constServerDomain & constRootServerPath & strRelPathToRoot & strFileName
End Select
'WScript.Echo "strProcessedPath: """ & strProcessedPath & """"
ProcessLocalPathToServerPath = strProcessedPath
End Function
' The Internet Explorer object is used, because WSH
' and VBScript don't support clipboard access by themselves.
Sub SendToClipboard(strToClipboard)
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.Document.ParentWindow.ClipboardData.SetData "text", strToClipboard
objIE.Quit
Set objIE = Nothing
End Sub
Sub Register
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
On Error Resume Next
' Add the required registry entries for files
wshShell.RegWrite "HKEY_CLASSES_ROOT\*\shell\webists_serverpathtoclip\", "Copy Sever URL"
wshShell.RegWrite "HKEY_CLASSES_ROOT\*\shell\webists_serverpathtoclip\command\", "wscript.exe """ & WScript.ScriptFullName & """ ""%L""", "REG_EXPAND_SZ"
On Error Goto 0
Set wshShell = Nothing
WScript.Echo "Script successfully registered."
WScript.Quit 0
End Sub
Sub UnRegister
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
On Error Resume Next
' Remove the registry entries for the files menu
wshShell.RegDelete "HKEY_CLASSES_ROOT\*\shell\webists_serverpathtoclip\command\"
wshShell.RegDelete "HKEY_CLASSES_ROOT\*\shell\webists_serverpathtoclip\"
' Remove the registry entries for the folders menu
' wshShell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\webists_serverpathtoclip\command\"
' wshShell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\webists_serverpathtoclip\"
On Error Goto 0
Set wshShell = Nothing
WScript.Echo "Script successfully unregistered."
WScript.Quit 0
End Sub
Sub Syntax
Dim strMsg
strMsg = "Webists_GetCorrespondingServerPath.vbs, Version 1.00" & vbCrLf _
& "written by Andy Brennenstuhl @ The Webists" & vbCrLf _
& "http://www.thewebists.com" & vbCrLf & vbCrLf _
& "Use this script to get corresponding server paths of synchronised files." & vbCrLf & vbCrLf _
& "MAKE SURE TO CONFIGURE BY EDITING CONST VALUES IN THE SCRIPT." & vbCrLf & vbCrLf _
& "Usage: WSCRIPT Webists_GetCorrespondingServerPath.vbs ""text string"" | /Register | /Unregister" & vbCrLf & vbCrLf _
& "Where: ""text string"" is the full local path of the files you want to get the URL for" & vbCrLf _
& " /Register Adds an entry ""Copy Webists Viewer Path"" to Explorers' context menu" & vbCrLf _
& " /UnRegister Removes the menu entry again" _
& vbCrLf & vbCrLf _
& "Based on 'SendClip.vbs' Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit 1
End Sub
我不喜欢的唯一的事情是有点它使用IE浏览器把字符串中的剪贴板,因为它每次都要求得到允许的方式。
任何人都可以提出一个更好的办法?
Sub SendToClipboard(strToClipboard)
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.Document.ParentWindow.ClipboardData.SetData "text", strToClipboard
objIE.Quit
Set objIE = Nothing
End Sub
我已经回答以下问题。 – AndyAtTheWebists 2012-02-08 12:00:52