Bootstrapping Windows
Feb 10, 2011
Finding myself back in the Windows domain I really miss package repository tools like YUM and apt-get. In what seems eons ago I used a toolset called Unattended for windows installations. It’s a little rough around the edges but it gave me some interesting ideas. I put together a quick script to download some common tools I find myself using on windows servers.
Here’s the general code cobbled together;
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
Const BINARY = 1
Const SAVE_CREATE_OVERWRITE = 2
Const SAVE_CREATE_NOT_EXIST = 1
Const ERR_DOWNLOAD_FILE_UNAVAILABLE = -1
Const ERR_DOWNLOAD_FILE_UNSAVABLE = -2
temp = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2).Path & "\"
Dim http, WshShell, file_stream
Set WshShell = WScript.CreateObject("WScript.Shell")
download_file "http://javadl.sun.com/webapps/download/AutoDL?BundleId=44457", "jre.exe"
WshShell.Run temp & "jre.exe /s /v ""/qn ADDLOCAL=ALL IEXPLORER=1""", 1, TRUE
' JRE
' Download a file to the temp folder and specified filename.
'
'
Function download_file(src, dest)
' TODO: Add better error handling for http and file handles.
Set http = CreateObject("MSXML2.ServerXMLHTTP")
If IsNull(http) Then
WScript.Echo "Microsoft.XmlHttp creation failed"
End If
http.open "GET", src, FALSE
http.send
Set file_stream = CreateObject("Adodb.Stream")
file_stream.type = BINARY
file_stream.open
file_stream.write http.responseBody
file_stream.saveToFile temp & dest, SAVE_CREATE_OVERWRITE
file_stream.close
Set file_stream = nothing
Set http = nothing
End Function
tags: [ powershell ]