本帖最后由 for_flr 于 2022-3-18 16:46 编辑
批处理调用powershell可以完成。- #@&cls&powershell "iex(gc '%~0'|out-string)"&pause&exit /b"
-
- if ([threading.thread]::CurrentThread.GetApartmentState() -ne "STA"){
- powershell -sta
- }
- Add-Type -AssemblyName System.Windows.Forms
- #加载System.Windows.Forms
-
- $folder=get-date -f D
- if(!(test-path $folder)){md $folder}
- $folder=gi $folder
- $folder
- #根据日期建立文件夹$folder
- #也可以直接定义$folder="d:\aaa\bbb\test"
-
- $h=1
- $ms=$h*3600000
- $rate=800
- $loop=$ms/$rate
- #定义监控时间及频率,这里定义的1小时,每800毫秒检查一次剪贴板。
-
- function monitor{
- $clipdata = [System.Windows.Forms.Clipboard]::GetDataObject()
- $filetime=get-date -f MMddHHmmss
- if ($clipdata.ContainsImage()) {
- $clipdata.getimage().save("$folder\$filetime.jpg")
- write-host "存储图片到文件$filetime+.jpg" -fore green
- }
- if($clipdata.containstext()){
- $clipdata.gettext()+"`r`n"|ac $folder\text.txt
- write-host "存储文字到文件text.txt" -fore green
- }
- if($clipdata.containsfiledroplist()){
- copy $clipdata.getfiledroplist() $folder
- write-host "复制文件到文件夹$folder" -fore green
- }
-
- [System.Windows.Forms.Clipboard]::clear()
- write-host "监控剪贴板..."
- Start-Sleep -Milliseconds $rate
- }
-
- for($i=1;$i -lt $loop;$i++){monitor}
- #根据前面定义的时长,循环执行
复制代码
|