dcandygmailcom

PrintClip.exe #2 prints any text or filenames on the clipboa

Feb 16th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.70 KB | None | 0 0
  1. REM PrintClip.bat #2 Also does filenames on the clipboard
  2. REM This file compiles PrintClip.vb to PrintClip.exe
  3. REM PrintClip.exe prints any text or filenames on the clipboard to a console
  4. REM To use
  5. REM PrintClip
  6. "C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\PrintClip.exe" "%~dp0\PrintClip.vb" /verbose
  7. pause
  8.  
  9. -------------------------------------------------
  10.  
  11.  
  12. 'PrintClip.vb #2
  13. Imports System
  14. Imports System.IO
  15. Imports System.Runtime.InteropServices
  16. Imports Microsoft.Win32
  17.  
  18. Public Module PrintClip
  19.     Public Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Integer
  20.     Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As IntPtr
  21.     Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As IntPtr) As Integer
  22.     Public Declare Function CloseClipboard Lib "user32" () As Integer
  23.     Public Declare UNICODE Function DragQueryFileW Lib "shell32.dll" (ByVal HDROP As Integer, ByVal UINT As Integer, ByVal lpStr As String, ByVal ch As Integer) As Integer
  24.  
  25.     Public Const CF_TEXT = 1
  26.     Public Const CF_BITMAP = 2
  27.     Public Const CF_METAFILEPICT = 3
  28.     Public Const CF_SYLK = 4
  29.     Public Const CF_DIF = 5
  30.     Public Const CF_TIFF = 6
  31.     Public Const CF_OEMTEXT = 7
  32.     Public Const CF_DIB = 8
  33.     Public Const CF_PALETTE = 9
  34.     Public Const CF_PENDATA = 10
  35.     Public Const CF_RIFF = 11
  36.     Public Const CF_WAVE = 12
  37.     Public Const CF_UNICODETEXT = 13
  38.     Public Const CF_ENHMETAFILE = 14
  39.     Public Const CF_HDROP = 15
  40.     Public Const CF_OWNERDISPLAY = &H80
  41.     Public Const CF_DSPTEXT = &H81
  42.     Public Const CF_DSPBITMAP = &H82
  43.     Public Const CF_DSPMETAFILEPICT = &H83
  44.     Public Const CF_DSPENHMETAFILE = &H8E
  45.  
  46.  
  47.     Sub Main()
  48. '       On Error Resume Next
  49.         Dim Ret as IntPtr
  50.         If OpenClipboard(0) <> 0 then
  51.             If IsClipboardFormatAvailable(CF_UNICODETEXT) <> 0 then
  52.                 Ret = GetClipboardData( CF_UNICODETEXT)
  53.                 Console.writeline(Marshal.PtrToStringUni(Ret))
  54.                 Environment.ExitCode = 0
  55.             ElseIf IsClipboardFormatAvailable(CF_hDrop) <> 0 then
  56.                 Dim TotalCount as Integer
  57.                 Dim FName as String
  58.                 Dim hDrop as IntPtr
  59.                 hDrop = GetClipboardData( CF_hDrop)
  60.                 FName = Space(33000)
  61.                 TotalCount = DragQueryFileW(hDrop,  &hFFFFFFFF, FName, 33000)
  62.                 For x = 0 to TotalCount - 1
  63.                     FName = Space(33000)
  64.                     If DragQueryFileW(hDrop,  x, FName, 33000) <> 0 then
  65.                         Console.writeline(Trim(FName))
  66.                     End If
  67.                 Next
  68.                 Environment.ExitCode = 0
  69.             Else
  70.                 Environment.ExitCode = 1
  71.                 Console.writeline("No text or filenames on clipboard")
  72.             End If
  73.             CloseClipboard()
  74.         Else
  75.             Environment.ExitCode = err.lastdllerror
  76.             Console.Writeline("Clipboard is locked by another application")
  77.         End If
  78.  
  79.     End Sub
  80. End Module
  81.  Module
Advertisement
Add Comment
Please, Sign In to add comment