Error reading registry entry for Firefox - firefox

I have an AutoIt v3 script (copied from the author of FF.au3):
#Include <FF.au3>
_FFStart("http://ff-au3-example.thorsten-willert.de/")
If _FFIsConnected() Then
Sleep(2000)
_FFAction("presentationmode", True)
Sleep(2000)
_FFOpenURL("http://www.google.com")
Sleep(2000)
_FFAction("back")
_FFAction("presentationmode", False)
Sleep(2000)
_FFOpenURL("chrome:bookmarks")
Sleep(2000)
_FFAction("alert", "Bye bye ...")
_FFQuit()
EndIf
Exit
But when I run it, I get an error message:
__FFStartProcess ==> General Error: Error reading registry entry for FireFox.
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox\*CurrentVersion*\Main\PathToExe
Error from RegRead: 1
I have Firefox and AutoIt v3 installed, I downloaded the FF.au3 UDF to same directory as my script, and I have MozRepl Firefox plugin installed and activated (it's active at the menu->plug-ins, I don't see the "Activate on startup" option). I do have an entry at:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox\26.0 (pl)\Main
That points to the right destination. Why is there an "Error reading registry entry for FireFox."?

Here is the relevant piece of code from the Firefox library:
Local $sHKLM = 'HKEY_LOCAL_MACHINE\SOFTWARE\'
If #OSArch <> 'X86' Then $sHKLM &= 'Wow6432Node\'
$sHKLM &= 'Mozilla\Mozilla Firefox'
Local $sFFExe = RegRead($sHKLM & "" & RegRead($sHKLM, "CurrentVersion") & "\Main", "PathToExe")
If #error Then
SetError(__FFError($sFuncName, $_FF_ERROR_GeneralError, "Error reading registry entry for FireFox." & #CRLF & _
$sHKLM & "\*CurrentVersion*\Main\PathToExe" & #CRLF & _
"Error from RegRead: " & #error))
Return 0
EndIf
It reads the key CurrentVersion (probably of type REG_SZ) from the path HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox to get the current version of the application. Say for example that this returns the string "27.0".
Then it looks in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox\27.0\Main (based on the string it just found for the current version) for the key PathToExe (REG_SZ also probably). This is the first attempt and if it does not fail it uses this path for the executable.
If this fails though, it checks the path HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox\*CurrentVersion*\Main (literally with the asterisks) for the key PathToExe. This fails as well and that's why you are getting the error.
Check all of the above registry paths for your system. It may be possible that the Firefox library needs to be updated for the later Firefox versions. Try an "as clean as possible" install of Firefox and see if that works. Also try repairing the installation via the setup/deinstaller if that is possible.
If nothing works and you are left to modifying your own system to get it to work, I will check and ask the author of the Firefox library to update it.

I think there's a missing backslash. In the FF.au3 UDF change the following:
Local $sFFExe = RegRead($sHKLM & "" & RegRead($sHKLM, "CurrentVersion") & "\Main", "PathToExe")
to:
Local $sFFExe = RegRead($sHKLM & "\" & RegRead($sHKLM, "CurrentVersion") & "\Main", "PathToExe")
Regards,
Gonnosuke

Most registry manipulation problems are about lack of permissions.
Add #RequireAdmin at the top of your code.

"When running on 64-bit Windows if you want to read a value specific to the 64-bit environment you have to suffix the HK... with 64 i.e. HKLM64."

Related

How to escape & ampersand in Custom protocol handler in Windows

I made a custom protocol handler following this link. The case is I need to open a link which can only be opened in IE and might contains several query parameters and should be opened in IE from our web app which is running on Chrome (this is really annoying). After many tries and fails, I managed to find the snippet to add entry to the windows registry hive and made .reg file and run:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"="\"\""
#="\"URL:IE Protocol\""
[HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon]
#="\"explorer.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
#="cmd /k set myvar=%1 & call set myvar=%%myvar:ie:=%% & call \"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\" %%myvar%% & exit /B"
It worked but the problem is if a link contains more than 1 query params, all but the first are omitted, I am sure this because of character encoding in windows command line:
e.g. some_example_url?query1=value1&query2=value2&query3=value3 is becoming some_example_url?query1=value1
I find this solution but it did not work either. How can I properly escape & character, so that it can be opened on IE with all query parameters. (as before mentioned link is triggered by web app running on Chrome)
EDIT: The code which triggers:
fileClicked(url) {
// url should be escaped with ^
const escapedUrl = url.replace(/&/gi, '^&');
const ie = document.createElement('a');
// ie: scheme => custom protocol handler
// host computer (windows) should add custom protocol to windows registry
ie.href = `ie:${escapedUrl}`;
ie.click();
}
EDIT 2
#muzafako fixed the script, just last line should be replaced like below:
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
You don't need to decode query parameters at all. I've tried to find solution for this issue and saw this answer. Its works for me. just change command line to:
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"

Code Error 800A0409 - Unterminated String Constant (Japanese Windows)

This one is kind of strange to me. Prior to posting I did research this error code and according to many articles out there it seems relatively a straight forward issue. The issue is generally related to either missing double quotes in a string or where a string spans across multiple lines.
However, in my case neither of the above seem to be the cause of the issue. The strange thing is my code works fine in English windows operating system but I encounter this error only in the Japanese version of windows.
The error is pointing to the following line of code:
WScript.Echo "PFXファイル " & pfxFileName & " は存在しません。"
Any ideas why this would only happen in the Japanese version of Windows?
Here is the block of surrounding code in case it gives any further clues:
' check if pfx file exists
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
pfxFileExists = 0
Do
If fso.FileExists(pfxFilePath & pfxFileName) Then
' it exists, continue
pfxFileExists = 1
Else
' The PFX file does not exist.
WScript.Echo "PFXファイル " & pfxFileName & " は存在しません。"
End If
Loop Until pfxFileExists = 1

vbscript reads File object properties, but won't delete the file

Here is my (very simple) code:
if fs.FileExists(strPath) then
set thisFile=fs.GetFile(strPath)
wscript.echo thisFile.Name & " (" & thisFile.Size & ") will be deleted"
thisFile.Delete
end if
The path is correct, because I can read the file name and file size in the output. However, this is the output I'm getting:
D:\Inetpub>cscript PDFDelete.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
131_1443_cds101711.pdf (28660) will be deleted
D:\Inetpub\PDFDelete.vbs(38, 3) Microsoft VBScript runtime error: File not found
As you can see, I get the proper output on the file properties, so I know I have a valid reference to the file object, but trying to execute the Delete() method on that exact same file object produces a "File not found" error?!
It makes no sense to me. How can the file be "not found" if I just accessed its name and size properties?
EDIT I should have mentioned, I initially was using the code "fs.DeleteFile(strPath)" when I first got the "File Not Found" error. I changed it to the more direct "File.Delete()" method, but the error persists.
You can try:
if fs.FileExists(strPath) then
set thisFile=fs.GetFile(strPath)
wscript.echo thisFile.Name & " (" & thisFile.Size & ") will be deleted"
fs.DeleteFile strPath
end if
http://www.devguru.com/technologies/vbscript/14055
I found the issue.
There was a stray line of code further down in the script that was referencing thisFile.Size, after trying to delete that file. The error was happening on that line, not on the thisFile.Delete line.
Moral of the story: make use of the On Error Resume Next/On Error Goto 0 error trapping from the start, and things get a lot clearer.

VBS RegRead doesn't return value

I've got the following code:
Dim objShell,failing_path,working_path
failing_path = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test"
working_path = "HKEY_LOCAL_MACHINE\SOFTWARE\7-zip\Path"
Set objShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "Working: " & objShell.RegRead(working_path)
WScript.Echo "Not Working: " & objShell.RegRead(failing_path)
When executing I will get the Path from the 7-zip Registrykey, but the Test Key returns following error:
Error says: Registry wasn't opened for reading.
Here the proof that the Test-Key exists:
What am I doing wrong? I also tried to read the key via oReg.GetStringValue but this always returned null.
It seems like your script is running in a 32-Bit compatible scripting host but in a 64-bit OS.
Since 32 bit applications are automatically redirected to the WOW6432Node areas of the registry in 64-Bit OSes, RegRead method tries to read 32-Bit equivalent path like
HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Test
instead
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test
So, if the redirected path does not exist you receive that error as expected.
You may need to force run your scripts in 64-bit compatible scripting hosts to get rid of that kind of implicit registry redirects.
When I tested this, I was able to read from non-Wow6432Node paths just fine, even when using a 32-bit cscript.exe from a 32-bit cmd.exe (Process Explorer showed image type 32-bit for both processes).
Perhaps it's something really simple? I was able to reproduce the behavior you described when I created a registry value with a spurious trailing space:
>>> key = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
>>> WScript.Echo sh.RegRead(key & "Test")
Unable to open registry key "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\
Uninstall\Test" for reading. (0x80070002)
>>> WScript.Echo sh.RegRead(key & "Test ")
asd

Delete file in windows 7 using VB.NET

I have written following code in vb.net to delete the file.
If File.Exists(strPath & "\ReportEng.ini") = True Then
File.SetAttributes(strPath & "\ReportEng.ini", FileAttributes.Normal)
File.Delete(strPath & "\ReportEng.ini")
End If
File.Copy("\\192.168.0.1\SAP_Shared\AddonExtra\ReportEng.ini", strPath & "\ReportEng.ini")
This code works perfectly in windows xp. But in Windows 7,I can not delete it. This OS is hectic OS from developer's point of view. Some or other problem occurs and Microsoft has not considered the developer while building this OS.
How do I delete file in Windows 7 ?
It's so easy to do so;
If My.Computer.FileSystem.FileExists("C:\somefile.ext") Then 'Check whether file exists
My.Computer.FileSystem.DeleteFile("C:\somefile.ext") 'Delete the file!
End If
Have a nice day!
You don't need to delete the file: there is an overload File.Copy Method (String, String, Boolean) which allows overwriting.
You didn't say what error you get. I suspect it is because the user doesn't have write access to the directory. You should probably be using a subdirectory of the directory returned by Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) or maybe .LocalApplicationData, and definitely not the directory containing the program.
Also, using Path.Combine(strPath, "ReportEng.ini") is how you're meant to combine paths - it'll take care of, e.g., the trailing path separator for you.
The preferred method for interfacing with the Windows file system uses the following namespace:
Imports Microsoft.VisualBasic.FileIO.FileSystem
To delete a file:
Dim FileLocation As String = strPath & "\ReportEng.ini"
If Not GetDirectoryInfo(FileLocation).Exists Then
GetFileInfo(FileLocation).Delete()
End If

Resources