Article View: borland.public.cppbuilder.nativeapi
Article #11849Re: problem with TerminateProcess and user rights
From: Remy Lebeau (TeamB)
Date: Tue, 13 Jan 2004 01:41
Date: Tue, 13 Jan 2004 01:41
79 lines
3344 bytes
3344 bytes
"saso badovinac" <none@none.com> wrote in message
news:400341ac@newsgroups.borland.com...
> now i have to do it in c++. now i have a problem with
>
>
SetSecurityInfo(plist32.szExeFile,SE_KERNEL_OBJECT,OWNER_SECURITY_INFORMATIO
N,0,0,0,0);
>
> i just dont know what to set for those 0 (NULL) at the end :\
Why are you trying to use that function in the first place? It is not in
the VB code you showed. Also, the function expects a handle to an active
object, not to a filename. If anything, you should be passing the process
handle that OpenProcess() returns.
As for the parameters are you asking for, if you actually read the
documentation for SetSecurityInfo(), you will see that you only need one of
them - the psidOwner parameter. If you want to get the SID for your own
process, then have a look at the GetKernelObjectSecurity() and
GetSecurityDescriptorOwner() functions.
> the vb code:
That would be the following in C++:
bool KillProcess(DWORD ProcessID, DWORD ExitCode = 0)
{
HANDLE hToken = NULL;
HANDLE hProcess = NULL;
TOKEN_PRIVILEGES tp = {0};
OSVERSIONINFO ver = {0};
bool Result = false;
GetVersionEx(&ver);
if( ver.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
if( !OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) )
return false;
if( !LookupPrivilegeValue("", "SeDebugPrivilege",
&tp.Privileges[0].Luid) )
{
CloseHandle(hToken);
return false;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if( !AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL) )
{
CloseHandle(hToken);
return false;
}
}
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, ProcessID);
if( hProcess )
{
Result = TerminateProcess(hProcess, ExitCode);
CloseHandle(hProcess);
}
if( ver.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL);
CloseHandle(hToken);
}
return Result;
}
Gambit
Technical Details
Message-ID:
<40034b5f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4000a4a8@newsgroups.borland.com> <400341ac@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,6dea0870157ee61c X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-12 17:39:55 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4000a4a8@newsgroups.borland.com> <400341ac@newsgroups.borland.com> Subject: Re: problem with TerminateProcess and user rights Date: Mon, 12 Jan 2004 17:41:39 -0800 Lines: 81 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <40034b5f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1073957727 67.22.138.253 (12 Jan 2004 17:35:27 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail