Strona 1 z 1

How to add registry key from HTML Application (HTA) - snippet example

: 15 mar 2024, 12:43
autor: WinSxS
How to add registry key from HTML Application (HTA) - snippet example
Jak dodać klucz rejestru spod aplikacji HTML (HTA) - przykładowy wycinek
Angielski język w temacie dla pozycjonowania w wyszukiwarkach.

Example:
Add Open File Location (Find Target) to context menu

Example reg file:

Kod: Zaznacz cały

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Open File Location]
@="&Open File Location"

[HKEY_CLASSES_ROOT\Directory\shell\Open File Location\command]
@="\"explorer.exe\" /select,\"%1\""

[HKEY_CLASSES_ROOT\*\shell]

[HKEY_CLASSES_ROOT\*\shell\Open File Location]
@="&Open File Location"

[HKEY_CLASSES_ROOT\*\shell\Open File Location\command]
@="\"explorer.exe\" /select,\"%1\""
Example HTA Code:

Kod: Zaznacz cały

<script language="VBScript">
Option Explicit
Dim WshShell,Title
Title = "Open File Location" 
Set WshShell = CreateObject("WScript.Shell")
'*************************************************************************
Sub Write2Registry()
    WshShell.RegWrite "HKCR\Directory\Shell\Open File Location","&Open File Location", "REG_SZ"
    WshShell.RegWrite "HKCR\*\Shell\Open File Location","&Open File Location", "REG_SZ"
    WshShell.RegWrite "HKCR\Directory\shell\Open File Location\command\",Chr(34)& "explorer.exe" &Chr(34)& " /select," & Chr(34) & "%1" & Chr(34), "REG_SZ"
    WshShell.RegWrite "HKCR\*\shell\Open File Location\command\",Chr(34)& "explorer.exe" &Chr(34)& " /select," & Chr(34) & "%1" & Chr(34), "REG_SZ"
end sub
'*************************************************************************
Sub DeleteKeyFromRegistry()
On Error Resume Next
Dim MyKey
    MyKey = WshShell.RegDelete("HKCR\Directory\Shell\Open File Location\command\")
    MyKey = WshShell.RegDelete("HKCR\Directory\Shell\Open File Location\")
    MyKey = WshShell.RegDelete("HKCR\*\Shell\Open File Location\command\")
    MyKey = WshShell.RegDelete("HKCR\*\Shell\Open File Location\")
    If Err <> 0 Then
        MsgBox Err.Number & vbcr & Err.Description,vbCritical,Title
    Else
        'MsgBox MyKey,vbInformation,Title
    End If  
End Sub
</script>
<br><br>
<INPUT NAME="btnWriteKey" title="WriteKey" TYPE="BUTTON" VALUE="Install" OnClick="Write2Registry()">
<INPUT NAME="btnDeleteKey" title="btnDeleteKey" TYPE="BUTTON" VALUE="Remove" OnClick="DeleteKeyFromRegistry()">
Explanation/Wyjaśnienie:

Chr(34)& "explorer.exe" &Chr(34)& " /select," & Chr(34) & "%1" & Chr(34)

Chr(34) = "
& = sums phrases on left and right
Chr(34)& "explorer.exe" &Chr(34) = "explorer.exe"
Chr(34)& "explorer.exe" &Chr(34)& " /select," & Chr(34) & "%1" & Chr(34) = "explorer.exe" /select,"%1"

That code may request for administrator privileges in Vista+.