473,412 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

win service and HKCU and SHGetFolderPath with CSIDL_APPDATA

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

Nov 17 '05 #1
4 5410
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,

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

Nov 17 '05 #2
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"
<an*******@discussions.microsoft.com> wrote :
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,

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


Nov 17 '05 #3

"Viviana Vc" <vc*******@hotmail.com> wrote in message
news:39*************@individual.net...
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?
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\P arameters

- Sten
Thanks,
Viv
On Fri, 11 Mar 2005 20:10:44 +0100, "Kornél Pál"
<an*******@discussions.microsoft.com> wrote :
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,

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

Nov 17 '05 #4
> "Viviana Vc":
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?

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. :)

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\P arameters


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

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Wiktor Zychla | last post by:
I need a patch that is returned by API's SHGetFolderPath with CSIDL_COMMON_DOCUMENTS. I expected to find it among other enums in Environment.SpecialFolder enumeration. But I cannot find it there. ...
10
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
9
by: Adam Klobukowski | last post by:
Hello I've written a small C# program that uses VFPOLEDB it is working perfectly. Then, I redesigned it to work as service (as described in...
8
by: MSDN Account | last post by:
I have looked at the documentation for 'Microsoft.Win32.Registry' and 'System.Security.Permissions.RegistryPermission' but am still stuck, hoping some can give me a nudge in the right direction. ...
0
by: atx | last post by:
Hi, I have a web service, as I understand from msdn docs, web services in IIS 6 works with network service account. Therefore for a specific purpose, I have to access the HKCU registry of network...
3
by: Ahmad Jalil Qarshi | last post by:
Hi! I am developing an application in C# as a windows NT Service. This application needs to check for eventlog using EventLog.Exists("System") But unfortunately it generates exception...
7
by: Ahmed Perlom | last post by:
Hi all, I am trying to start a windows application that has a GUI from a Windows service written in .NET 2.0. I have been searching on this for few days now with no avail. When using the...
12
by: Simon Hart | last post by:
Hi, I am using Impersonation and turned off anon access for my web service. I am using the administator to authenticate the request using ICredentials. I am simply trying to read a key in...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.