c# - Edit registry key of other user -


how change or edit registry values of other user current user? know credentials of other user.

you can impersonate user , change registry current context. here couple of resources on c# , impersonation:

what want (pseudo):

using(var impersonation = new impersonate(username,password)) {     changeregistry(keys, values); } 

and when impersonation disposed, using running user again. here example implementation of impersonate class implements idisposable act pseudo-exampel shown above , here example.

here example on how change registry values:

var registry = registry.currentuser; var key = registry.opensubkey(    @"hkey_current_user\some\path\that\you\want\tochange", true);  key.setvalue(null, "");               registry.currentuser.flush(); 

update

so need in order access hkcu have load user profile. done invoking win32 method called loaduserprofile. there's complete example here can use, i'm going include important bits here.

first need include win32 methods this:

[dllimport("userenv.dll", setlasterror = true, charset = charset.auto)] public static extern bool loaduserprofile(intptr htoken,                                           ref profileinfo lpprofileinfo);  [dllimport("userenv.dll",  callingconvention = callingconvention.winapi,                             setlasterror = true, charset = charset.auto)] public static extern bool unloaduserprofile(intptr htoken,                                                     intptr lpprofileinfo); 

inside impersonation using-block need following:

profileinfo profileinfo = new profileinfo(); profileinfo.dwsize = marshal.sizeof(profileinfo); profileinfo.lpusername = username; profileinfo.dwflags = 1; boolean loadsuccess = loaduserprofile(tokenduplicate, ref profileinfo); 

and after should able access hkcu. when you're done, need unload profile using unloaduserprofile(tokenduplicate, profileinfo.hprofile);.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -