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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With