-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CreateNewUSB.bat
280 lines (248 loc) · 7.41 KB
/
CreateNewUSB.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
:runasadmin
@echo off
cls
:checkforadminrights
if "%1"=="elevate" (
shift
goto :haverights
)
net file >nul 2>&1
if %errorlevel%==0 (
goto :haverights
) else (
goto :getrights
)
:getrights
echo set uac = createobject("shell.application") > %temp%\getrights.vbs
echo uac.shellexecute "%~0",elevate,,"runas" >> "%temp%\getrights.vbs"
"%temp%\getrights.vbs"
exit
:haverights
@echo on
:runasadmin
@echo off
color 1e
mode con: cols=31 lines=23
echo.
echo ****** ******
echo **** ****
echo *** *********** ***
echo ** *************** **
echo * ******************* *
echo * **** **** *
echo *** ******* ***
echo *** ********* ***
echo *** *** *** ***
echo *** ** ** ***
echo *Bright House Networks*
echo *** ** ** ***
echo *** *** *** ***
echo *** ******** ***
echo *** ******* ***
echo * **** **** *
echo * ******************* *
echo ** *************** **
echo *** *********** ***
echo **** ****
echo ****** ******
ping 127.0.0.1 >nul
color 07
mode con: cols=79 lines=13
set retry=0
color 0c
echo ******************************************************************************
echo ******************************************************************************
echo ******************************************************************************
echo ******************************************************************************
echo ******************************************************************************
echo * Ensure that the flash drive that you want to make bootable is the only USB *
echo ********************* drive plugged into your computer!! *********************
echo ******************************************************************************
echo ******************************************************************************
echo ******************************************************************************
echo ******************************************************************************
echo ******************************************************************************
pause
mode con: cols=150 lines=25
:existingdrives
setlocal ENABLEDELAYEDEXPANSION
set letter=abfghijklmnopqrstuvwxyz
for /l %%d in (1,1,23) do (
set dletter=!letter:~0,1!
set letter=!letter:~1,23!
if not exist !dletter!: (
goto :drivescan
)
)
setlocal disabledelayedexpansion
Echo No drives to use!
goto :eof
:drivescan
cls
color 07
echo.
echo.
echo Scanning disk drives...
setlocal enabledelayedexpansion
for /F "tokens=2 delims=PHYSICALDRIVE" %%s in ('wmic diskdrive get deviceid ^| find "PHYSICALDRIVE"') do (
set drive=%%s
echo select disk !drive! >%temp%\diskscript.txt
echo detail disk >>%temp%\diskscript.txt
for /F "tokens=2 delims=:" %%t in ('diskpart /s %temp%\diskscript.txt ^| find "USB" /i') do (
set type=%%t
if !type! == ^ USB goto :USB
)
)
echo.
echo.
setlocal disabledelayedexpansion
call :cecho 0c "No USB drives detected! Please make sure your USB drive is plugged in and works."
pause
if %retry% == 3 goto:eof
set /a retry=%retry%+1
goto :drivescan
:USB
for /F "tokens=1 delims=:" %%n in ('diskpart /s %temp%\diskscript.txt ^| find "USB Device" /i') do (
set diskname=%%n
)
echo.
echo.
call :cecho 0c "All data on %diskname% will be erased" /nb
setlocal disabledelayedexpansion
call :cecho 0c "! Are you sure you want to proceed? [Y,N]"
setlocal enabledelayedexpansion
set bootablefiles=\\tamp20pvfiler09\SHARE1\Installs\HofmanniaStudios\Imaging\USB
set /p confirmation=
If /i %confirmation%==y (
echo.
echo.
echo Creating bootable flash drive...
echo select disk %drive% >%temp%\diskscript.txt
echo clean >>%temp%\diskscript.txt
echo create partition primary >>%temp%\diskscript.txt
echo format fs=ntfs quick >>%temp%\diskscript.txt
echo active >>%temp%\diskscript.txt
echo assign letter=%dletter% >>%temp%\diskscript.txt
diskpart /s %temp%\diskscript.txt
ping 127.0.0.1 >nul
robocopy "!bootablefiles!" %dletter%:\ * /e /z /is /v /nc /njh /njs
ping 127.0.0.1 >nul
echo.
echo.
setlocal disabledelayedexpansion
echo.
echo.
call :cecho 0a "Bootable flash drive creation complete!"
echo.
echo.
) else (
goto :eof
)
pause
exit
:cecho <color> <string> </nb>
@rem Created by Hofmannia Studios 2015
@rem All rights reserved and other fake legal sounding stuff...
rem @echo off
rem Setting variables.
set colvar=%~1
set stringvar=%~2
rem Help functionality.
if "%~1"=="/?" (
call :helptext
set ERRORLEVEL=0
goto :eof
)
rem Start defining cecho errors.
if not defined %colvar (
call :colorerror
set ERRORLEVEL=1
goto :eof
)
if not "%colvar%"=="%colvar:~0,2%" (
call :colorerror
set ERRORLEVEL=1
goto :eof
)
if "%colvar:~1,1%"=="" (
call :colorerror
set ERRORLEVEL=1
goto :eof
)
if "%colvar%" NEQ "/?" if not defined stringvar (
call :stringerror
set ERRORLEVEL=1
goto :eof
)
rem End defining cecho errors.
rem Find length of this file's name.
setlocal enableDelayedExpansion
(
set "s=%~nx0#"
set "len=0"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "s=!s:~%%P!"
)
)
)
(
endlocal
set "namelength=%len%"
)
set /a namelength=%namelength%+6
rem Create a variable containing a backspace character.
for /F "tokens=1 delims=#" %%a in ('"prompt #$H# & echo on & for %%b in (1) do rem"') do set "delchar=%%a"
rem Use findstr to search this file and nul and display lines consisting of "-" with our string and "\..\" appended at the start of the output. All output will be colored based on our color code.
pushd %~dp0
findstr /p /r /a:%~1 "^-" "%~2\..\%~nx0" nul
popd
rem Delete the name of this file, "\..\", and ":-" from the output.
for /l %%n in (1,1,%namelength%) do <nul set /p "=%delchar%"
endlocal
rem Add a line break if nb switch was not used.
if not "%~3"=="/nb" echo.
goto :eof
:colorerror
echo color must be in 2 digit hex format!
goto :eof
:stringerror
echo string is required!
goto :eof
:helptext
echo Usage: Displays text in a specified color.
echo.
echo cecho color string [/nb]
echo.
echo color Specifies color attribute with two hex digits. See "color /?"
echo.
echo string The text to be displayed. Text containing spaces must be placed
echo within quotation marks.
echo.
echo [/nb] Optional. Removes the line break after the text. The next
echo command will display on the same line.
echo.
echo Example:
echo.
echo cecho 0b Hello
echo.
echo Would display the text "Hello" with a black background
echo and light aqua font and then proceed to the next line.
echo.
call :cecho 0b " Hello"
echo.
echo cecho 20 "This is" /nb ^& cecho 02 "a test" /nb ^& cecho 20 "of cecho"
echo.
echo Would display the text "This is a test of cecho" on one line with
echo "This is" and "of cecho" in black text on a green background, and
echo "a test" in green text on a black background, then proceed to the
echo next line.
echo.
call :cecho 00 " " /nb & call :cecho 20 "This is" /nb & call :cecho 02 "a test" /nb & call :cecho 20 "of cecho"
echo.
echo.
pause
goto :eof
rem The last line of this file must consist of simply "-"!
-