我正在使用 Windows PE 和闪存驱动器对一组机器进行映像处理。我创建了几个脚本来自动化该过程,但我无法让它在启动时启动。我已将其放在 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 文件夹中,这样无论谁登录它都会运行。映像已准备好在映像安装完成后立即启动时以管理员身份登录。
我尝试将其放在 C:\Users\administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 文件夹中,但它在启动时也不会运行。我可以手动单击它们,它们会运行,但不会自动运行。
以下是脚本:
下面的脚本是主要脚本,当满足注册表值时,它将启动并启动其他脚本。
@echo off
title Computer Setup
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
echo Computer Setup Command
echo Version 3.0
echo Date Created 7-7-17
echo Author: Harley Frank
echo ====================
ECHO Checking Registry for AutoRun Value
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run"
set VALUE_NAME=AutoRun
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
if defined ValueName (
@echo Value Name = %ValueName%
@echo Value Type = %ValueType%
@echo Value Value = %ValueValue%
set regValue=%ValueValue%
) else (
@echo %KEY_NAME%\%VALUE_NAME% not found.
@echo Creating registry value now to begin the setup. This will take only but a moment.
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v AutoRun /t REG_SZ /d 1
)
Echo Now running the setup scripts. Please wait.
if %regValue% EQU 1 (
echo Initial Restart Script
echo Version 2
echo Date Created 7-7-17
echo Author: Harley Frank
echo ====================
echo Restarting the Machine for the First Time.
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d administrator
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d omitted
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 1
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v AutoRun /t REG_SZ /d 2
shutdown /r /c "Restarting the computer to apply changes." /t 60 /f
) else if %regValue% EQU 2 (
call "C:\Source Files\Scripts\rename.bat"
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v AutoRun /t REG_SZ /d 3
exit
) else if %regValue% EQU 3 (
call "C:\Source Files\Scripts\domain.bat"
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v AutoRun /t REG_SZ /d 4
exit
) else if %regValue% EQU 4 (
echo running silent software install
"C:\Source Files\SCCM2012Client\ccmsetup.exe"
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Run" /v AutoRun /t REG_SZ /d 5
msg "%username%" The machine setup should be completed now. SCCM should have successfully launched and is running in the background.
) else if %regValue% EQU 5 (
rem del "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\run.bat"
echo DONE
exit
)
这是计算机重命名脚本:
@ECHO OFF
title Computer Rename
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO Setting Machine to Login as Administrator on next reboot.
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d administrator
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d omitted
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 1
echo Rename Script
echo Version 3.0
echo Date Created 7-11-17
echo Author: Harley Frank
echo ====================
SET count=1
SET /p campus= Please enter the abbreviation name of the campus you are at for this computer to be properly named:
FOR /F "tokens=* USEBACKQ" %%F IN (`wmic bios get serialnumber`) DO (
SET serialnumber!count!=%%F
SET /a count=!count!+1
)
SET pcname=%campus%-%serialnumber2%
::
SET pcname=%pcname:~0,15%
SET pcname=%pcname: =%
::
ECHO Automated Rename in Progress. Renaming to:
ECHO %pcname%
WMIC computersystem where name="%computername%" call rename name="%pcname%"
shutdown /r /c "Restarting to apply computer name changes." /t 60 /f
以下是域批处理文件和 PowerShell 文件:
@ECHO OFF
tile Domain Setup Script
echo Domain Setup Script
echo Version 4.0
echo Date Created 6-29-17
echo Author: Harley Frank
echo ====================
ECHO Prepping the machine to sign into the default domain account on restart.
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d omitted
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d adddomain
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d omitted
ECHO y | reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 2
ECHO Adding the machine to the domain. Will restart when complete.
CALL PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\Source Files\Scripts\domain.ps1""' -Verb RunAs}"
ECHO Restarting machine now.
shutdown /r /c "Restarting to add the machine to the domain." /t 60 /f
Write-Output 'Domain Setup Script'
Write-Output 'Version 4.0'
Write-Output 'Date Created 6-29-17'
Write-Output 'Author: Harley Frank'
Write-Output '===================='
Write-Output 'Adding machine to the domain using adddomain user.'
$domain = "omitted"
$password = "omitted" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\adddomain"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential
Write-Output 'Restarting the computer to apply changes.'
它所做的最后一件事是登录通用域帐户并安装 SCCM。
我分别测试了这些脚本,它们运行正常,只是不会自动启动。有没有办法让它在启动时运行?
更新:
我重启了机器好几次。至少重启了 3 次,然后脚本才决定运行。我将脚本放入 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 文件夹中。