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