我需要自动为我的客户端部署Windows 10。我使用SetupComplete.cmd功能连接到公司的wifi并安装MSI。有一些EXE安装我无法静默运行,因此我打算将安装文件复制到本地驱动器,并使用命令schtasks.exe设置一个计划任务,以便在下次登录时运行脚本以完成其余安装。
脚本成功连接到wifi,安装msi并将文件复制到本地驱动器。但是,未设置计划任务。
如果我在用户登录后在机器上运行SetupComplete.cmd脚本,则包括计划任务创建在内的所有功能都将成功完成。
我指定了schtask (windir/system32)的确切文件夹路径,并从那里运行。手动运行时有效,而不是从setupcomplete.cmd运行。
我已经尝试将schtasks.exe复制到安装介质并从其中调用程序(以防在脚本运行时未编写可执行文件,我对此表示怀疑)
我已经将该任务作为最后一步,并在其执行之前包含了20秒的休眠。
我启用了日志记录,命令运行了,但是没有确认请求。关闭回显后,不会给出结果。如果启用echo,则打印该行时不会产生任何结果。
我从我的SetupComplete脚本中删除了所有其他命令,只运行schtasks.exe命令,以防它与其他命令不能很好地配合使用,但这仍然不起作用。我见过其他论坛在他们的SetupCmplete脚本中使用schtasks.exe作为一些需求的解决方案,所以如果使用得当,它似乎可以工作。
我知道这个阶段的脚本是在System帐户下运行的,但是找不到任何不能使用这些权限运行的内容。
@echo off
set LOGFILE= D:\test\batch.log
call :LOG > %LOGFILE%
exit /B
:LOG
netsh wlan add profile filename="D:\Blah.xml"
netsh wlan connect name=An interface="WiFi"
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d D:\bkgrnd\blah.bmp /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
REM ***MSI INSTALLS***
msiexec.exe /i "D:\MSI\3t.msi" /quiet /norestart /L*V "D:\MSI\logs\3TLog.log"
msiexec.exe /i "D:\MSI\Chrome.msi" /quiet /norestart /L*V "D:\MSI\logs\ChromeLog.log"
msiexec.exe /i "D:\MSI\FireFox.msi" /quiet /norestart /L*V "D:\MSI\logs\FFLog.log"
msiexec.exe /i "D:\MSI\node.msi" /quiet /norestart /L*V "D:\MSI\logs\nodeLog.log"
msiexec.exe /i "D:\MSI\Slack.msi" /quiet /norestart /L*V "D:\MSI\logs\SlackLog.log"
msiexec.exe /i "D:\MSI\fs-windows-agent-2.5.0.msi" /quiet /norestart /L*V "D:\MSI\logs\FreshService.log"
REM Copy install files and create scheduled task to complete installs of BD and CB
mkdir C:\FinalInstalls
mkdir C:\FinalInstalls\BD
mkdir C:\FinalInstalls\CB
xcopy "D:\EXE\setupdownloader_[astring].exe" C:\FinalInstalls\BD
xcopy D:\EXE\CB\Setup.exe C:\FinalInstalls\CB
xcopy D:\EXE\CB\settings.ini C:\FinalInstalls\CB
xcopy D:\finalinstalls.cmd C:\FinalInstalls
schtasks /create /tn "FinalInstalls" /tr "cmd.exe /k C:\FinalInstalls\finalinstalls.cmd" /sc ONLOGON /RL HIGHEST
我希望任务在任务调度器中显示,就像我手动运行它时一样。我想不出另一种方法来解决这个问题,而且它似乎对其他人也有效。如有任何帮助,我们将不胜感激:)
谢谢!
发布于 2020-11-04 02:14:53
确保在setupcomplete.cmd运行之前禁用UAC。
我使用现有的Windows ISO在生产计算机上加载Windows 10,并使用:
启动primary
在更新我部署的操作系统时,我最初没有配置autounattend.xml,而是仅使用setupcomplete.cmd文件测试部署,因为我必须通过DISM将该文件插入到映像中。我在setupcomplete.cmd文件中的Schtask命令不会运行,但批处理文件的其余部分可以正常运行。
正如其他人所经历的那样,我要将schtask命令输出导出到的日志文件已创建,但没有任何内容。此外,在手动运行时,包括schtask命令在内的setupcomplete.bat可以正常工作。
经过多次测试,我发现当我在未提升的cmd提示符中手动运行setupcomplete.cmd的schtask行时,我会得到与setupcomplete.cmd被自动触发时相同的行为。
然后,我能够确认我的autounattend.xml文件确实禁用了UAC,并输入了以下条目:
<settings pass="offlineServicing">
<component name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EnableLUA>false</EnableLUA>
</component>
</settings>
一旦我使用所示的设置将autounattend.xml文件应用于部署的映像,setupcomplete.cmd就能够成功地运行schtask命令。
https://stackoverflow.com/questions/56431516
复制相似问题