Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for sendclip.vbs

(view source code of sendclip.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim objIE
  4.  
  5. ' Parse the command line arguments
  6. If WScript.Arguments.Count      <> 1 Then Syntax
  7. If WScript.Arguments.Named.Count = 1 Then
  8. 	If WScript.Arguments.Named.Exists( "Register" ) Then
  9. 		Register
  10. 	ElseIf WScript.Arguments.Named.Exists( "Unregister" ) Then
  11. 		UnRegister
  12. 	Else
  13. 		Syntax
  14. 	End If
  15. End If
  16.  
  17. ' If the command line argument is a text string, send it to the
  18. ' clipboard. The Internet Explorer object is used, because WSH
  19. ' and VBScript don't support clipboard access by themselves.
  20. If WScript.Arguments.UnNamed.Count = 1 Then
  21. 	Set objIE = CreateObject( "InternetExplorer.Application" )
  22. 	objIE.Navigate( "about:blank" )
  23. 	objIE.Document.ParentWindow.ClipboardData.SetData "text", _
  24. 	                                     WScript.Arguments.Unnamed(0)
  25. 	objIE.Quit
  26. 	Set objIE = Nothing
  27. End If
  28.  
  29.  
  30. Sub Register
  31. 	Dim wshShell
  32.  
  33. 	Set wshShell = CreateObject( "WScript.Shell" )
  34.  
  35. 	On Error Resume Next
  36.  
  37. 	' Add the required registry entries for files
  38. 	wshShell.RegWrite "HKEY_CLASSES_ROOT\*\shell\sendclip\", _
  39. 	                  "Send full path to clipboard"
  40. 	wshShell.RegWrite "HKEY_CLASSES_ROOT\*\shell\sendclip\command\", _
  41. 	                  "wscript.exe """ & WScript.ScriptFullName _
  42. 	                  & """ ""%L""", "REG_EXPAND_SZ"
  43.  
  44. 	' Add the required registry entries for folders
  45. 	wshShell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\sendclip\", _
  46. 	                  "Send full path to clipboard"
  47. 	wshShell.RegWrite "HKEY_CLASSES_ROOT\Folder\shell\sendclip\command\", _
  48. 	                  "wscript.exe """ & WScript.ScriptFullName _
  49. 	                  & """ ""%L""", "REG_EXPAND_SZ"
  50.  
  51. 	On Error Goto 0
  52.  
  53. 	Set wshShell = Nothing
  54.  
  55. 	WScript.Quit 0
  56. End Sub
  57.  
  58.  
  59. Sub UnRegister
  60. 	Dim wshShell
  61.  
  62. 	Set wshShell = CreateObject( "WScript.Shell" )
  63.  
  64. 	On Error Resume Next
  65.  
  66. 	' Remove the registry entries for the files menu
  67. 	wshShell.RegDelete "HKEY_CLASSES_ROOT\*\shell\sendclip\command\"
  68. 	wshShell.RegDelete "HKEY_CLASSES_ROOT\*\shell\sendclip\"
  69.  
  70. 	' Remove the registry entries for the folders menu
  71. 	wshShell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\sendclip\command\"
  72. 	wshShell.RegDelete "HKEY_CLASSES_ROOT\Folder\shell\sendclip\"
  73.  
  74. 	On Error Goto 0
  75.  
  76. 	Set wshShell = Nothing
  77.  
  78. 	WScript.Quit 0
  79. End Sub
  80.  
  81.  
  82. Sub Syntax
  83. 	Dim strMsg
  84. 	strMsg = "SendClip.vbs,  Version 1.01" & vbCrLf _
  85. 	       & "Send a text string to the clipboard" & vbCrLf & vbCrLf _
  86. 	       & "Usage:  WSCRIPT  SENDCLIP.VBS  ""text string"" " _
  87. 	       & "| /Register | /Unregister" & vbCrLf & vbCrLf _
  88. 	       & "Where:  ""text string""   is the text to be sent to " _
  89. 	       & "the clipboard" & vbCrLf _
  90. 	       & "        /Register       Adds an entry " _
  91. 	       & """Send full path to clipboard""" & vbCrLf _
  92. 	       & "                        to Explorers' " _
  93. 	       & "context menu for all files" & vbCrLf _
  94. 	       & "        /UnRegister     Removes the menu entry again" _
  95. 	       & vbCrLf & vbCrLf _
  96. 	       & "Written by Rob van der Woude" & vbCrLf _
  97. 	       & "http://www.robvanderwoude.com"
  98. 	WScript.Echo strMsg
  99. 	WScript.Quit 1
  100. End Sub
  101.  

page last modified: 2024-04-16; loaded in 0.0075 seconds