Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the CreateUserProfileEx in C#

Tags:

c#

pinvoke

winapi

I am building a small application in C# that can create the user profile on Windows XP, Windows7 and Windows 8, using the Windows APIs

For Windows 7 and 8, the method CreateProfile worked perfectly.

But, when trying to use the CreateUserProfileEx on Windows XP, it didn't work, it returned me an error notifying that the method couldn't be find in the "UserEnv.dll", after reading a little bit more the API, I realized that I would need to use the LoadLibrary and GetProcAddress to link to Userenv.dll.

I searched for some sample related to this, but I couldn't find something that could give me a good idea or explanation how to do this.

if someone could put some sample in C# or point me where I could review about this, I would really appreciate it.

like image 580
jfvf Avatar asked Jun 29 '14 08:06

jfvf


People also ask

How to expand the source string of a user profile?

Expands the source string by using the environment block established for the specified user. Retrieves the path to the root of the All Users profile. Retrieves the path to the root of the Default User profile. Retrieves the path to the root directory where all user profiles are stored. Retrieves the type of profile loaded for the current user.

What is the use of retrieve user profile?

Retrieves the path to the root of the Default User profile. Retrieves the path to the root directory where all user profiles are stored. Retrieves the type of profile loaded for the current user. Retrieves the path to the root directory of the specified user's profile.

How to run multiple processes using execvp in C?

So, whenever you use execvp (), if you want to maintain your C program, you generally use fork () to first spawn a new process, and then use execvp () on that new process. This is called the “fork-exec” model, and is the standard practice for running multiple processes using C. Let’s now look at some examples, to understand this function better.

How to prevent runtime looking for getprocaddressa in a string?

GetProcAddress only comes in an ANSI flavor, hence we help the runtime by telling it to always use ANSI when marshalling the string parameter. We also prevent the runtime looking for a non-existent GetProcAddressA, because the default for C# is to set ExactSpelling to false. Show activity on this post. You really need to add some error checking.


1 Answers

after reading a little bit more the API, I realized that I would need to use the LoadLibrary and GetProcAddress to link to Userenv.dll.

Read a little bit more:

This function is not declared in the software development kit (SDK) headers and has no associated import library. You must use the LoadLibrary and GetProcAddress functions to link to Userenv.dll. The ANSI version of the function, CreateUserProfileExA is referenced from Userenv.dll as ordinal 153. The Unicode version, CreateUserProfileExW is referenced as ordinal 154.

Google a little bit:

Additionally, in Windows you can bind to exported DLL functions by their ordinal values. If you need to do this, an EntryPoint value such as "#1" or "#129" indicates the ordinal value of the unmanaged function in the DLL rather than a function name.

like image 141
ta.speot.is Avatar answered Oct 12 '22 22:10

ta.speot.is