[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
test.ps1
  1. $shell = New-Object -ComObject 'WScript.Shell' ; $arr = @()
  2. $args | foreach { $arr += $shell.CreateShortcut($_).TargetPath }
  3. $s = $arr -join "`r`n" ; Write-Host $s
  4. Set-Clipboard -Value $s
复制代码
powershell test.ps1 "C:\Users\Public\Desktop\腾讯QQ.lnk"  "F:\Desktop\微信.lnk"

TOP

  1. [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
  2. $shell = New-Object -ComObject 'WScript.Shell'
  3. $paths = New-Object 'System.Collections.Specialized.StringCollection'
  4. $args | foreach {
  5.     $file_str = $shell.CreateShortcut($_).TargetPath
  6.     Write-Host $file_str
  7.     [void]$paths.Add($file_str)
  8. }
  9. [System.Windows.Forms.Clipboard]::SetFileDropList($paths)
复制代码
1

评分人数

TOP

test.bat 管理员运行
  1. @echo off & cd /d "%~dp0"
  2. set "ps1=F:\Desktop\test.ps1"
  3. reg add "HKCR\lnkfile\shell\复制源到剪贴板\command" /ve /d "powershell \"%ps1%\" %%1" /f
  4. pause&exit
复制代码
F:\Desktop\test.ps1
只支持单个文件右键

TOP

回复 7# g495326
  1. [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
  2. $shell = New-Object -ComObject 'WScript.Shell'
  3. $paths = New-Object 'System.Collections.Specialized.StringCollection'
  4. $args | foreach {
  5.     if($_.EndsWith('.lnk')){
  6.         $file_str = $shell.CreateShortcut($_).TargetPath
  7.     } else {
  8.         $file_str = $_
  9.     }
  10.     Write-Host $file_str
  11.     [void]$paths.Add($file_str)
  12. }
  13. [System.Windows.Forms.Clipboard]::SetFileDropList($paths)
复制代码

TOP

  1. using namespace 'Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes';cls
  2. [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
  3. Add-Type -Name 'WinApi' -MemberDefinition '[DllImport("user32.dll")]public static extern short GetKeyState(uint VK);'
  4. $shell = New-Object -ComObject 'WScript.Shell'
  5. $paths = New-Object 'System.Collections.Specialized.StringCollection'
  6. if([WinApi]::GetKeyState(16) -band 0x8000){ $paths = [System.Windows.Forms.Clipboard]::GetFileDropList() }
  7. $args | foreach { [void]$paths.Add($shell.CreateShortcut($_).TargetPath) }
  8. $paths = $paths | Select-Object -Unique | Where-Object {[System.IO.File]::Exists($_)}
  9. [System.Windows.Forms.Clipboard]::SetFileDropList($paths)
  10. $paths
复制代码
回复 9# g495326

TOP

本帖最后由 went 于 2022-10-19 16:04 编辑
  1. using namespace 'Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes'
  2. using namespace 'System.Windows.Forms'
  3. using namespace 'System.Collections.Specialized';cls
  4. [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
  5. Add-Type -Name 'WinApi' -MemberDefinition '[DllImport("user32.dll")]public static extern short GetKeyState(uint VK);'
  6. $shell = New-Object -ComObject 'WScript.Shell'
  7. $paths = New-Object 'StringCollection'
  8. $arr_err = New-Object 'System.Collections.ArrayList'
  9. if([WinApi]::GetKeyState(16) -band 0x8000){ write-host 'shift';$paths = [Clipboard]::GetFileDropList() }
  10. $args | foreach { [void]$paths.Add($_) }
  11. $paths = &{
  12. $paths | Select-Object -Unique | foreach {
  13. #目录
  14. if([System.IO.Directory]::Exists($_)){ return $_ }
  15. #文件
  16. if([System.IO.File]::Exists($_)){
  17. #lnk文件
  18. if($_.EndsWith('.lnk')){
  19. $p = $shell.CreateShortcut($_).TargetPath
  20. if([System.IO.File]::Exists($p)){ return $p }
  21. if([System.IO.Directory]::Exists($p)){ return $p }
  22.                 [void]$arr_err.Add(('{0} -> {1}' -f $_,$p))
  23. return $null
  24. }
  25. #其它文件
  26. return $_
  27. }
  28. } | Select-Object -Unique
  29. }
  30. if($paths.Count -gt 0){
  31. [Clipboard]::SetFileDropList($paths)
  32. 'ok'
  33. $paths
  34. '-----------'
  35. }
  36. if($arr_err.Count -gt 0){
  37. 'fail'
  38. $arr_err
  39. '-----------'
  40. pause
  41. }
复制代码

TOP

源文件报错第28行改为
  1. if($paths.Count -gt 0){ [Clipboard]::SetFileDropList($paths) }
复制代码
检测shift要加载dll耗时,只有多按一点时间 5-8行都是

TOP

回复 15# g495326


    21行 return $null 改为
  1. Write-Host ('未找到源 {0} -> {1}' -f $_,$p);pause
  2. return $null
复制代码

TOP

回复 17# g495326


    12楼改了,你直接复制

TOP

回复 20# g495326


   我win11,用不了发送到菜单

TOP

win11

TOP

回复 24# g495326


    对话框选择文件我测试是ok的


你在脚本最后添加一行 pause
看看是否有报错

TOP

回复 27# g495326


    目标都变了不可能还能定位到
    上面的意思是lnk目标改变,还是能解析到lnk里原先保存的源目标,而不至于报错

TOP

返回列表