以管理员身份运行时,批处理不会键入ASCII

时间:2014-04-21 12:40:32

标签: batch-file scripting ascii-art

我有一个批处理文件,我将它们组合在一起以自动完成我们在内部进行的安装,但是我使用ASCII艺术制作的标题用type打印到脚本中。当我以管理员身份运行时,它不会type文本文件。

我有什么遗失的吗?

:::::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights::
:::::::::::::::::::::::::::::::::::::::::::
@echo off
CLS 
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:checkPrivileges 
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges ) 

:getPrivileges 
if '%1'=='ELEV' (shift & goto gotPrivileges)  
ECHO. 
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation 
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs" 
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs" 
"%temp%\OEgetPrivileges.vbs" 
exit /B 

:gotPrivileges 
:::::::
:START:
:::::::
setlocal & pushd .
@echo off

:: Get ADMIN Privs
:-------------------------------------
mkdir "%windir%\BatchGotAdmin"
if '%errorlevel%' == '0' (
  rmdir "%windir%\BatchGotAdmin" & goto gotAdmin 
) else ( goto UACPrompt )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute %0, "", "", "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"
:-------------------------------------
:: End Get ADMIN Privs
@echo off
Title  Baseline Out of Box - Server Config
Color F
type RequiredFiles\header.txt
pause
cls
echo 3
ping localhost -n 2 > nul
cls
echo 3.
ping localhost -n 2 > nul
cls
echo 3..
ping localhost -n 2 > nul
cls
echo 3..2
ping localhost -n 2 > nul
cls
echo 3..2.
ping localhost -n 2 > nul
cls
echo 3..2..
ping localhost -n 2 > nul
cls
echo 3..2..1
ping localhost -n 2 > nul
cls
echo Liftoff
ping localhost -n 2 > nul
cls
echo Creating Users - Admin - Adding New Users to
echo Administrators and Remote Desktop User Groups
ping localhost -n 4 > nul
net user Admin  /ADD
net user  /ADD
net localgroup "Remote Desktop Users" Admin /add
net localgroup "Remote Desktop Users" /add
net localgroup "Administrators" Admin /add
net localgroup "Administrators"  /add
pause
cls
type RequiredFiles\text1.txt
ping localhost -n 2 > nul
cls
type RequiredFiles\text2.txt
ping localhost -n 2 > nul
cls
type RequiredFiles\text3.txt
ping localhost -n 2 > nul
pause
netsh interface set interface name = "Local Area Connection" newname = "Outside"
echo Local Area Connection has been changed to "Outside"
echo Now, minion, configure it's IP
echo.
echo.
echo Choose:
echo [Static] Set Static IP
echo [Dynamic] Set DHCP
echo.
:choice
SET /P C=[Static,Dynamic]?
for %%? in (Static) do if /I "%C%"=="%%?" goto Static
for %%? in (Dynamic) do if /I "%C%"=="%%?" goto Dynamic
goto choice
:Static
@echo off
echo "Please enter Static IP Address Information"
echo "Static IP Address:"
set /p IP_Addr=
echo.
echo "Default Gateway:"
set /p D_Gate=
echo.
echo "Subnet Mask:"
set /p Sub_Mask=
echo.
echo "DNS being configured to Google Public"
netsh interface ip set dns name="Outside" source=static addr=8.8.8.8

echo "Setting Static IP Information"
netsh interface ip set address "Outside" static %IP_Addr% %Sub_Mask% %D_Gate% 1
ping localhost -n 4 > nul
Echo Your New IP Settings
echo.
netsh int ip show config
pause
cls
goto interface2

:Dynamic
@ECHO OFF
ECHO Resetting IP Address and Subnet Mask For DHCP
netsh int ip set address name = "Outside" source = dhcp

ipconfig /renew

ECHO Here are the new settings for %computername%:
netsh int ip show config

pause
cls
goto interface2
:interface2

netsh interface set interface name = "Local Area Connection 2" newname = "Storage"
echo Local Area Connection 2 has been changed to "Storage"
echo Now, minion, configure it's IP....again
echo.
echo.
echo Choose:
echo [Static] Set Static IP
echo [Dynamic] Set DHCP
echo.
:choice
SET /P C=[Static,Dynamic]?
for %%? in (Static) do if /I "%C%"=="%%?" goto Static
for %%? in (Dynamic) do if /I "%C%"=="%%?" goto Dynamic
goto choice
:Static
@echo off
echo "Please enter Static IP Address Information"
echo "Static IP Address:"
set /p IP_Addr=
echo.
echo "Default Gateway:"
set /p D_Gate=
echo.
echo "Subnet Mask:"
set /p Sub_Mask=

echo "Setting Static IP Information"
netsh interface ip set address "Storage" static %IP_Addr% %Sub_Mask% %D_Gate% 1
ping localhost -n 4 > nul
cls
Echo Your New IP Settings
echo.
netsh int ip show config
pause
goto next

:Dynamic
@ECHO OFF
ECHO Resetting IP Address and Subnet Mask For DHCP
netsh int ip set address name = "LAN" source = dhcp

ipconfig /renew

Echo Your New IP Settings
echo.
netsh int ip show config
pause
goto next

:next
cls
echo Disabling Firewall
netsh advfirewall set allprofiles state off
msg * "WARNING - All Firewall Profiles Have Been Disabled"
ping localhost -n 4 > nul
pause
goto changename

:changename
cls
@echo off
SET /P PCNAME=Please enter desired computer name: 
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d %PCNAME% /f
ping localhost -n 4 > nul
pause
goto enableremote

:enableremote
cls
Echo Enabling Remote Desktop
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
ping localhost -n 4 > nul
pause
goto logmein

:logmein
cls
echo Installing LogMeIn - Please Follow Installer
msiexec /i RequiredFiles\LogMeIn.msi
echo LogMeIn Installer Has Finished
pause
goto genetec

:genetec
cls
echo Installing Genetec Security Center - Please Follow Installer
start /wait RequiredFiles\Genetec\Full\setup.exe
echo Genetec Installer Has Finished
pause
goto finished

:finished
cls
echo Out of Box Configuration Complete
msg * "Out of Box Configuration Complete"
ping localhost -n 2 > nul
cls
type RequiredFiles\end.txt
ping localhost -n 2 > nul
exit

1 个答案:

答案 0 :(得分:0)

以管理员身份运行时,工作目录会更改。

full path用于文本文件或使用%~dp0的变量来获取批处理文件的路径。