Problems to read the windows registry with a Guest access

Problems to read the windows registry with a Guest access

Postby Marco Turco » Fri Mar 24, 2006 8:53 am

Hi,
I want to read some hardware values from the windows registry using the tsysinfo class.

There are no problems when I access to the system as "Administrator" but it read nothing when I access as "Guest".

The strange is that as "Guest" I can read those informations without problems.

Any ideas ?

I made a self-contained sample that show the problem at www.softwarexp.co.uk/beta/sample.prg

Try to execute this app with an "Administrator" account and then on a "Guest" account. You will see that with the "Guest" account it return nothing.

Thanks in advance.

Regards,

Marco Turco
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby modicr » Fri Mar 24, 2006 11:19 am

Hello!

TSysInfo is using TReg32 and there is a problem in
New() method:
Code: Select all  Expand view  RUN
   #ifdef __CLIPPER__
      ::nError = RegOpenKeyEx( nKey, cRegKey,, KEY_ALL_ACCESS, @nHandle )
   #else
      ::nError = RegOpenKeyExA( nKey, cRegKey,, KEY_ALL_ACCESS, @nHandle )
   #endif


As you can see, KEY_ALL_ACCESS is used, but you don't have such rights
when running guest or limited user. This class should be enhanced
to support KEY_READ:
http://www.deez.info/sengelha/blog/2006 ... a-changes/
Here is how to perform some common development tasks while working in a least-privileged environment:

    Need to read from a HKEY_LOCAL_MACHINE key in the registry? Use RegOpenKeyEx() (not RegOpenKey()) and request KEY_READ (not KEY_ALL_ACCESS) privileges.
    Need to save per-user data which will roam with the user (i.e. may be replicated to the network)? Get the path to the Application Data\ folder by either retrieving the value of the environment variable %APPDATA% or calling SHGetFolderPath() with the parameter CSIDL_APPDATA. The recommended directory in which to store files appears to be %APPDATA%\<Vendor>\<Product>\, e.g. %APPDATA%\Microsoft\Office\.
    Need to save per-user data which will not roam with the user (e.g. a web browser cache)? Call SHGetFolderPath() with the parameter CSIDL_LOCAL_APPDATA.
    Need to save per-machine data (e.g. machine-wide game high scores)? Use %ALLUSERSPROFILE% or SHGetFolderPath() with the parameter CSIDL_COMMON_APPDATA.
    Need a place to store a temporary file? Use %TEMP% or GetTempPath(). GetTempFileName() may also be useful.


Same useful links regarding LUA (and UAC):
Fixing "LUA bugs"
Security Tools for Windows applications
http://nonadmin.editme.com/KnownProblems
http://homepage.mac.com/corrp/windows/LUA/homesite.html

Regards, Roman
© I'm not patented!
User avatar
modicr
 
Posts: 207
Joined: Fri Oct 07, 2005 7:58 am
Location: ljubljana, barje, slovenia

Postby Antonio Linares » Fri Mar 24, 2006 11:38 am

Roman,

Thanks for the info. This may seem the right code to use in source\classes\reg32.prg:
Code: Select all  Expand view  RUN
#define ERROR_SUCCESS 0

   ...

   #ifdef __CLIPPER__
      ::nError = RegOpenKeyEx( nKey, cRegKey,, KEY_ALL_ACCESS, @nHandle )
      if ::nError != ERROR_SUCCESS
         ::nError = RegOpenKeyEx( nKey, cRegKey,, KEY_READ, @nHandle )
      endif   
   #else
      ::nError = RegOpenKeyExA( nKey, cRegKey,, KEY_ALL_ACCESS, @nHandle )
      if ::nError != ERROR_SUCCESS
         ::nError = RegOpenKeyExA( nKey, cRegKey,, KEY_READ, @nHandle )
      endif   
   #endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Marco Turco » Fri Mar 24, 2006 12:50 pm

I confirm. It runs now !!

Thanks Roman and Antonio.

Best Regards,

Marco
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests