|
|
本帖最后由 tt911 于 2026-4-5 10:54 编辑
尝试了多次,包括VBS、NirCMD、PowerShell都是失败告终:
- Windows Registry Editor Version 5.00
- [HKEY_CLASSES_ROOT\*\shell\copypath]
- @="复制文件完整路径"
- "Icon"="D:\\网络相关\\袖珍版IDM.exe,0"
- [HKEY_CLASSES_ROOT\*\shell\copypath\command]
- @="\"d:\\CopyMultiPath.exe\" \"%1\""
复制代码 最后一生气,干脆使用VS2022专门开发一下吧:
- #define _CRT_SECURE_NO_WARNINGS // 1. 禁用安全警告
- #include <windows.h>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <windows.h>
- // 使用 wchar_t 处理 Unicode,确保中文路径不乱码
- void SetClipboardUnicode(const std::wstring& text) {
- if (!OpenClipboard(nullptr)) return;
- EmptyClipboard();
- size_t size = (text.size() + 1) * sizeof(wchar_t);
- HGLOBAL hGlob = GlobalAlloc(GMEM_MOVEABLE, size);
- if (hGlob) {
- memcpy(GlobalLock(hGlob), text.c_str(), size);
- GlobalUnlock(hGlob);
- SetClipboardData(CF_UNICODETEXT, hGlob);
- }
- CloseClipboard();
- }
- int wmain(int argc, wchar_t* argv[]) { // 使用 wmain 接收宽字符参数
- if (argc < 2) return 0;
- // 2. 获取临时文件路径
- wchar_t tempPath[MAX_PATH];
- GetTempPathW(MAX_PATH, tempPath);
- std::wstring tempFile = std::wstring(tempPath) + L"xcopy_paths.tmp";
- // 3. 追加路径到临时文件 (使用二进制模式并写入 UTF-16)
- std::wofstream ofs(tempFile, std::ios::app);
- ofs.imbue(std::locale("")); // 适配系统语言
- ofs << argv[1] << L"\n";
- ofs.close();
- // 4. 等待并发写入完成
- Sleep(200);
- // 5. 读取并同步到剪贴板
- std::wifstream ifs(tempFile);
- ifs.imbue(std::locale(""));
- if (ifs.is_open()) {
- std::wstring allPaths((std::istreambuf_iterator<wchar_t>(ifs)), std::istreambuf_iterator<wchar_t>());
- ifs.close();
- if (!allPaths.empty()) {
- SetClipboardUnicode(allPaths);
- DeleteFileW(tempFile.c_str()); // 阅后即焚
- }
- }
- return 0;
- }
复制代码
|
|