Using "temporary" registry keys

Questions, Support, etc.

Using "temporary" registry keys

Postby jsantos98 on Thu Sep 18, 2008 3:32 pm

Hello there!

First of all, good work! This looks like an excelent SDK!


I was making some tests using your Internet Explorer example using Delphi, where I wanted to change the location of the cookies.
This is in the registry under
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
in the Cookies value.

The test went OK inside the initialization area...
Code: Select all
   BoxedAppSDK_CreateVirtualRegKeyA ( HKEY_CURRENT_USER,
                                      'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',
                                      0,
                                      nil,
                                      REG_OPTION_NON_VOLATILE,
                                      KEY_ALL_ACCESS,
                                      nil,
                                      phkResult,
                                      0);

   Reg := TRegistry.Create;
   try
      Reg.RootKey := HKEY_CURRENT_USER;
      Reg.KeyExists('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders');

      if (Reg.OpenKey ('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', True)) then
      begin
         Reg.WriteInteger('aa', 1978);
         Reg.WriteString('Cookies', 'D:\temp\Boxed\samples\Delphi\a');
         if (Reg.ValueExists('Cookies')) then
            ShowMessage ((Reg.ReadString('Cookies')))
         else
            ShowMessage ('Error');
      end;
   finally
      Reg.Free;
   end;

   Reg := TRegistry.Create;
   try
      Reg.RootKey := HKEY_CURRENT_USER;
      if Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', False) then
         showMessage( Reg.ReadString('Cookies'));
   finally
      Reg.CloseKey;
      Reg.Free;
   end;


However, in the browser window inside the application (under a button click, p.e.), the same code as before
Code: Select all
   Reg := TRegistry.Create;
   try
      Reg.RootKey := HKEY_CURRENT_USER;
      if Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', False) then
         showMessage( Reg.ReadString('Cookies'));
   finally
      Reg.CloseKey;
      Reg.Free;
   end;

no longer works... What am I doing wrong?

Regards,
João
jsantos98
 
Posts: 8
Joined: Thu Sep 18, 2008 3:23 pm

Re: Using "temporary" registry keys

Postby Artem A. Razin on Thu Sep 18, 2008 4:36 pm

Thank you for your question.

Yes, I tried and it seems you're right. I should make some more test to understand what's wrong. I will write here ASAP.

Thank you!
Artem A. Razin
Site Admin
 
Posts: 746
Joined: Mon Jul 28, 2008 5:04 pm
Location: St.Petersburg, Russia

Re: Using "temporary" registry keys

Postby Artem A. Razin on Thu Sep 18, 2008 5:06 pm

I've debugged, it seems that Windows restores this value.

Small test.

Change HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders -> Cookies to another value. Then start Internet Explorer and load something. Then refresh regedit (F5)... and the value is restored!
Artem A. Razin
Site Admin
 
Posts: 746
Joined: Mon Jul 28, 2008 5:04 pm
Location: St.Petersburg, Russia

Re: Using "temporary" registry keys

Postby Artem A. Razin on Thu Sep 18, 2008 5:10 pm

I have one idea how to resolve it. We (developers of the SDK) should add ability to set a callback that is called each time when a value is read. Agree?
Artem A. Razin
Site Admin
 
Posts: 746
Joined: Mon Jul 28, 2008 5:04 pm
Location: St.Petersburg, Russia

Re: Using "temporary" registry keys

Postby jsantos98 on Thu Sep 18, 2008 5:44 pm

Artem A. Razin wrote:I have one idea how to resolve it. We (developers of the SDK) should add ability to set a callback that is called each time when a value is read. Agree?


Yes, I think that would very nice!
(I suppose that it would be possible to override the value returned to the caller)
jsantos98
 
Posts: 8
Joined: Thu Sep 18, 2008 3:23 pm

Re: Using "temporary" registry keys

Postby jsantos98 on Thu Sep 18, 2008 5:52 pm

I just thought of a problem...

I was hoping the virtual registry setting would be only available inside the application instance that created it!

Imagine this scenario...
You have an application with an webbrowser embedded inside.
You want to have a different cookie (or temp files) location everytime you start it.
You have 2 instances running...

Would your solution work in this scenario?
jsantos98
 
Posts: 8
Joined: Thu Sep 18, 2008 3:23 pm

Re: Using "temporary" registry keys

Postby Artem A. Razin on Fri Sep 19, 2008 9:20 am

jsantos98 wrote:I just thought of a problem...

I was hoping the virtual registry setting would be only available inside the application instance that created it!


If you create a virtual key, this key is available only inside the process.

jsantos98 wrote:Imagine this scenario...
You have an application with an webbrowser embedded inside.
You want to have a different cookie (or temp files) location everytime you start it.
You have 2 instances running...

Would your solution work in this scenario?


Yes, it will work.
Artem A. Razin
Site Admin
 
Posts: 746
Joined: Mon Jul 28, 2008 5:04 pm
Location: St.Petersburg, Russia

Re: Using "temporary" registry keys

Postby jsantos98 on Fri Sep 19, 2008 9:52 am

Wonderful!!!

When you have something to test let me know ;)

Once again, great work!
jsantos98
 
Posts: 8
Joined: Thu Sep 18, 2008 3:23 pm

Re: Using "temporary" registry keys

Postby Artem A. Razin on Sat Sep 20, 2008 9:43 am

We've added this thing.

Please download the demo again, then see samples\Delphi\Sample1_InternetExplorer\MainUnit.pas.

Uncomment:

Code: Select all
BoxedAppSDK_AddHandler(@BoxedAppSDKHandler, nil);


The handler's code:

Code: Select all
function BoxedAppSDKHandler(Param: Pointer; RequestId: DWORD; pAdditionalInfo: Pointer): DWORD; stdcall;
var
   buf: Pointer;
begin
   if EnumBoxedAppSDK_RequestId__RegQueryValue = RequestId then
   begin
      if ((PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_Root = HKEY_CURRENT_USER) And
          (PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_szPath = 'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders') And
          (PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_szValue = 'Cookies'))
      Then
      begin
         buf := BoxedAppSDK_Alloc(256);

         lstrcpyW(PWideChar(buf), 'C:\!Cache');

         PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_pData := buf;
         PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_dwSize := 256;
         PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_dwType := REG_SZ;

         PBoxedAppSDK__RegQueryValue(pAdditionalInfo)^.m_bHandled := 1;
      end;
   end;
end;


Thank you.
Artem A. Razin
Site Admin
 
Posts: 746
Joined: Mon Jul 28, 2008 5:04 pm
Location: St.Petersburg, Russia

Re: Using "temporary" registry keys

Postby jsantos98 on Mon Sep 22, 2008 11:04 am

Hello!

First of all, thanks for your efforts!

However, I was trying your example, removed the comment and runned the application (after changing the URL to a site with cookies), however, the IE never calls that key...
Now, I'm not sure if is a problem with the boxed application, or simply a security issue with IE...

Any ideas?
jsantos98
 
Posts: 8
Joined: Thu Sep 18, 2008 3:23 pm

Next

Return to BoxedApp SDK

cron