Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

win service and HKCU and SHGetFolderPath with CSIDL_APPDATA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Viviana Vc - 11 Mar 2005 18:02 GMT
Hi all,

A Windows service (which obviously starts before any user logs in) is
failing to:
- read something from registry from a key under the HKCU
- try to find out the user path by doing the following call:
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path)
if any of these is tried before a user logs in.

My question is: are these 2:
- read something from registry from a key under the HKCU
- try to find out the user path by doing the following call:
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path)
supposed to fail also after the user logs in? (XP and 2000)

Thanks in advance,
Viv
Korn?l P?l - 11 Mar 2005 19:10 GMT
Hi,

I think this is because the user profile of the service account is not
loaded.
You should use LoadUserProfile and then access HKCU. SHGetFolderPath is
using HKCU as well.

Sincerely,
Korn?l

> Hi all,
>
[quoted text clipped - 13 lines]
> Thanks in advance,
> Viv
Viviana Vc - 14 Mar 2005 12:17 GMT
Thx for your answer.

Actually I have a LSP (layered service provider) dll that is loaded by
all services and I noticed that for services, in my dll trying to read
the HKCU fails, and wasn't sure if this is a general rule for all
services or the behaviour depends on how the service is written ...
Seems that it can be different depends if the service is doing a
LoadUserProfile() call before my dll is used right?

Thanks,
Viv

On Fri, 11 Mar 2005 20:10:44 +0100, "Kornél Pál"
<anonymous@discussions.microsoft.com> wrote :

>Hi,
>
[quoted text clipped - 23 lines]
>> Thanks in advance,
>> Viv
Sten Westerback - 14 Mar 2005 14:14 GMT
> Thx for your answer.
>
[quoted text clipped - 4 lines]
> Seems that it can be different depends if the service is doing a
> LoadUserProfile() call before my dll is used right?

Sure "environment" depends on what is done before your code is run. :)

The default account used for Services ("LocalSystem") simply doens't
have a user profile so no HKCU link is created to a new place in
HKU. (I'm not fully sure but the HKCU may be linked to HKU\.DEFAULT
by default).

So either you load an suitable profile for LocalSystem (making sure the
local account can access the file), define a normal account as the service
account or, most properly, use keys somewhere under HKLM or most
properly HKLM\SYSTEM\CurrentControlSet\Services\MyService\Parameters

- Sten

> Thanks,
> Viv
[quoted text clipped - 26 lines]
> >> Thanks in advance,
> >> Viv
Korn?l P?l - 14 Mar 2005 20:20 GMT
> "Viviana Vc":
>> Actually I have a LSP (layered service provider) dll that is loaded by
[quoted text clipped - 3 lines]
>> Seems that it can be different depends if the service is doing a
>> LoadUserProfile() call before my dll is used right?

After the answer of Arnaud Debaene I have done some test using the following
environment:
Windows XP SP2, Microsoft .NET Framework 1.1 SP1, a test service written in
C#

I have tried the service with Local System, Local Service, Network Service
and a custom, non-administrative user.
In all of these cases I was able to access HKCU for read and write as well.
And I'm sure that the Framework isn't using LoadUserProfile at all.

"Sten Westerback":
> Sure "environment" depends on what is done before your code is run. :)
>
[quoted text clipped - 7 lines]
> account or, most properly, use keys somewhere under HKLM or most
> properly HKLM\SYSTEM\CurrentControlSet\Services\MyService\Parameters

The Local System account has a HKCU key and it is the same as
HKEY_USERS\.DEFAULT.

For more information please read my reply to Arnaud Debaene's message.

According to Platform SDK Documentation LoadUserProfile can be called only
by administrators or system. It is intendet to be used by a service if you
are using a high privileged account (eg. Local System) and want to
impersonate to a low privileged account. In this case the profile of the
impersonated account is not loaded and you have to load it using
LoadUserProfile to access HKCU for example. But you have to load it as Local
System.

I'm sure if a service is executed it has a HKCU. You problem may be caused
because the underlaying service is doing impersonation without loading the
user profile. But I cannot tell you anything else wthout the analisis of the
wole soultion...

I advise you the same as Sten to use a registry key in HKLM, the mentioned
Parametes subkey is a common solution.

Sincerely,
Korn?l

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.