On Sat, 9 Aug 2014 02:56:34 +0200, "R.Wieser" <add...@not.available>
wrote:
>Hello Geoff,
>
>> You have to ID the process and ask the system to elevate the
>> process privilege level.
>
>Yep, thats what I figured too. Though I must say that I find it odd that a
>process can elevate *itself* by using a few DLL functions (how is this *not*
>abused ?)
A process inherits the context of the user that launched it. A process
can't elevate itself but it can _ask_ to be elevated. If that user is
administrator the elevation is automatic and transparent, which is why
logging in as administrator and operating a Windows computer as
administrator is so hazardous. So, yes, processes may and often do
elevate themselves by simply doing so.
A bit of history:
Originally, in NT 4.0 and successors up to the Vista/XP era,
installations of Windows created the first account as Administrator,
which is equivalent to Linux "root". It didn't matter what the user
name was, it was in the Administrator's group and therefore it was
every bit an administrator as the account with the "Administrator"
login name.
The intent was that the owner would create a new account for himself
in the ordinary Users group and operate the computer from that login.
Unfortunately, NT didn't have a mechanism for easily transitioning
from User to Administrator rank and back again the way Unix/Linux
does, you can't type "sudo someprog", give the root password and
execute that process as root and go back about your business as
ordinary user again. You had to ctrl-alt-del, log out, log in, do
something in the new session, log out, log in. Tedious.
So everybody running Windows NT got used to running as administrator
and so did every program written for Windows NT, scribbling files all
over their home directories, into the %systemroot% and whatever.
Microsoft learned their lessons and eventually Windows XP and Windows
7 came along and did a better job of trying to lock things down.
Windows XP is still vulnerable to the lazy install problem described
above but Windows 7 manages to lock down "ordinary users" and even
administrators in some aspects but they can still elevate in the style
of sudo at the click of a mouse button. This is the origin of the
"User Account Control" dialog that pops up when RegEdit asks for
elevated privileges on Windows 7.
>
>Also, I hoped to se a link (or two) to some standard code, instead of me
>trying to re-invent the proverbial wheel ....
>
I can't help you there, I haven't quite delved into it enough to be
authoritative.
>> Regedit uses:
>
>Thanks.
>
>I will check those functions out. Though if I cannot find anything about
>which arguments those functions need and/or how they are supposed to work
>together only those function names alone won't help me much ...
>
>> Regedit does not use any Nt* or Zw* functions and I still don't
>> see the point of restricting yourself to using to using them.
>
>Actually, regedit, or rather the Reg* functions it uses do. Those Reg*
>functions are just skinny wrappers around the Nt* ones, to create a unified
>Win32 interface.
>
Well, yes and no, as you have described below. Regedit may ultimately
get down into those Nt* functions but it doesn't get there directly.
It does use the Reg* functions directly and it seems to know what it's
doing.
>As for you not seeing the point, how is that important to the answer ?
>
It's not, it was just a comment.
>But as you are curious about it, the Reg* functions use zero-terminated
>strings, while the Nt* functions use counted strings (for both the key names
>and values). That means the Nt* functions can do some stuff the Reg*
>functions cannot.
>
>> When the user isn't Administrator on Windows 7 the system prompts
>> for elevation. Behavior should be the same on XP but it's been so
>> long I don't remember what XP does.
>
>In my case regedit is able to show more content than the Reg* or Nt*
>functions I've been using in my programs, which I find odd -- regedit does
>show any "please elevate me" prompt.
>
I'm not sure I understand that last sentence. I think there's a typo
and you're saying there isn't a prompt from the system about elevating
RegEdit's access level.
If you're logged in as a member of Administrators then there won't be
any restrictions on any process you initiate and "elevations" are
going to be automatically granted to those processes.
My guess, and this is only a guess, is that KEY_ALL_ACCESS isn't
adequate in some cases for some keys and RegEdit is doing something
different.
FWIW, I just tried writing a key onto my Win7 HKLM registry using a
process I wrote and ran as a member of Administrators in Visual
Studio's debugger and the create failed. This is code that used to
work just fine in XP. I did not attempt just reading a key.