我正在使用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文件夹中。
“它最后做的是登录通用域帐户并安装SCCM。”这不能回答你的问题,但是人们不禁要问你为什么不使用SCCM或MDT来进行这些安装。
—
Patrick Seymour
长话短说,微软PXE服务器崩溃无法修复。他们不想重建它,因为它会花费太多,他们想转向像鬼一样的东西。然而,通过大量的研究,我发现通过USB和PE更容易,但仍需要安装SCCM。当我们一次重新成像大型机器时,我试图有效地做到这一点。
—
Harley Frank
很公平,我不会因为它没有回答您的问题而将其击败,但您可以使用MDT(Microsoft Deployment Toolkit)构建部署,并将该部署放在USB驱动器上。我只提到这一点,因为您不需要自己完成所有这些自定义脚本。
—
Patrick Seymour