forked from brianfgonzalez/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall_Drivers_v3.txt
104 lines (95 loc) · 8.71 KB
/
Install_Drivers_v3.txt
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
'==========================================================================
'
' NAME: Install_Drivers_v2.vbs
'
' AUTHOR: Brian Gonzalez, PSCNA
' DATE : 10/9/2012
'
' COMMENT:
' Pulls model number and then installs all drvrs/utils from subfolders if
' matching model pre-fix is found.
'==========================================================================
On Error Resume Next
'Setup common objects
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("Wscript.Network")
strLogFilePath = "C:\Windows\Temp\Pana_Install_Drivers.log"
strTempFolder = objShell.ExpandEnvironmentStrings("%Temp%")
'Populate var with current directory
strScriptFolder = objFSO.GetParentFolderName(Wscript.ScriptFullName) 'No trailing backslash
'Ensure script is being run locally
strQuery = "SELECT * FROM Win32_LogicalDisk WHERE DeviceID LIKE '" & Left(strScriptFolder, 2) & "'"
'Run query against Drive Letter pulled from strScriptFolder var
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery(strQuery, "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strDiskDescription = objItem.Description
Next
'Check if Drive Letter is a local fixed disk and not a mapped drive
If Not strDiskDescription = "Local Fixed Disk" Then
logHelper "Script needs to be run locally, so copy routine is beginning..."
Wscript.Echo "Script needs to be run locally, so copy routine is beginning..."
objFSO.CopyFolder strScriptFolder, "C:\Drivers", True
logHelper "Copy is complete, now kicking off copied script (C:\Drivers\Install_Drivers.vbs)..."
Wscript.Echo "Copy is complete, now kicking off copied script (C:\Drivers\Install_Drivers.vbs)..."
sRet = objShell.Run("cscript.exe //NoLogo C:\Drivers\" & Wscript.ScriptName, 3, True)
WScript.Quit
End If
'////Main Execution/////
'=====================================================
'Enumerate through the drivers subfolder
strDriverParentFolder = strScriptFolder & "\src"
If objFSO.FolderExists(strDriverParentFolder) Then
'Set up object for driver folder to utilize SubFolders collection attrib
Set objDriverParentFolder = objFSO.GetFolder(strDriverParentFolder)
'Cycle through sub-folders and execute "PInstall.bat" files within directories, if avail.
For Each fol In objDriverParentFolder.SubFolders
'Ignore "99" pre-fixed directories as they are predetermined as optional
If Not Left(fol.name, 2) = "99" Then
strPNPIDTxtPath = fol.path & "\pnpid.txt"
PNPIDMismatch = ""
If objFSO.FileExists(strPNPIDTxtPath) Then
'PNPID text file found, reading file
Set objPNPIDTxtFile = objFSO.OpenTextFile(strPNPIDTxtPath)
strpnpid = objPNPIDTxtFile.ReadAll
logHelper "PNPID file found for: " & strpnpid
If PNPMatch(strpnpid) = 0 Then 'No matches found
logHelper "PNPID NOT found in WMI database"
PNPIDMismatch = True
End If
End If
strPInstallPath = fol.path & "\pinstall.bat"
'Check if "PInstall.bat" file inside subfolder exists.
If objFSO.FileExists(strPInstallPath) And Not PNPIDMismatch = True Then
'It does exist, so set "CurrentDirectory" to driver folder
objShell.CurrentDirectory = fol.path
logHelper "Executing: " & fol.path & "\pinstall.bat"
Wscript.Echo "Executing: " & fol.path & "\pinstall.bat"
sRet = objShell.Run("cmd /c pinstall.bat", 2, True)
logHelper "Completed executing and returned: " & sRet
End If
Else
logHelper "Ignoring install: " & fol.path
Wscript.Echo "Ignoring install: " & fol.path
End If
Next
Else
'No model pre-fixed subfolder was found. Exiting script.
loghelper "Utility and driver folder does not exist (""" & strDriverParentFolder & """) . Exiting Script."
WScript.Quit
End If
loghelper "Image configuration is complete."
Sub logHelper(strText)
If Not IsObject(objLogFile) Then
Set objLogFile = objFSO.OpenTextFile(strLogFilePath, ForAppending, True)
End If
objLogFile.WriteLine(Time & ": " & strText)
End Sub
Function PNPMatch(strPNPDeviceID)
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%" & strPNPDeviceID & "%'")
PNPMatch = colItems.Count
End Function