如何用 batch 取得剪貼簿的內容 - Windows
By Tom
at 2011-04-01T18:45
at 2011-04-01T18:45
Table of Contents
(OS是XP)
這個問題困擾我蠻久了
我常常寫小程式來自動化一些任務
很多工作只需 batch (.bat) 即可完成
但唯有剪貼簿的操作要靠其他程式語言或外部程式
例如...
1. 用vbs清空剪貼簿
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", ""
objIE.Quit
2. 用 clip.exe 清空剪貼簿
%windir%\system32\cmd.exe /c "echo off | clip"
3. 用 python 清空剪貼簿
import ctypes
#Get required functions, strcpy..
strcpy = ctypes.cdll.msvcrt.strcpy
ocb = ctypes.windll.user32.OpenClipboard #Basic Clipboard functions
ecb = ctypes.windll.user32.EmptyClipboard
gcd = ctypes.windll.user32.GetClipboardData
scd = ctypes.windll.user32.SetClipboardData
ccb = ctypes.windll.user32.CloseClipboard
ga = ctypes.windll.kernel32.GlobalAlloc # Global Memory allocation
gl = ctypes.windll.kernel32.GlobalLock # Global Memory Locking
gul = ctypes.windll.kernel32.GlobalUnlock
GMEM_DDESHARE = 0x2000
def Get( ):
ocb(None) # Open Clip, Default task
pcontents = gcd(1) # 1 means CF_TEXT.. too lazy to get the token thingy ...
data = ctypes.c_char_p(pcontents).value
#gul(pcontents) ?
ccb()
return data
def Paste(data):
ocb(None) # Open Clip, Default task
ecb()
hCd = ga( GMEM_DDESHARE, len( bytes(data,"ascii") )+1 )
pchData = gl(hCd)
strcpy(ctypes.c_char_p(pchData),bytes(data,"ascii"))
gul(hCd)
scd(1,hCd)
ccb()
ocb(None)
ecb()
想請問的是
在不使用外部程式(clip, nircmd, ...)或其他程式語言(vb, c/c++, ...)的情況下
該如何利用 batch 取得及設定剪貼簿的文字內容?
查了幾個小時依然一無所獲...
--
這個問題困擾我蠻久了
我常常寫小程式來自動化一些任務
很多工作只需 batch (.bat) 即可完成
但唯有剪貼簿的操作要靠其他程式語言或外部程式
例如...
1. 用vbs清空剪貼簿
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", ""
objIE.Quit
2. 用 clip.exe 清空剪貼簿
%windir%\system32\cmd.exe /c "echo off | clip"
3. 用 python 清空剪貼簿
import ctypes
#Get required functions, strcpy..
strcpy = ctypes.cdll.msvcrt.strcpy
ocb = ctypes.windll.user32.OpenClipboard #Basic Clipboard functions
ecb = ctypes.windll.user32.EmptyClipboard
gcd = ctypes.windll.user32.GetClipboardData
scd = ctypes.windll.user32.SetClipboardData
ccb = ctypes.windll.user32.CloseClipboard
ga = ctypes.windll.kernel32.GlobalAlloc # Global Memory allocation
gl = ctypes.windll.kernel32.GlobalLock # Global Memory Locking
gul = ctypes.windll.kernel32.GlobalUnlock
GMEM_DDESHARE = 0x2000
def Get( ):
ocb(None) # Open Clip, Default task
pcontents = gcd(1) # 1 means CF_TEXT.. too lazy to get the token thingy ...
data = ctypes.c_char_p(pcontents).value
#gul(pcontents) ?
ccb()
return data
def Paste(data):
ocb(None) # Open Clip, Default task
ecb()
hCd = ga( GMEM_DDESHARE, len( bytes(data,"ascii") )+1 )
pchData = gl(hCd)
strcpy(ctypes.c_char_p(pchData),bytes(data,"ascii"))
gul(hCd)
scd(1,hCd)
ccb()
ocb(None)
ecb()
想請問的是
在不使用外部程式(clip, nircmd, ...)或其他程式語言(vb, c/c++, ...)的情況下
該如何利用 batch 取得及設定剪貼簿的文字內容?
查了幾個小時依然一無所獲...
--
Tags:
Windows
All Comments
Related Posts
win7裡面沒有 1440*900解析度
By Puput
at 2011-04-01T16:53
at 2011-04-01T16:53
Win7 x64 Ult右下的氣泡訊息提示消失了
By Carol
at 2011-04-01T15:45
at 2011-04-01T15:45
win7 x64 和 photoimpact X3 的相容?
By Valerie
at 2011-04-01T13:53
at 2011-04-01T13:53
兩張網卡能否設定外部網路的優先權?
By Adele
at 2011-04-01T09:08
at 2011-04-01T09:08
學生專案之下載會更新嗎?
By Hamiltion
at 2011-04-01T02:16
at 2011-04-01T02:16