PDA

View Full Version : VP can't find app from registry


beeneeb
01-31-2007, 01:04 PM
Here's my code:

-- Location method: Registry key
-- Read a folder path from the Registry.
if not g_InstalledVersion then
local MainKey = HKEY_LOCAL_MACHINE;
local SubKey = SessionVar.Expand("SOFTWARE\\YORKFURNSRVGD\\");
local ValueName = "Location";
local FolderPath = Registry.GetValue(MainKey, SubKey, ValueName);
g_InstalledVersion = VisualPatch.CheckFolderVersion("%AppFolder%", FolderPath);
if g_InstalledVersion then
SessionVar.Set("%AppFolder%", FolderPath);
end
end

==============

The registry value for the installed app is located at:

HKEY_LOCAL_MACHINE > SOFTWARE > YORKFURNSRVGD
The value name for where the app is located is under: "Location"
The program is installed at: C:\ProgramFiles\York Furnace Service Guide

==============

Does anyone know why the patch can't find the application via the registry?

Thanks,

Brian

Lorne
01-31-2007, 01:27 PM
I would enable logging and see what the log says.

Assuming the Location value exists inside HKLM\SOFTWARE\YORKFURNSRVGD and there is no typo in that name :)...

...in other words, assuming the value is being read from the Registry just fine...

...then it's most likely just that the key files at that path don't match the key files in any of the versions your project knows about.

In other words, the VisualPatch.CheckFolderVersion() function is validating the files found at the FolderPath location, using the key files designated in your project to identify the version that is installed. If the key files don't match, then no valid patchable version has been found.

Lorne
01-31-2007, 01:30 PM
The program is installed at: C:\ProgramFiles\York Furnace Service GuideBTW, the program files folder usually has a space between the words Program and Files, like so:

Program Files

...unless you specifically changed it after you installed Windows.

I'd check to make sure your Location value in the registry actually contains the right path.

beeneeb
01-31-2007, 01:37 PM
Thanks for the help Lorne. My log is below. Maybe you can figure something out:

[01/31/2007 13:34:54] Success Patch started: C:\Documents and Settings\ny000637\Desktop\YORKFURNSRVGD.exe
[01/31/2007 13:34:54] Notice Patch engine version: 2.0.4.0
[01/31/2007 13:34:54] Notice Product: York Furnace Service Guide
[01/31/2007 13:34:54] Success Language set: Primary = 9, Secondary = 1
[01/31/2007 13:34:54] Success Include script: _Global_Functions.lua
[01/31/2007 13:34:54] Notice Start project event: Global Functions
[01/31/2007 13:34:54] Success Run project event: Global Functions
[01/31/2007 13:34:54] Notice Start project event: On Startup
[01/31/2007 13:34:55] Error Script: On Startup, [86]: File.Find(Folder,TargetFileName,true,false,nil,g_c bFcnFindApplicationCallback); (1002)
[01/31/2007 13:35:21] Error Could not locate software on system
[01/31/2007 13:35:21] Success Run project event: On Startup
[01/31/2007 13:35:21] Success Display screen: Cannot Locate Software
[01/31/2007 13:35:22] Success Delete image file: C:\DOCUME~1\ny000637\LOCALS~1\Temp\_ir_vp2_temp_0\ IRIMG1.BMP
[01/31/2007 13:35:22] Success Delete image file: C:\DOCUME~1\ny000637\LOCALS~1\Temp\_ir_vp2_temp_0\ IRIMG2.BMP
[01/31/2007 13:35:22] Notice Exit patch process (Return code: 1210)

Lorne
01-31-2007, 01:42 PM
Go to Project > Settings > Advanced tab, and change the "Include action details" setting from "Errors" to "Extended Errors" to get as much info as possible in the log.

You could also insert some GetLastError actions to get more specific information on the error.

beeneeb
01-31-2007, 01:46 PM
I already requested the extended errors and that's what I got.



What about the line below? Does it mean that it found the Folder, but not the TargetFileName?

Error Script: On Startup, [86]: File.Find(Folder,TargetFileName,true,false,nil,g_c bFcnFindApplicationCallback);

Lorne
01-31-2007, 01:49 PM
What about the line below? Does it mean that it found the Folder, but not the TargetFileName?

Error Script: On Startup, [86]: File.Find(Folder,TargetFileName,true,false,nil,g_c bFcnFindApplicationCallback);It's failing with error code 1002, which is "The specified path was not found." So it's probably the path that is incorrect.

Which means that the path being supplied doesn't exist.

I think you should check the Registry value as I suggested above. :)

beeneeb
01-31-2007, 01:54 PM
According to the registry, the app is located in:
C:\Program Files\York Furnace Service Guide

I went through windows explorer and the app is located at:
C:\Program Files\York Furnace Service Guide



I just cannot figure this out...I compared this to another app that I have & the formats are exactly alike.

I know this has just got to be something small that I'm missing...

Lorne
01-31-2007, 01:59 PM
Try adding some dialog boxes to the script to see what the values of Folder and TargetFileName are immediately before the File.Find action.

beeneeb
01-31-2007, 02:14 PM
Try adding some dialog boxes to the script to see what the values of Folder and TargetFileName are immediately before the File.Find action.

How exactly do I do that?

Lorne
01-31-2007, 02:16 PM
Use Dialog.Message() actions. Search for "Debugging Your Scripts" in the help index.

beeneeb
01-31-2007, 02:56 PM
The only thing that I can figure out is that "AppFolder" has a "nil" value even after it checks the registry.

Lorne
01-31-2007, 02:58 PM
Can you post the entire On Startup script?

Put it between [_CODE_] and [_/CODE_] tags to preserve formatting (remove the underscores). Like this:

-- this is inside a code block

beeneeb
01-31-2007, 03:01 PM
--------------------------------------------------------------
-- Check for administrative privileges
--------------------------------------------------------------

-- Make sure that the user has administrative privileges on the system.
-- (g_IsUserAdmin is defined in _Global_Functions.lua)
if not g_IsUserAdmin() then
if not _SilentPatch then
local Title = SessionVar.Expand("%WindowTitle%");
local Message = SessionVar.Expand(VisualPatch.GetLocalizedString("MSG_SYSREQ_ADMIN"));
local DlgResult = Dialog.Message(Title, Message, MB_OKCANCEL, MB_ICONEXCLAMATION);
if DlgResult == IDCANCEL then
Application.Exit(EXIT_REASON_USER_NOT_ADMIN);
end
else
-- Since it is a silent patch, fail
Application.Exit(EXIT_REASON_USER_NOT_ADMIN);
end
end

--------------------------------------------------------------
-- Locate installed version
--------------------------------------------------------------

-- Define a global variable that will indicate the name
-- of the installed version on the user's system. A nil value
-- indicates that an installed version has not been found.
g_InstalledVersion = nil;

-- Location method: Registry key
-- Read a folder path from the Registry.
if not g_InstalledVersion then
local MainKey = HKEY_LOCAL_MACHINE;
local SubKey = SessionVar.Expand("SOFTWARE\\YORKFURNSRVGD\\");
local ValueName = "Location";
local FolderPath = Registry.GetValue(MainKey, SubKey, ValueName);
Dialog.Message("Temporary Debug Message:" , "bob" .. AppFolder);
g_InstalledVersion = VisualPatch.CheckFolderVersion("%AppFolder%", FolderPath);
Dialog.Message("Temporary Debug Message:" , "bob" .. AppFolder);
if g_InstalledVersion then
SessionVar.Set("%AppFolder%", FolderPath);
end
end

-- Location method: Current folder
-- Check whether the software is installed in the folder
-- that the patch was run from.
if not g_InstalledVersion then
g_InstalledVersion = VisualPatch.CheckFolderVersion("%AppFolder%", _SourceFolder);
if g_InstalledVersion then
SessionVar.Set("%AppFolder%", _SourceFolder);
end
end



-- Location method: File search
-- Search the user's system for a file that is known to
-- exist in the software's application folder.
if not g_InstalledVersion then
local TargetFileName = "YorkFurnace.exe";
local tbFolders = {};
tbFolders[1] = SessionVar.Expand("%ProgramFilesFolder%\\York Furnace Service Guide");
tbFolders[2] = SessionVar.Expand("%ProgramFilesFolder%\\Johnson Controls Unitary Products");
tbFolders[3] = SessionVar.Expand("%ProgramFilesFolder%");
-- Insert other folders here...

local CheckFixedDrives = true;
local CheckNetworkDrives = false;

-- (g_FindApplicationOnSystem is defined in _Global_Functions.lua)
g_InstalledVersion = g_FindApplicationOnSystem("%AppFolder%", TargetFileName, tbFolders, CheckFixedDrives, CheckNetworkDrives);
end

--------------------------------------------------------------
-- Ensure that installed software is not running
--------------------------------------------------------------

-- If we located an out-of-date version, make sure the installed
-- software is not running.
-- Remove the following block comment to enable this script
--[[
if g_InstalledVersion then
local Filename = SessionVar.Expand("MyProgram.exe");
local ProgramName = SessionVar.Expand("York Furnace Service Guide");
-- (g_EnsureProgramIsClosed is defined in _Global_Functions.lua)
local ProgramIsClosed = g_EnsureProgramIsClosed(Filename, ProgramName);
if not ProgramIsClosed then
Application.Exit(EXIT_REASON_PROGRAM_IS_OPEN);
end
end
]]

--------------------------------------------------------------
-- Set session variables
--------------------------------------------------------------

-- Set session variables that will be used in the log file
-- and in the user interface.
if g_InstalledVersion then
SessionVar.Set("%InstalledVersion%", g_InstalledVersion);
SessionVar.Set("%TargetVersion%", VisualPatch.GetTargetVersion());
end

--------------------------------------------------------------
-- Log result
--------------------------------------------------------------

-- Make a log file entry with the result.
if g_InstalledVersion then
local LogMsg = SessionVar.Expand("Success\tLocated installed version %InstalledVersion%: %AppFolder%\r\n");
VisualPatch.WriteToLogFile(LogMsg);
else
local LogMsg = SessionVar.Expand("Error\tCould not locate software on system\r\n");
VisualPatch.WriteToLogFile(LogMsg);
end

--------------------------------------------------------------
-- Select start screen
--------------------------------------------------------------

-- Decide which "Before Patching" screen to show.
if g_InstalledVersion then
if g_InstalledVersion == VisualPatch.GetTargetVersion() then
-- The target version was found
Screen.SetStartScreen("Software is Current");
else
-- An out-of-date version was found
Screen.SetStartScreen("Ready to Patch");
end
else
-- No version was found
Screen.SetStartScreen("Cannot Locate Software");
end

Lorne
01-31-2007, 03:08 PM
Ah, there is no variable named AppFolder in your script; %AppFolder% is a session variable, which is kind of like a patch-specific environment variable of sorts. You need to use a SessionVar.Expand() action to get the value of those; a Lua script variable isn't created for the session variables automatically.

Try changing the highlighted lines like so:

-- Location method: Registry key
-- Read a folder path from the Registry.
if not g_InstalledVersion then
local MainKey = HKEY_LOCAL_MACHINE;
local SubKey = "SOFTWARE\\YORKFURNSRVGD";
local ValueName = "Location";
local FolderPath = Registry.GetValue(MainKey, SubKey, ValueName);
Dialog.Message("Temporary Debug Message:" , "FolderPath = \""..FolderPath.."\"");
g_InstalledVersion = VisualPatch.CheckFolderVersion("%AppFolder%", FolderPath);
Dialog.Message("Temporary Debug Message:" , "%AppFolder% = \"" .. SessionVar.Expand("%AppFolder%").."\"");
if g_InstalledVersion then
SessionVar.Set("%AppFolder%", FolderPath);
end
end

I added the escaped quotes to make it easier to see any extra characters (like spaces) in the values.

beeneeb
01-31-2007, 03:15 PM
It still does the same thing..."Software not Found"

Lorne
01-31-2007, 03:18 PM
What is reported in the first dialog message box? What is FolderPath set to?

beeneeb
01-31-2007, 03:32 PM
FolderPath = "C:\Program Files\York Furnace Service Guide"

After I click "Okay", it then posts:

%AppFolder% = "%AppFolder%"

Lorne
01-31-2007, 04:12 PM
Oops, that second Dialog.Message action should be moved to after the SessionVar.Set() action, like so:

-- Location method: Registry key
-- Read a folder path from the Registry.
if not g_InstalledVersion then
local MainKey = HKEY_LOCAL_MACHINE;
local SubKey = "SOFTWARE\\YORKFURNSRVGD";
local ValueName = "Location";
local FolderPath = Registry.GetValue(MainKey, SubKey, ValueName);
Dialog.Message("Temporary Debug Message:" , "FolderPath = \""..FolderPath.."\"");
g_InstalledVersion = VisualPatch.CheckFolderVersion("%AppFolder%", FolderPath);
if g_InstalledVersion then
SessionVar.Set("%AppFolder%", FolderPath);
Dialog.Message("Temporary Debug Message:" , "%AppFolder% = \"" .. SessionVar.Expand("%AppFolder%").."\"");
end
endAfter this change, if the CheckFolderVersion action doesn't recognize the installed version, g_InstalledVersion will be nil, and the 2nd dialog message won't be shown.

The good news is we know it's getting the value from the Registry okay, so the CheckFolderVersion action probably isn't recognizing the contents of that folder as a version.

If that's the case, then it's generally just that (a) the installed version doesn't match the versions you added to your project or (b) you need to choose appropriate key files so the CheckFolderVersion action can make a positive ID.

Here are some questions to ask:

What version of the software is installed at that location?
What key files did you select in your project?
What is the MD5 signature of the key files that are installed? Do those signatures match the MD5 signatures of the key files in your project?
Are the key files that you selected for each version different from each other so Visual Patch can use them to tell your versions apart?