-
Notifications
You must be signed in to change notification settings - Fork 37
/
vs_find.vbs
210 lines (191 loc) · 4.82 KB
/
vs_find.vbs
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
Option Explicit
Function GetVsVersion()
dim regk ,regv,regobj,regarr,c
regk = "HKEY_CLASSES_ROOT\VisualStudio.DTE\CurVer\"
regv = ReadReg(regk)
if IsEmpty(regv) Then
GetVsVersion=""
Exit Function
End If
set regobj = CreateObject("VBScript.RegExp")
regobj.Global = True
regobj.IgnoreCase = True
regobj.Pattern = "[\d]+\.[\d]+"
set regarr = regobj.Execute(regv)
for each c in regarr
set regarr = Nothing
set regobj = Nothing
GetVsVersion=c
Exit Function
Next
GetVsVersion=""
End Function
Function GetDevenvCom()
dim regkey,regval
dim regobj
regkey="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe\"
regval=ReadReg(regkey)
if IsEmpty(regval) Then
GetDevenvCom=Empty
Exit Function
End If
set regobj = CreateObject("VBScript.RegExp")
regobj.Global = True
regobj.IgnoreCase = True
regobj.Pattern = "^" & chr(34)
regval = regobj.Replace(regval,"")
regobj.Pattern = chr(34) & "$"
regval = regobj.Replace(regval,"")
regobj.Pattern = "\.exe$"
regval=regobj.Replace(regval,".com")
set regobj = Nothing
GetDevenvCom=regval
End Function
Function CheckInstallBasedir(directory)
dim narr,i,j,num,sp,ret,clexe
narr = Split(directory,"\")
if IsArray(narr) Then
num=Ubound(narr)
i=num
j=1
sp=narr(0)
While j < (i+1)
clexe=sp & "\Common7\IDE\devenv.exe"
ret=FileExists(clexe)
if ret Then
CheckInstallBasedir=sp
Exit Function
End If
sp = sp & "\" & narr(j)
j = j+1
Wend
End If
CheckInstallBasedir=Empty
End Function
Function IsInstallVisualStudio(version)
dim curval
dim curver
dim instdir
dim versions
dim values
dim idx
dim max
dim devcom
dim getversion
versions=Array(16.0,15.0,14.0,12.0)
values=Array("16.0","15.0","14.0","12.0")
devcom=GetDevenvCom()
if IsEmpty(devcom) Then
' nothing to get ,so we return error
IsInstallVisualStudio=Null
Exit Function
End If
'WScript.Stderr.writeline("devcom[" & devcom &"]")
' now get the version
getversion = GetVsVersion()
if Len(getversion) <= 0 Then
IsInstallVisualStudio=Null
Exit Function
End If
getversion=CDbl(getversion)
idx = 0
max = Ubound(versions) + 1
Do while idx < max
curver = versions(idx)
curval = values(idx)
If curver >= (getversion-0.01) and curver <= (getversion + 0.01) and (version) <= (getversion) Then
instdir=CheckInstallBasedir(devcom)
if not IsEmpty(instdir) Then
IsInstallVisualStudio=curval
Exit Function
End If
End If
idx = idx + 1
Loop
IsInstallVisualStudio=Null
End Function
Function GetVisualStudioInstdir(version)
dim curval
dim curver
dim instdir
dim versions
dim values
dim idx
dim max
dim devcom
dim getversion
versions=Array(16.0,15.0,14.0,12.0)
devcom=GetDevenvCom()
if IsEmpty(devcom) Then
' nothing to get ,so we return error
GetVisualStudioInstdir=Null
Exit Function
End If
instdir=CheckInstallBasedir(devcom)
if not IsEmpty(instdir) Then
GetVisualStudioInstdir=instdir
Exit Function
End If
GetVisualStudioInstdir=Null
End Function
Function GetNmake(basedir,vsver)
dim msvcdir
dim curdir
dim fso
dim i,max
dim reads
dim arrdir
dim curfile
if vsver = "12.0" or vsver = "14.0" Then
curfile = basedir & "\VC\bin\nmake.exe"
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(curfile) Then
GetNmake=curfile
set fso = Nothing
Exit Function
End If
GetNmake=Empty
ElseIf vsver = "15.0" or vsver = "16.0" Then
msvcdir= basedir & "\VC\Tools\MSVC"
reads = ReadDir(msvcdir)
arrdir = Split(reads,";")
i = 0
max = Ubound(arrdir) + 1
Set fso = CreateObject("Scripting.FileSystemObject")
Do While i < max
curdir = arrdir(i)
curfile = curdir & "\bin\Hostx64\x64\nmake.exe"
if fso.FileExists(curfile) Then
set fso = Nothing
GetNmake=curfile
Exit Function
End If
i = i + 1
Loop
set fso = Nothing
GetNmake=empty
Else
GetNmake=empty
End If
End Function
Function GetVsAllBatchCall(vsver,basedir,compiletarget)
dim cmdline
cmdline=""
if vsver = "12.0" or vsver = "14.0" Then
cmdline="Call " & chr(34) & basedir & "\VC\vcvarsall.bat" & chr(34) & " " & compiletarget & " >NUL"
Else
if compiletarget = "amd64" Then
cmdline="call " & chr(34) & basedir & "\VC\Auxiliary\Build\vcvarsall.bat" & chr(34) & " x64" & " >NUL"
ElseIf compiletarget = "amd64_x86" Then
cmdline = "call " & chr(34) & basedir & "\VC\Auxiliary\Build\vcvarsall.bat" & chr(34) & " x64_x86" & " >NUL"
Else
WScript.Stderr.writeline("not supported compiletarget[" & compiletarget & "]")
End If
End If
GetVsAllBatchCall=cmdline
End Function
Function GetDevenvSlnRun(vsver,slnfile,basedir,target)
dim cmdline
cmdline = chr(34) & basedir & "\Common7\IDE\devenv.exe" & chr(34) & " " & chr(34) & slnfile & chr(34) & " /useenv /build " & chr(34) & target & chr(34)
GetDevenvSlnRun=cmdline
End Function