-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstallShellExtensions.vbs
More file actions
106 lines (87 loc) · 3.07 KB
/
installShellExtensions.vbs
File metadata and controls
106 lines (87 loc) · 3.07 KB
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
' This script installs Any2fb2 shell extensions:
' "Autoconvert to fb2" menu item for the files of types
' *.html; *.htm; *.txt; *.prt; *.rtf; *.doc; *.dot; *.wri; *.wk1; *.wk3; *.wk4; *.mcw
'
' Use "installShellExtensions.vbs -u" to remove all corresponding registry entries.
'
' Script must be executed from the same folder where Any2fb2.vbs is located.
'
' Fj (fj.mail@gmail.com)
Dim Sh 'shell object
Dim cmdline 'open command line
Dim supportedExtensions
supportedExtensions = Split(".html .htm .txt .prt .rtf .doc .dot .wri .wk1 .wk3 .wk4 .mcw")
Dim uninstall 'true to remove keys
' *******
Function WriteApplicationKey(key)
Sh.RegWrite key & "FriendlyAppName", "Autoconvert to fb2"
Sh.RegWrite key & "shell\", "Autoconvert2fb2"
Sh.RegWrite key & "shell\Autoconvert2fb2\", "&Autoconvert to fb2"
Sh.RegWrite key & "shell\Autoconvert2fb2\FriendlyAppName", "Autoconvert to fb2"
Sh.RegWrite key & "shell\Autoconvert2fb2\command\", cmdline, "REG_EXPAND_SZ"
For Each ext in supportedExtensions
Sh.RegWrite key & "SupportedTypes\" & ext, "", "REG_SZ"
Next
End Function
' *******
Function DeleteApplicationKey(key)
Sh.RegDelete key & "shell\Autoconvert2fb2\Command\"
Sh.RegDelete key & "shell\Autoconvert2fb2\"
Sh.RegDelete key & "shell\"
Sh.RegDelete key & "SupportedTypes\"
Sh.RegDelete key
End Function
' *******
' *******
Function AssociateWithExtension(ext)
Dim key
On Error Resume Next
filetype = Sh.RegRead ("HKEY_CLASSES_ROOT\" & ext & "\")
On Error GoTo 0
If filetype <> Empty Then
key = "HKEY_CLASSES_ROOT\" & filetype & "\"
Sh.RegWrite key & "shell\Autoconvert2fb2\", "&Autoconvert to fb2"
Sh.RegWrite key & "shell\Autoconvert2fb2\Command\", cmdline, "REG_EXPAND_SZ"
End If
End Function
' *******
Function UnAssociateWithExtension(ext)
Dim key
filetype = Sh.RegRead ("HKEY_CLASSES_ROOT\" & ext & "\")
If filetype <> Empty Then
key = "HKEY_CLASSES_ROOT\" & filetype & "\"
Sh.RegDelete key & "shell\Autoconvert2fb2\Command\"
Sh.RegDelete key & "shell\Autoconvert2fb2\"
End If
End Function
' =============================
Set Sh = CreateObject("WScript.Shell")
cmdline = """%SystemRoot%\System32\WScript.exe"" """ & Sh.CurrentDirectory & "\any2fb2.vbs"" ""%1"""
' parse args
uninstall = False
For Each arg in WScript.Arguments
If arg = "-u" Then uninstall = True
Next
If uninstall Then
On Error Resume Next
' base application key
DeleteApplicationKey("HKEY_CLASSES_ROOT\Any2fb2.vbs\")
' "open with" menu
' DeleteApplicationKey("HKEY_CLASSES_ROOT\Applications\Any2fb2.vbs\")
' file extensions
For Each ext in supportedExtensions
UnAssociateWithExtension(ext)
Next
On Error GoTo 0
WSCript.Echo "Registry setup completed, ""Autoconvert to fb2"" option removed"
Else
' base application key
WriteApplicationKey("HKEY_CLASSES_ROOT\Any2fb2.vbs\")
' "open with" menu
' WriteApplicationKey("HKEY_CLASSES_ROOT\Applications\Any2fb2.vbs\")
' file extensions
For Each ext in supportedExtensions
AssociateWithExtension(ext)
Next
WSCript.Echo "Registry setup completed, ""Autoconvert to fb2"" option installed, use ""installShellExtensions.vbs -u"" to remove"
End If