Trouble adding If/Then condition to script that opens regedit & "jumps to" any key on cClipboard

wittonlin

Board Regular
Joined
Jan 30, 2016
Messages
144
Code:
' Created by Sergey Tkachenko
' (c) http://winaero.com/
Dim objHTA
Dim cClipBoard
Dim WshShell
set objHTA=createobject("htmlfile")
cClipBoard=objHTA.parentwindow.clipboarddata.getdata("text")
Set WshShell = WScript.CreateObject("WScript.Shell")

[B]if findstring([cClipBoard], "HKCR")>=0 then
   Call Replace([cClipBoard], "HKCR", "HKEY_CLASSES_ROOT")
elseif findstring([cClipBoard], "HKCU")>=0 then
   Call Replace([cClipBoard], "HKCU", "HKEY_CURRENT_USER")
elseif findstring([cClipBoard], "HKLM")>=0 then
   Call Replace([cClipBoard], "HKLM", "HKEY_LOCAL_MACHINE")
elseif findstring([cClipBoard], "HKU")>=0 then
   Call Replace([cClipBoard], "HKU", "HKEY_USERS")
else
 [cClipBoard]
End If[/B]

WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey", cClipBoard, "REG_SZ"
WshShell.Run "regedit.exe -m"
Set objHTA = nothing
Set WshShell = nothing
Set cClipBoard = nothing


Obviously I'm trying to add conditions that will handle the root key abbriviations for HKCR, HKCU, etc.

Adding "Call" to the Replace function was the only way to get rid of the initial error "cannot use parentheses when calling a sub"

Now I can't handle the "Type Mismatch" error on "findstring".

The only thing I can think of is that it's not recognizing [cClipBoard]. I have no idea what object to use to describe and edit then.

Maybe windows default clipboard contents cannot be edited and I have to edit it once written in LastKey registry?

Note: If I use i.e. "HKCR\WIA.DeviceManager\CLSID" on the clipboard, the registry opens but not to any KEY, and checking WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey" (Ironically the abbriviation is used here) THIS is the data in the LastKey = "HKCR\WIA.DeviceManager\CLSID", which of course needs to rather be "HKEY_CLASSES_ROOT\WIA.DeviceManager\CLSID"

Any ideas?



Also posted here.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Got it. Thanks anyway.

Code:
asif = objHTA.parentwindow.clipboarddata.getdata("text")
asif1= Replace(asif,"HKCR", "HKEY_CLASSES_ROOT")
asif2= Replace(asif1,"HKCU", "HKEY_CURRENT_USER")
asif3= Replace(asif2,"HKLM", "HKEY_LOCAL_MACHINE")
cClipBoard= Replace(asif3, "HKU", "HKEY_USERS")
Set WshShell = WScript.CreateObject("WScript.Shell")
 
Upvote 0

Forum statistics

Threads
1,215,781
Messages
6,126,870
Members
449,345
Latest member
CharlieDP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top