C – How do I get the path to the Windows “Special Folder” for a specific user?

In the service, what is the best way to determine a special folder path (such as “My Documents”) for a specific user? SHGetFolderPath allows you to pass in a token, so I assume there are some ways to simulate the user of the folder you are interested in.

Is there a way to do this based only on the username? If not, what is the minimum amount of information required for a user account? I would rather not have to ask for the user’s password.

(This is a related question.)

I will mount the user’s registry hive and look up the path value. Yes, for all the reasons mentioned (poor forward compatibility, etc.), this is a sub-optimal solution. However, unlike many others in Windows The content is the same, MS does not provide API methods to perform the operations you want, so it is the best choice.

You can use LookupAccountName to get the user’s SID (instead of GUID). You can use LoadUserProfile loads the user’s registry hive, but unfortunately, this also requires a user token, which will require their password. Fortunately, you can use RegLoadKey to manually load the hive to any location, read the data and Uninstall it (I think).

Yes, it is a pain, yes, it may break in future Windows versions. Maybe by then MS will provide an API to implement it, which will It is backported to the old version of Windows, and automatically distributed through Windows updates… But I will not hold my breath.

Attachment: This information is intended to enhance the information provided in your related questions, including Disclaimer.

In the service, what is the best way to determine a special folder path (such as “My Documents”) for a specific user? SHGetFolderPath allows you to pass in a token, so I assume there are some ways to simulate the user of the folder you are interested in.

Is there a way to do this based only on the username? If not, what is the minimum amount of information required for a user account? I would rather not have to ask for the user’s password.

(This is a related question.)

I will mount the user’s registry configuration Unit and find the path value. Yes, for all the reasons mentioned (poor forward compatibility, etc.), this is a sub-optimal solution. However, like many other things in Windows, MS does not provide an API method to perform what you want You can use LookupAccountName to get the user’s SID (instead of GUID). You can use LoadUserProfile to load the user’s registry hive, but unfortunately Yes, this also requires a user token, which will require their password. Fortunately, you can use RegLoadKey to manually load the hive to any location, read the data and unload it (I think).

< p>Yes, it is a pain, yes, it may break in future Windows versions. Maybe by then MS will provide an API to implement it, backport it to older versions of Windows, and Automatic distribution via Windows updates…but I won’t hold my breath.

P.S. This information is intended to enhance the information provided in your related questions, including the disclaimer.

< p>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2167 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.