1 | @echo off
|
---|
2 | REM $Id: comregister.cmd 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 | REM
|
---|
4 | REM Script to register the VirtualBox COM classes
|
---|
5 | REM (both inproc and out-of-process)
|
---|
6 | REM
|
---|
7 |
|
---|
8 | REM
|
---|
9 | REM Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
10 | REM
|
---|
11 | REM This file is part of VirtualBox base platform packages, as
|
---|
12 | REM available from https://www.virtualbox.org.
|
---|
13 | REM
|
---|
14 | REM This program is free software; you can redistribute it and/or
|
---|
15 | REM modify it under the terms of the GNU General Public License
|
---|
16 | REM as published by the Free Software Foundation, in version 3 of the
|
---|
17 | REM License.
|
---|
18 | REM
|
---|
19 | REM This program is distributed in the hope that it will be useful, but
|
---|
20 | REM WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | REM General Public License for more details.
|
---|
23 | REM
|
---|
24 | REM You should have received a copy of the GNU General Public License
|
---|
25 | REM along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | REM
|
---|
27 | REM SPDX-License-Identifier: GPL-3.0-only
|
---|
28 | REM
|
---|
29 |
|
---|
30 | setlocal
|
---|
31 |
|
---|
32 | REM Check if the current user is an administrator. Otherwise
|
---|
33 | REM all the COM registration will fail silently.
|
---|
34 | NET FILE 1>NUL 2>NUL & IF ERRORLEVEL 1 (ECHO Must be run as Administrator. Exiting.) & GOTO end
|
---|
35 |
|
---|
36 | REM
|
---|
37 | REM Figure out where the script lives first, so that we can invoke the
|
---|
38 | REM correct VBoxSVC and register the right VBoxC.dll.
|
---|
39 | REM
|
---|
40 |
|
---|
41 | REM Determine the current directory.
|
---|
42 | set _SCRIPT_CURDIR=%CD%
|
---|
43 | for /f "tokens=*" %%d in ('cd') do set _SCRIPT_CURDIR=%%d
|
---|
44 |
|
---|
45 | REM Determine a correct self - by %0.
|
---|
46 | set _SCRIPT_SELF=%0
|
---|
47 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
48 | set _SCRIPT_SELF=%_SCRIPT_SELF%.cmd
|
---|
49 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
50 |
|
---|
51 | REM Determine a correct self - by current working directory.
|
---|
52 | set _SCRIPT_SELF=%_SCRIPT_CURDIR%\comregister.cmd
|
---|
53 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
54 |
|
---|
55 | REM Determine a correct self - by the PATH
|
---|
56 | REM This is very verbose because nested for loops didn't work out.
|
---|
57 | for /f "tokens=1 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
58 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
59 | for /f "tokens=2 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
60 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
61 | for /f "tokens=3 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
62 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
63 | for /f "tokens=4 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
64 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
65 | for /f "tokens=5 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
66 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
67 | for /f "tokens=6 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
68 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
69 | for /f "tokens=7 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
70 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
71 | for /f "tokens=8 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
72 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
73 | for /f "tokens=9 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
74 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
75 | for /f "tokens=10 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
76 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
77 | for /f "tokens=11 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
78 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
79 | for /f "tokens=12 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
80 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
81 | for /f "tokens=13 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
82 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
83 | for /f "tokens=14 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
84 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
85 | for /f "tokens=15 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
86 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
87 | for /f "tokens=16 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
88 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
89 | for /f "tokens=17 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
90 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
91 | for /f "tokens=18 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
92 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
93 | for /f "tokens=19 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
94 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
95 | for /f "tokens=20 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
|
---|
96 | if exist "%_SCRIPT_SELF%" goto found_self
|
---|
97 | echo Warning: Not able to determin the comregister.cmd location.
|
---|
98 | set _VBOX_DIR=
|
---|
99 | goto register
|
---|
100 |
|
---|
101 | :found_self
|
---|
102 | set _VBOX_DIR=
|
---|
103 | cd "%_SCRIPT_SELF%\.."
|
---|
104 | for /f "tokens=*" %%d in ('cd') do set _VBOX_DIR=%%d\
|
---|
105 | cd "%_SCRIPT_CURDIR%"
|
---|
106 |
|
---|
107 | REM
|
---|
108 | REM Check for 64-bitness.
|
---|
109 | REM
|
---|
110 | set fIs64BitWindows=0
|
---|
111 | if not "%ProgramW6432%x" == "x" set fIs64BitWindows=1
|
---|
112 | if exist "%windir\syswow64\kernel32.dll" set fIs64BitWindows=1
|
---|
113 |
|
---|
114 | REM
|
---|
115 | REM Figure out the Windows version as the proxy stub requires 6.0 or later (at least for 64-bit).
|
---|
116 | REM
|
---|
117 | set WinVer=Version 4.0.1381
|
---|
118 | set WinVerMajor=4
|
---|
119 | set WinVerMinor=0
|
---|
120 | set WinVerBuild=1381
|
---|
121 | for /f "tokens=2 delims=[]" %%a in ('ver') do set WinVer=%%a
|
---|
122 | for /f "tokens=2,3,4 delims=. " %%a in ("%WinVer%") do (
|
---|
123 | set WinVerMajor=%%a
|
---|
124 | set WinVerMinor=%%b
|
---|
125 | set WinVerBuild=%%c
|
---|
126 | )
|
---|
127 | REM echo WinVerMajor=%WinVerMajor% WinVerMinor=%WinVerMinor% WinVerBuild=%WinVerBuild% WinVer=%WinVer%
|
---|
128 |
|
---|
129 | REM
|
---|
130 | REM Parse arguments.
|
---|
131 | REM
|
---|
132 | set fNoProxy=0
|
---|
133 | set fUninstallOnly=0
|
---|
134 |
|
---|
135 | :arg_loop
|
---|
136 | if "%1x" == "x" goto arg_done
|
---|
137 |
|
---|
138 | if "%1" == "-u" goto arg_uninstall
|
---|
139 | if "%1" == "--uninstall" goto arg_uninstall
|
---|
140 | if "%1" == "--proxy" goto arg_proxy
|
---|
141 | if "%1" == "--no-proxy" goto arg_no_proxy
|
---|
142 | echo syntax error: Unknown option %1
|
---|
143 | echo usage: comregister.cmd [-u,--uninstall] [--no-proxy] [--proxy]
|
---|
144 | goto end
|
---|
145 |
|
---|
146 | :arg_uninstall
|
---|
147 | set fUninstallOnly=1
|
---|
148 | goto arg_next
|
---|
149 |
|
---|
150 | :arg_proxy
|
---|
151 | set fNoProxy=0
|
---|
152 | goto arg_next
|
---|
153 |
|
---|
154 | :arg_no_proxy
|
---|
155 | set fNoProxy=1
|
---|
156 | goto arg_next
|
---|
157 |
|
---|
158 | :arg_next
|
---|
159 | shift
|
---|
160 | goto arg_loop
|
---|
161 | :arg_done
|
---|
162 |
|
---|
163 | REM
|
---|
164 | REM Do the registrations.
|
---|
165 | REM
|
---|
166 | @if %fIs64BitWindows% == 1 goto register_amd64
|
---|
167 |
|
---|
168 | :register_x86
|
---|
169 | @echo on
|
---|
170 | "%_VBOX_DIR%VBoxSVC.exe" /UnregServer
|
---|
171 | regsvr32 /s /u "%_VBOX_DIR%VBoxC.dll"
|
---|
172 | %windir%\system32\regsvr32 /s /u "%_VBOX_DIR%VBoxProxyStub.dll"
|
---|
173 | @if %fUninstallOnly% == 1 goto end
|
---|
174 | "%_VBOX_DIR%VBoxSVC.exe" /RegServer
|
---|
175 | "%_VBOX_DIR%VBoxSDS.exe" /RegService
|
---|
176 | regsvr32 /s "%_VBOX_DIR%VBoxC.dll"
|
---|
177 | @if %fNoProxy% == 1 goto end
|
---|
178 | if exist "%_VBOX_DIR%VBoxProxyStub.dll" %windir%\system32\regsvr32 /s "%_VBOX_DIR%VBoxProxyStub.dll"
|
---|
179 | @echo off
|
---|
180 | goto end
|
---|
181 |
|
---|
182 | REM Unregister all first, then register them. The order matters here.
|
---|
183 | :register_amd64
|
---|
184 | if "%WinVerMajor%" == "5" goto register_amd64_legacy
|
---|
185 | if not "%WinVerMajor%" == "6" goto register_amd64_not_legacy
|
---|
186 | if not "%WinVerMinor%" == "0" goto register_amd64_not_legacy
|
---|
187 | :register_amd64_legacy
|
---|
188 | set s64BitProxyStub=VBoxProxyStubLegacy.dll
|
---|
189 | goto register_amd64_begin
|
---|
190 | :register_amd64_not_legacy
|
---|
191 | set s64BitProxyStub=VBoxProxyStub.dll
|
---|
192 | :register_amd64_begin
|
---|
193 | echo s64BitProxyStub=%s64BitProxyStub%
|
---|
194 | @echo on
|
---|
195 | "%_VBOX_DIR%VBoxSVC.exe" /UnregServer
|
---|
196 | "%_VBOX_DIR%VBoxSDS.exe" /UnregService
|
---|
197 | %windir%\system32\regsvr32 /s /u "%_VBOX_DIR%VBoxC.dll"
|
---|
198 | %windir%\syswow64\regsvr32 /s /u "%_VBOX_DIR%x86\VBoxClient-x86.dll"
|
---|
199 | %windir%\system32\regsvr32 /s /u "%_VBOX_DIR%%s64BitProxyStub%"
|
---|
200 | %windir%\syswow64\regsvr32 /s /u "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll"
|
---|
201 | if %fUninstallOnly% == 1 goto end
|
---|
202 | "%_VBOX_DIR%VBoxSVC.exe" /RegServer
|
---|
203 | "%_VBOX_DIR%VBoxSDS.exe" /RegService
|
---|
204 | %windir%\system32\regsvr32 /s "%_VBOX_DIR%VBoxC.dll"
|
---|
205 | %windir%\syswow64\regsvr32 /s "%_VBOX_DIR%x86\VBoxClient-x86.dll"
|
---|
206 | if %fNoProxy% == 1 goto end
|
---|
207 | if exist "%_VBOX_DIR%%s64BitProxyStub%" %windir%\system32\regsvr32 /s "%_VBOX_DIR%%s64BitProxyStub%"
|
---|
208 | if exist "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll" %windir%\syswow64\regsvr32 /s "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll"
|
---|
209 | @echo off
|
---|
210 |
|
---|
211 | :end
|
---|
212 | @endlocal
|
---|