summaryrefslogtreecommitdiffstats
path: root/src/VBox/Main/src-all/win/comregister.cmd
blob: 31cab3442eee3bd3b8bd5d97a94cf592440a886e (plain)
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
211
212
@echo off
REM $Id: comregister.cmd $
REM
REM Script to register the VirtualBox COM classes
REM (both inproc and out-of-process)
REM

REM
REM Copyright (C) 2006-2023 Oracle and/or its affiliates.
REM
REM This file is part of VirtualBox base platform packages, as
REM available from https://www.virtualbox.org.
REM
REM This program is free software; you can redistribute it and/or
REM modify it under the terms of the GNU General Public License
REM as published by the Free Software Foundation, in version 3 of the
REM License.
REM
REM This program is distributed in the hope that it will be useful, but
REM WITHOUT ANY WARRANTY; without even the implied warranty of
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
REM General Public License for more details.
REM
REM You should have received a copy of the GNU General Public License
REM along with this program; if not, see <https://www.gnu.org/licenses>.
REM
REM SPDX-License-Identifier: GPL-3.0-only
REM

setlocal

REM Check if the current user is an administrator. Otherwise
REM all the COM registration will fail silently.
NET FILE 1>NUL 2>NUL & IF ERRORLEVEL 1 (ECHO Must be run as Administrator. Exiting.) & GOTO end

REM
REM Figure out where the script lives first, so that we can invoke the
REM correct VBoxSVC and register the right VBoxC.dll.
REM

REM Determine the current directory.
set _SCRIPT_CURDIR=%CD%
for /f "tokens=*" %%d in ('cd') do set _SCRIPT_CURDIR=%%d

REM Determine a correct self - by %0.
set _SCRIPT_SELF=%0
if exist "%_SCRIPT_SELF%" goto found_self
set _SCRIPT_SELF=%_SCRIPT_SELF%.cmd
if exist "%_SCRIPT_SELF%" goto found_self

REM Determine a correct self - by current working directory.
set _SCRIPT_SELF=%_SCRIPT_CURDIR%\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self

REM Determine a correct self - by the PATH
REM This is very verbose because nested for loops didn't work out.
for /f "tokens=1  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=2  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=3  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=4  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=5  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=6  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=7  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=8  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=9  delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=10 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=11 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=12 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=13 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=14 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=15 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=16 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=17 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=18 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=19 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
for /f "tokens=20 delims=;" %%d in ("%PATH%") do set _SCRIPT_SELF=%%d\comregister.cmd
if exist "%_SCRIPT_SELF%" goto found_self
echo Warning: Not able to determin the comregister.cmd location.
set _VBOX_DIR=
goto register

:found_self
set _VBOX_DIR=
cd "%_SCRIPT_SELF%\.."
for /f "tokens=*" %%d in ('cd') do set _VBOX_DIR=%%d\
cd "%_SCRIPT_CURDIR%"

REM
REM Check for 64-bitness.
REM
set fIs64BitWindows=0
if not "%ProgramW6432%x" == "x" set fIs64BitWindows=1
if exist "%windir\syswow64\kernel32.dll" set fIs64BitWindows=1

REM
REM Figure out the Windows version as the proxy stub requires 6.0 or later (at least for 64-bit).
REM
set WinVer=Version 4.0.1381
set WinVerMajor=4
set WinVerMinor=0
set WinVerBuild=1381
for /f "tokens=2 delims=[]" %%a in ('ver') do set WinVer=%%a
for /f "tokens=2,3,4 delims=. " %%a in ("%WinVer%") do (
    set WinVerMajor=%%a
    set WinVerMinor=%%b
    set WinVerBuild=%%c
)
REM echo WinVerMajor=%WinVerMajor% WinVerMinor=%WinVerMinor% WinVerBuild=%WinVerBuild%  WinVer=%WinVer%

REM
REM Parse arguments.
REM
set fNoProxy=0
set fUninstallOnly=0

:arg_loop
if "%1x" == "x"             goto arg_done

if "%1" == "-u"             goto arg_uninstall
if "%1" == "--uninstall"    goto arg_uninstall
if "%1" == "--proxy"        goto arg_proxy
if "%1" == "--no-proxy"     goto arg_no_proxy
echo syntax error: Unknown option %1
echo usage: comregister.cmd [-u,--uninstall] [--no-proxy] [--proxy]
goto end

:arg_uninstall
set fUninstallOnly=1
goto arg_next

:arg_proxy
set fNoProxy=0
goto arg_next

:arg_no_proxy
set fNoProxy=1
goto arg_next

:arg_next
shift
goto arg_loop
:arg_done

REM
REM Do the registrations.
REM
@if %fIs64BitWindows% == 1 goto register_amd64

:register_x86
@echo on
"%_VBOX_DIR%VBoxSVC.exe" /UnregServer
regsvr32 /s /u "%_VBOX_DIR%VBoxC.dll"
%windir%\system32\regsvr32 /s /u "%_VBOX_DIR%VBoxProxyStub.dll"
@if %fUninstallOnly% == 1 goto end
"%_VBOX_DIR%VBoxSVC.exe" /RegServer
"%_VBOX_DIR%VBoxSDS.exe" /RegService
regsvr32 /s    "%_VBOX_DIR%VBoxC.dll"
@if %fNoProxy% == 1 goto end
if exist "%_VBOX_DIR%VBoxProxyStub.dll"     %windir%\system32\regsvr32 /s "%_VBOX_DIR%VBoxProxyStub.dll"
@echo off
goto end

REM Unregister all first, then register them. The order matters here.
:register_amd64
if "%WinVerMajor%" == "5" goto register_amd64_legacy
if not "%WinVerMajor%" == "6" goto register_amd64_not_legacy
if not "%WinVerMinor%" == "0" goto register_amd64_not_legacy
:register_amd64_legacy
set s64BitProxyStub=VBoxProxyStubLegacy.dll
goto register_amd64_begin
:register_amd64_not_legacy
set s64BitProxyStub=VBoxProxyStub.dll
:register_amd64_begin
echo s64BitProxyStub=%s64BitProxyStub%
@echo on
"%_VBOX_DIR%VBoxSVC.exe" /UnregServer
"%_VBOX_DIR%VBoxSDS.exe" /UnregService
%windir%\system32\regsvr32 /s /u "%_VBOX_DIR%VBoxC.dll"
%windir%\syswow64\regsvr32 /s /u "%_VBOX_DIR%x86\VBoxClient-x86.dll"
%windir%\system32\regsvr32 /s /u "%_VBOX_DIR%%s64BitProxyStub%"
%windir%\syswow64\regsvr32 /s /u "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll"
if %fUninstallOnly% == 1 goto end
"%_VBOX_DIR%VBoxSVC.exe" /RegServer
"%_VBOX_DIR%VBoxSDS.exe" /RegService
%windir%\system32\regsvr32 /s    "%_VBOX_DIR%VBoxC.dll"
%windir%\syswow64\regsvr32 /s    "%_VBOX_DIR%x86\VBoxClient-x86.dll"
if %fNoProxy% == 1 goto end
if exist "%_VBOX_DIR%%s64BitProxyStub%"         %windir%\system32\regsvr32 /s "%_VBOX_DIR%%s64BitProxyStub%"
if exist "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll" %windir%\syswow64\regsvr32 /s "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll"
@echo off

:end
@endlocal