VirtualBox

source: vbox/trunk/src/VBox/Main/src-all/win/comregister.cmd@ 52418

Last change on this file since 52418 was 52418, checked in by vboxsync, 11 years ago

comregister.cmd: Check if the current user is an administrator. Otherwise all the COM registration will fail silently.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette