473,406 Members | 2,273 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,406 software developers and data experts.

Access to a user's Special Folders

How can I get access for another user's special folder locations?

A configuration file is stored in the users' appData folder and the
program altering it will be ran under the admin.

Aug 21 '06 #1
12 7968

You could use LogonUser to impersonate the other user and then
SHGetFolderPath to get the appropriate path, but it'd be much easier
to just get the current user's special folder location and then use
string manipulation to get the other user's folder.

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 21 Aug 2006 12:01:58 -0700, wh*******@gmail.com wrote:
>How can I get access for another user's special folder locations?

A configuration file is stored in the users' appData folder and the
program altering it will be ran under the admin.
Aug 21 '06 #2
but it'd be much easier
to just get the current user's special folder location and then use
string manipulation to get the other user's folder.
The problem with this is that the user can set their special folder to
whatever they want; ie. set my documents to c:\Docs instead of the
normal path.

I guess I might try the impersonate option.

Aug 21 '06 #3

Another thing you can try is reading the registry directly. The
directories are stored here:

HKEY_USERS\xxxx\Software\Microsoft\Windows\Current Version\Explorer\Shell
Folders

The trick is you need to loop through all the users and find the right
one based on "Logon User Name" stored here (which will include
domain):

HKEY_USERS\xxxx\Software\Microsoft\Windows\Current Version\Explorer

More work than impersonation, but doesn't require knowing passwords.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On 21 Aug 2006 12:25:32 -0700, wh*******@gmail.com wrote:
>but it'd be much easier
to just get the current user's special folder location and then use
string manipulation to get the other user's folder.

The problem with this is that the user can set their special folder to
whatever they want; ie. set my documents to c:\Docs instead of the
normal path.

I guess I might try the impersonate option.
Aug 21 '06 #4
The trick is you need to loop through all the users and find the right
one based on "Logon User Name" stored here (which will include
domain):

HKEY_USERS\xxxx\Software\Microsoft\Windows\Current Version\Explorer
Not sure what you mean here, xxxx is some random id number; not the
user name; how can i map the two together?

Aug 21 '06 #5
wh*******@gmail.com wrote:
>The trick is you need to loop through all the users and find the right
one based on "Logon User Name" stored here (which will include
domain):

HKEY_USERS\xxxx\Software\Microsoft\Windows\Curren tVersion\Explorer

Not sure what you mean here, xxxx is some random id number; not the
user name; how can i map the two together?
Hi,

IIRC, it's actually the user's SID, and you can try using P/Invoke to grab
an SID from username by means of the LookupAccountName function.

This webpage may help you:
http://www.pinvoke.net/default.aspx/...countName.html

Once you have the SID, if you get it into the correct format, you should be
able to do the registry lookup.

--
Hope this helps,
Tom Spink

Google first, ask later.
Aug 21 '06 #6

wh*******@gmail.com wrote:
How can I get access for another user's special folder locations?

A configuration file is stored in the users' appData folder and the
program altering it will be ran under the admin.
Remember that, if your program allows a "least-privilege" user to alter
another user's files or access their user folder, Microsoft will not
recognize it as XP or Vista-compatible and may even brand it malware.
This is not something most programs should be doing.

Having said that, you can have your program request to be run with
administrator permissions, or be run as if another user were logged on.

Aug 21 '06 #7
li****@gmail.com wrote:
>
wh*******@gmail.com wrote:
>How can I get access for another user's special folder locations?

A configuration file is stored in the users' appData folder and the
program altering it will be ran under the admin.

Remember that, if your program allows a "least-privilege" user to alter
another user's files or access their user folder, Microsoft will not
recognize it as XP or Vista-compatible and may even brand it malware.
This is not something most programs should be doing.

Having said that, you can have your program request to be run with
administrator permissions, or be run as if another user were logged on.
If the program is running in the context of a user without permissions to
the other users' folder, then it won't be able to alter/access the other
users' files, providing the ACL is correctly defined on those files. NTFS
built in security will take care of that.

The OP mentioned that the program will be running with admin privileges,
which is what you mentioned in your last point, anyway.

--
Hope this helps,
Tom Spink

Google first, ask later.
Aug 21 '06 #8
Remember that, if your program allows a "least-privilege" user to alter
another user's files or access their user folder, Microsoft will not
recognize it as XP or Vista-compatible and may even brand it malware.
This is not something most programs should be doing.
This is the problem i face:
A service is ran in the background by user, AAA. The service reads a
config file from AAA's settings directory.

The Admin can change the service settings by running a program that
alters this config file in AAA's settings directory.

Do you have any other recommendations to do this? The settings file
cannot be in a public folder because not everyone should alter it.

Aug 21 '06 #9
Not sure why you have a service running as a 'regular' user, services should
run as a 'service' user, that is running as LocalService or NetworkService.
Their special folders are accessible by admins and their paths are fixed.
Running a service as a regular users is a bad idea, their registry hives
(HKCU) are not loaded when the user is not logged on interactively, so you
can't rely on API's like the special folder API nor can you search the users
part of registry as it's not loaded.

Willy.
<wh*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
|Remember that, if your program allows a "least-privilege" user to alter
| another user's files or access their user folder, Microsoft will not
| recognize it as XP or Vista-compatible and may even brand it malware.
| This is not something most programs should be doing.
|
| This is the problem i face:
| A service is ran in the background by user, AAA. The service reads a
| config file from AAA's settings directory.
|
| The Admin can change the service settings by running a program that
| alters this config file in AAA's settings directory.
|
| Do you have any other recommendations to do this? The settings file
| cannot be in a public folder because not everyone should alter it.
|
Aug 21 '06 #10
Sorry I wasn't more clear; trying to make the example generic; I meant
AAA was the LocalSystem user. Is this user folder fixed? I would think
you can change it per system(ie, user has an e:\ rather than a c:\).
Willy Denoyette [MVP] wrote:
Not sure why you have a service running as a 'regular' user, services should
run as a 'service' user, that is running as LocalService or NetworkService.
Their special folders are accessible by admins and their paths are fixed.
Running a service as a regular users is a bad idea, their registry hives
(HKCU) are not loaded when the user is not logged on interactively, so you
can't rely on API's like the special folder API nor can you search the users
part of registry as it's not loaded.

Willy.
<wh*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
|Remember that, if your program allows a "least-privilege" user to alter
| another user's files or access their user folder, Microsoft will not
| recognize it as XP or Vista-compatible and may even brand it malware.
| This is not something most programs should be doing.
|
| This is the problem i face:
| A service is ran in the background by user, AAA. The service reads a
| config file from AAA's settings directory.
|
| The Admin can change the service settings by running a program that
| alters this config file in AAA's settings directory.
|
| Do you have any other recommendations to do this? The settings file
| cannot be in a public folder because not everyone should alter it.
|
Aug 21 '06 #11
I think storing the config info into the registry might be a better
solution.

wh*******@gmail.com wrote:
Sorry I wasn't more clear; trying to make the example generic; I meant
AAA was the LocalSystem user. Is this user folder fixed? I would think
you can change it per system(ie, user has an e:\ rather than a c:\).
Willy Denoyette [MVP] wrote:
Not sure why you have a service running as a 'regular' user, services should
run as a 'service' user, that is running as LocalService or NetworkService.
Their special folders are accessible by admins and their paths are fixed.
Running a service as a regular users is a bad idea, their registry hives
(HKCU) are not loaded when the user is not logged on interactively, so you
can't rely on API's like the special folder API nor can you search the users
part of registry as it's not loaded.

Willy.
<wh*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
|Remember that, if your program allows a "least-privilege" user to alter
| another user's files or access their user folder, Microsoft will not
| recognize it as XP or Vista-compatible and may even brand it malware.
| This is not something most programs should be doing.
|
| This is the problem i face:
| A service is ran in the background by user, AAA. The service reads a
| config file from AAA's settings directory.
|
| The Admin can change the service settings by running a program that
| alters this config file in AAA's settings directory.
|
| Do you have any other recommendations to do this? The settings file
| cannot be in a public folder because not everyone should alter it.
|
Aug 21 '06 #12

<wh*******@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
| Sorry I wasn't more clear; trying to make the example generic; I meant
| AAA was the LocalSystem user. Is this user folder fixed? I would think
| you can change it per system(ie, user has an e:\ rather than a c:\).
|

Not sure what exactly is meant here by a "user folder".
Just let me explain my point...
Service accounts aren't interactive accounts, they don't have an
'interactive' profile (created by the system at first interactive logon), so
they don't have "My documents" and other related stuff on the File system.
What they have is an environment block and a minimal profile loaded, this
profile has a an Application Data entry which refers to the FIXED FS path
(except the drive letter) like: C:\Documents and
Settings\LocalService\Application Data or C:\Documents and
Settings\NetworkService\Application Data.
This path is returned by Environment.SpecialFolder.ApplicationData when
running as LocalService or NetworkService resp.
Creating a file under this path say:
C:\Documents and Settings\LocalService\Application Data\config.xml
will effectively create the file on the FS.
Note that the command shell will not show you the directories of these
pseudo accounts, they are only visible through the explorer shell.
An admin has access to the folder, so IMO it should be a problem to edit
config info in that folder.

Willy.


Aug 22 '06 #13

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

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
26
by: Dragon | last post by:
I have an Access 2003 .mde sitting on an SQL Server. The tables for the application also sit on the Server. I'm having a problem with ODBC on only one of about 10 machines. All the other machines...
0
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the...
3
by: Nick | last post by:
VB.Net allows the ability to find the path of special folders by calling the System.Environment.GetFolderPath function with a parameter specifying which special folder I want the path of. ...
0
by: F I S H | last post by:
The site I am going to build has roughly 1000 html, php, asp, mp3, pdf, swf, doc. jpg, txt files etc....... I put them in 100 different folders. 200 users will be given access to 10 folders...
2
by: staffonline | last post by:
Hi Friends, I recently can not access some share folder on a file server. the share folders have special permissions (only some domain groups allowed, i was a member of that group). but i...
5
by: Nosferatum | last post by:
I am in need of a solution on how to solve this problem: I need to limit access to six different folders. My users are validated in a system which check their prescence with a couple of...
10
by: Arno R | last post by:
Hi all, So I bought a new laptop 10 days ago to test my apps with Vista. (home premium) Apparently Office 2007 is pre-installed. (a time limited but complete test version, no SP1) So I take the...
25
by: p byers | last post by:
Good Morning Folks I have a LAN Among the several connections to it are the following four devices: A MAXSTOR network Storage Device A PC running Microsoft Windows 2000 Server 5.0.2195 (SP4) A...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.