1 | @echo off
|
---|
2 | REM $Id: comregister.cmd 59365 2016-01-17 05:14:34Z 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-2015 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 | if "%WinVerMajor%" == "5" set fNoProxy=1
|
---|
124 | if "%WinVerMajor%" == "4" set fNoProxy=1
|
---|
125 | set fUninstallOnly=0
|
---|
126 |
|
---|
127 | :arg_loop
|
---|
128 | if "%1x" == "x" goto arg_done
|
---|
129 |
|
---|
130 | if "%1" == "-u" goto arg_uninstall
|
---|
131 | if "%1" == "--uninstall" goto arg_uninstall
|
---|
132 | if "%1" == "--proxy" goto arg_proxy
|
---|
133 | if "%1" == "--no-proxy" goto arg_no_proxy
|
---|
134 | echo syntax error: Unknown option %1
|
---|
135 | echo usage: comregister.cmd [-u,--uninstall] [--no-proxy] [--proxy]
|
---|
136 | goto end
|
---|
137 |
|
---|
138 | :arg_uninstall
|
---|
139 | set fUninstallOnly=1
|
---|
140 | goto arg_next
|
---|
141 |
|
---|
142 | :arg_proxy
|
---|
143 | set fNoProxy=0
|
---|
144 | goto arg_next
|
---|
145 |
|
---|
146 | :arg_no_proxy
|
---|
147 | set fNoProxy=1
|
---|
148 | goto arg_next
|
---|
149 |
|
---|
150 | :arg_next
|
---|
151 | shift
|
---|
152 | goto arg_loop
|
---|
153 | :arg_done
|
---|
154 |
|
---|
155 | REM
|
---|
156 | REM Do the registrations.
|
---|
157 | REM
|
---|
158 | @if %fIs64BitWindows% == 1 goto register_amd64
|
---|
159 |
|
---|
160 | :register_x86
|
---|
161 | @echo on
|
---|
162 | "%_VBOX_DIR%VBoxSVC.exe" /UnregServer
|
---|
163 | regsvr32 /s /u "%_VBOX_DIR%VBoxC.dll"
|
---|
164 | %windir%\system32\regsvr32 /s /u "%_VBOX_DIR%VBoxProxyStub.dll"
|
---|
165 | @if %fUninstallOnly% == 1 goto end
|
---|
166 | "%_VBOX_DIR%VBoxSVC.exe" /RegServer
|
---|
167 | regsvr32 /s "%_VBOX_DIR%VBoxC.dll"
|
---|
168 | @if %fNoProxy% == 1 goto end
|
---|
169 | if exist "%_VBOX_DIR%VBoxProxyStub.dll" %windir%\system32\regsvr32 /s "%_VBOX_DIR%VBoxProxyStub.dll"
|
---|
170 | @echo off
|
---|
171 | goto end
|
---|
172 |
|
---|
173 | REM Unregister all first, then register them. The order matters here.
|
---|
174 | :register_amd64
|
---|
175 | @echo on
|
---|
176 | "%_VBOX_DIR%VBoxSVC.exe" /UnregServer
|
---|
177 | %windir%\system32\regsvr32 /s /u "%_VBOX_DIR%VBoxC.dll"
|
---|
178 | %windir%\syswow64\regsvr32 /s /u "%_VBOX_DIR%x86\VBoxClient-x86.dll"
|
---|
179 | %windir%\system32\regsvr32 /s /u "%_VBOX_DIR%VBoxProxyStub.dll"
|
---|
180 | %windir%\syswow64\regsvr32 /s /u "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll"
|
---|
181 | if %fUninstallOnly% == 1 goto end
|
---|
182 | "%_VBOX_DIR%VBoxSVC.exe" /RegServer
|
---|
183 | %windir%\system32\regsvr32 /s "%_VBOX_DIR%VBoxC.dll"
|
---|
184 | %windir%\syswow64\regsvr32 /s "%_VBOX_DIR%x86\VBoxClient-x86.dll"
|
---|
185 | if %fNoProxy% == 1 goto end
|
---|
186 | if exist "%_VBOX_DIR%VBoxProxyStub.dll" %windir%\system32\regsvr32 /s "%_VBOX_DIR%VBoxProxyStub.dll"
|
---|
187 | if exist "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll" %windir%\syswow64\regsvr32 /s "%_VBOX_DIR%x86\VBoxProxyStub-x86.dll"
|
---|
188 | @echo off
|
---|
189 |
|
---|
190 | :end
|
---|
191 | @endlocal
|
---|