não é capaz de executar o arquivo em lotes de configuração do computador na inicialização

0

Estou visualizando um conjunto de máquinas usando o Windows PE e uma unidade flash. Eu criei vários scripts para automatizar o processo, mas não consigo iniciá-lo na inicialização. Coloquei-o na pasta C: \ ProgramData \ Microsoft \ Windows \ Menu Iniciar \ Programas \ StartUp para que, independentemente de quem o faça, seja executado. A imagem foi preparada para fazer login como administrador quando é inicializada logo após a instalação completa da imagem.

Eu tentei colocá-lo na pasta C: \ Usuários \ administrador \ AppData \ Roaming \ Microsoft \ Windows \ Menu Iniciar \ Programas \ Startup e ele não é executado na inicialização. Eu posso clicar neles manualmente, e eles serão executados, mas eles não são automaticamente.

Aqui estão os scripts abaixo:

O script abaixo é o principal que irá iniciar e iniciar os outros quando o valor do registro for atendido.

@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
)

Aqui está o script de renomeação do computador:

@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

Aqui está o arquivo em lote do domínio e o arquivo do 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.'

A última coisa que faz é entrar na conta de domínio geral e instalar o SCCM.

Eu testei os scripts separadamente e eles funcionam sem problemas, eles não serão iniciados automaticamente. Existe uma maneira de fazer isso funcionar no começo?

ATUALIZAÇÃO:

Eu reiniciei a máquina várias vezes. Pelo menos 3 e, em seguida, o script decidiu ser executado. Coloquei o script na pasta C: \ ProgramData \ Microsoft \ Windows \ Menu Iniciar \ Programas \ StartUp.

    
por Harley Frank 12.07.2017 / 18:25

0 respostas