Inno Setup 批处理文件使用 cacls 检查权限失败

Inno Setup Batch file Check for privileges using cacls fails

我尝试在安装完成后执行批处理文件。

Filename: "{cmd}"; Parameters: "/C ""{app}\Start.bat"""; \
    Description: {cm:LaunchAfterInstallQuest_lbl}; \
    Flags: nowait postinstall skipifsilent shellexec;

批处理文件start.bat正在请求管理权限并启动两项服务。

@if (1==1) @if(1==0) @ELSE
@echo off&SETLOCAL ENABLEEXTENSIONS
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"||(
    cscript //E:JScript //nologo "%~f0"
    @goto :EOF
)

REM --> start services
set error=0
set date=%date%_%time:~0,2%-%time:~3,2%-%time:~6,2%

net start "SMC Integrationsserver" 2>>"%~dp0logfile_start_%date%.txt"
IF ERRORLEVEL 1 ( set error=1 )

net start "Wildfly" 2>>"%~dp0logfile_start_%date%.txt"
IF ERRORLEVEL 1 ( set error=1 )

if %error%==1 ( 
echo Ein Fehler trat auf, bitte pruefen Sie die Logdatei "%~dp0logfile_start_%date%.txt"
pause
@goto :EOF
)
if %error%==0 (
del /s /q "%~dp0logfile_*.txt"
)

@goto :EOF
@end @ELSE
ShA=new ActiveXObject("Shell.Application")
ShA.ShellExecute("cmd.exe","/c \""+WScript.ScriptFullName+"\"","","runas",1);
@end

当我在设置安装程序中单击 完成 时,start.bat 文件正在无限循环中执行。

有什么问题吗?

首先,这太过分了。 运行 net start(或者至少是批处理文件)直接形成脚本的 [Run] 部分,没有 postinstall 标志。这样 net start(或批处理文件)以提升的权限启动。而且您不需要使用那种丑陋、容易出错且难以调试的 hack 将两种语言组合在一个文件中。

使用 "task" 使 运行 可由用户配置。


无论如何,批处理文件会循环,因为 Inno Setup 是 32 位应用程序,所以它默认启动 32 位 cmd.exe,在 64 位系统上看不到 C:\WINDOWS\system32\config\system。这是因为对于在 64 位系统上运行的 32 位进程 运行,C:\WINDOWS\system32 被重定向到 C:\WINDOWS\SysWOW64,其中没有 config 子目录。所以 cacls.exe 失败

The system cannot find the file specified.


查看这些问题以获取详细信息和解决方案(在您的案例中是 hack):