OSDN Git Service

Register.bat, RegisterPerUser.bat: Add /s option for silent registration
[winmerge-jp/winmerge-jp.git] / ShellExtension / Register.bat
1 @echo off
2 : Register.bat
3 :
4 : ShellExtension.dll is a so called 'Shell Extension'
5 : allowing user to start WinMerge from explorer's context
6 : menu to compare selected files/directories.
7 : However this dll file must be registered for
8 : Windows before it works.
9 :
10 : ShellExtension.dll can be unregistered with command:
11 : "Register.bat /U"
12
13 IF "%OS%" == ""                          Set DLLPATH=%0\..\ShellExtension.dll
14 IF "%PROCESSOR_ARCHITECTURE%" == "x86"   Set DLLPATH=%~dp0%ShellExtensionU.dll
15 IF "%PROCESSOR_ARCHITECTURE%" == "AMD64" Set DLLPATH=%~dp0%ShellExtensionX64.dll
16 IF "%PROCESSOR_ARCHITECTURE%" == "IA64"  Set DLLPATH=%~dp0%ShellExtensionX64.dll
17 IF "%PROCESSOR_ARCHITECTURE%" == "ARM64" Set DLLPATH=%~dp0%ShellExtensionARM64.dll
18
19 SET OPTIONS=
20 FOR %%i IN (%*) DO (
21   IF "%%i" == "/s" SET OPTIONS=%OPTIONS% /s 
22   IF "%%i" == "/S" SET OPTIONS=%OPTIONS% /s 
23 )
24
25 FOR %%i IN (%*) DO (
26   IF "%%i" == "/u" Goto Uninstall
27   IF "%%i" == "/U" Goto Uninstall
28 )
29
30 Echo Registering ShellExtension.dll...
31 IF "%OS%" == "" %WINDIR%\System\RegSvr32 %OPTIONS% "%DLLPATH%"
32 IF "%OS%" == "" Goto End
33 Call :Execute regsvr32 %OPTIONS% "%DLLPATH%"
34 IF EXIST "%~dp0\WinMerge32BitPluginProxy.exe" Call :Execute "%~dp0\WinMerge32BitPluginProxy.exe" /RegServer
35 Goto End
36
37 :Uninstall
38 Echo UnRegistering ShellExtension.dll...
39 IF "%OS%" == "" %WINDIR%\System\RegSvr32 /u %OPTIONS% "%DLLPATH%"
40 IF "%OS%" == "" Goto End
41 Call :Execute regsvr32 /u %OPTIONS% "%DLLPATH%"
42 IF EXIST "%~dp0\WinMerge32BitPluginProxy.exe" Call :Execute "%~dp0\WinMerge32BitPluginProxy.exe" /UnregServer
43 Goto End
44
45 :Execute
46 Ver | %WINDIR%\System32\Find " 5." > NUL
47 IF NOT ERRORLEVEL 1 (
48   rem Windows 2000, XP, Sever 2003
49   %1 %2 %3 %4
50 ) Else (
51   rem Windows Vista, Server 200x, Server 201x, Windows 8, Windows 10
52   Echo args="": For Each a in WScript.Arguments: If InStr^(a, " "^) ^> 0 Then args = args ^& """" ^& a ^& """ " Else args = args ^& a ^& " " End If: Next: CreateObject^("Shell.Application"^).ShellExecute "%~1", args, "", "runas" > "%TEMP%\Elevated.vbs"
53   Wscript //nologo "%TEMP%\Elevated.vbs" %2 %3 %4
54   Del "%TEMP%\Elevated.vbs" 2> NUL
55 )
56 Goto :EOF
57
58 :End
59 CLS