使用批处理文件将文件复制到 Photoshop 目录中

发布于 2024-09-04 23:54:47 字数 1917 浏览 12 评论 0原文

我正在尝试修改一个批处理脚本,将一个简单的脚本文件安装到用户的 photoshop 目录中。

安装程序的基本过程是将大部分产品文件复制到 %APPDATA% 文件夹中,然后此批处理脚本在安装后运行,将一个小钩子脚本复制到 photoshop\presets\scripts 中。但是,我们遇到了一些客户计算机上未定义 %APPDATA% 的问题,检查它是否存在然后设置它(如果不存在)是否是不好的做法,如果不存在,您最好如何设置它以适应不同版本的 Windows ?

我还沿着“reg query”之路经历了一段相当坎坷的旅程,尝试找到 Photoshop 设置的一致密钥,以便找到安装目录“Path”,但我想知道最佳实践是什么那也是。

这是我当前的工作版本,具有一些 vista 权限遗迹

    @echo off
rem | locate photoshop by querying the registry
echo Locating your photoshop installation..
set regpath="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Photoshop.exe"
set regval="Path"
set photoshop_path=

rem | accumlate the path from the query
for /f "tokens=2,* delims= " %%A in ('reg query %regpath% /v %regval%') do ( 
    set photoshop_path=%%B 
)

rem | get rid of the last hanging space
set photoshop_path=%photoshop_path:~0,-1%

echo found photoshop at %photoshop_path%

set script_path=%photoshop_path%Presets\Scripts\script.jsx

echo Removing existing copies of script.jsx..
if exist "%script_path%" del "%script_path%"
echo ...Done!

echo Installing script.jsx to Photoshop Scripts directory... %script_path%
if exist "%photoshop_path%Photoshop.exe copy "%APPDATA%\My Company\etc\script.jsx" "%script_path%"
echo Done!

rem | some fix for vista permissions
ver | find "XP" > nul
if %ERRORLEVEL% neq 0 goto exit

echo Setting permissions for Vista...
echo ...Taking ownership of files...
takeown /f "%APPDATA%\My Company" /r /d y
echo ...Granting write access to files...
icacls "%APPDATA%\My Company" /grant Users:F /t
echo Done!

:exit

echo Creating Product Library entry in folderlist.cfg
echo Product Library=%APPDATA%\My Company\library>>"%APPDATA%\My Company\etc\folderlist.cfg"
echo Done!

但是,当密钥不存在时就会出现问题,当前部署的解决方案只是强力尝试可能安装的每个已知位置的 Photoshop(基于 %PROGRAMFILES%/%PROGRAMFILES (x86)% 变量。非常感谢任何对更强大和一致的脚本的帮助,以及关于哪些安装程序产品最适合以跨平台方式部署此类脚本的建议(主要是 Mac/Windows)。

I am trying to modify a batch script that installs a simple script file into the users photoshop directory.

The basic process of the installer is to copy the bulk of the products files into the %APPDATA% folder, then this batch script runs post-install that copies a little hook script into photoshop\presets\scripts. However we've run into issues with %APPDATA% not being defined on some customers machines, would it be bad practice to check if it exist then set it if not, and if not how would you best set it accounting for different versions of Windows?

I've also taken a pretty bumpy ride down the 'reg query' road to try and find a consistent key that photoshop sets in order to find the "Path" which is the install directory but I'm wondering what the best-practices for that are as well.

Here's my current working version that has some vista permission relics

    @echo off
rem | locate photoshop by querying the registry
echo Locating your photoshop installation..
set regpath="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Photoshop.exe"
set regval="Path"
set photoshop_path=

rem | accumlate the path from the query
for /f "tokens=2,* delims= " %%A in ('reg query %regpath% /v %regval%') do ( 
    set photoshop_path=%%B 
)

rem | get rid of the last hanging space
set photoshop_path=%photoshop_path:~0,-1%

echo found photoshop at %photoshop_path%

set script_path=%photoshop_path%Presets\Scripts\script.jsx

echo Removing existing copies of script.jsx..
if exist "%script_path%" del "%script_path%"
echo ...Done!

echo Installing script.jsx to Photoshop Scripts directory... %script_path%
if exist "%photoshop_path%Photoshop.exe copy "%APPDATA%\My Company\etc\script.jsx" "%script_path%"
echo Done!

rem | some fix for vista permissions
ver | find "XP" > nul
if %ERRORLEVEL% neq 0 goto exit

echo Setting permissions for Vista...
echo ...Taking ownership of files...
takeown /f "%APPDATA%\My Company" /r /d y
echo ...Granting write access to files...
icacls "%APPDATA%\My Company" /grant Users:F /t
echo Done!

:exit

echo Creating Product Library entry in folderlist.cfg
echo Product Library=%APPDATA%\My Company\library>>"%APPDATA%\My Company\etc\folderlist.cfg"
echo Done!

However, problems arise when the key doesn't exist, the current solution that is deployed just brute force tries every known location photoshop might be installed (based on the %PROGRAMFILES%/%PROGRAMFILES(x86)% variables. Any help towards a more robust and consistent script is much appreciated as well as any advice on what installer products might work best for deploying this type of script in a cross-platform manner(Mac/Windows mostly).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

闻呓 2024-09-11 23:54:47

好吧,我通过使用 Inno setup 编写一个全新的安装程序基本上解决了这个问题。它很摇滚。它使用 pascal,这对我来说有点过时,但它比批处理脚本更容易掌握和使用。请有人写一个 python 安装程序 api!

就定位用户安装的 Photoshop(或任何与此相关的程序)的最佳实践而言,简单地尝试它可能位于的每个可能的键/目录的暴力方法似乎是最好的选择。

例如,当我最近安装 Photoshop 时,它实际上在 2 个单独的文件夹中给了我 2 个安装,一个 32 位版本和 64 位版本。理想情况下,当我运行安装程序将内容添加到 Photoshop 的目录时,它应该进入两个版本。如果我只是查询一些“主注册表项”并将其填入其中,则不会这样做。看来,多年来,即使像 Adob​​e 这样的大牌也没有以一致的方式使用注册表。因此,我的安装程序工作的最佳机会是列出 adobe 为 Photoshop 的安装路径创建的每个可能的注册表项的大列表,并尝试所有这些项,然后自己尝试原始目录(至少基于环境变量) 。如果人们遵守标准就好了!

Well, I basically solved this problem by writing a completely new installer using Inno setup. It rocks. It uses pascal which feels a little archaic to me but it was much easier to pickup and use than batch scripting. Somebody please write a python installer api!

As far as best practices go for locating a user's installation of photoshop(or any program for that matter), it seems like the brute force method of simply trying every possible key/directory it might be located in is the best bet.

For instance, when I installed photoshop recently, it actually gave me 2 installations in 2 separate folders, a 32 bit and 64 bit version. Ideally, when I run my installer to add things to photoshop's directory, it should go into both versions. It wouldn't do that if I simply queried some 'master registry key' and stuffed it in there. It seems that, over the years, even a big name like Adobe hasn't used the registry in a consistent manner. So, the best chance my installer has of working is making a big list of every possible registry key adobe has made for the installation path of photoshop and trying all of them, and then also trying raw directories myself (based on environment variables at least). If only people followed standards!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文