Void pslist (void)
{
Handle hprocesssnap = NULL;
Processentry32 pe32 = {0 };
Hprocesssnap = createconlhelp32snapshot (th32cs_snapprocess, 0 );
If (hprocesssnap = (handle)-1)
{
Printf ("/ncreatemedilhelp32snapshot () failed: % d", getlasterror ());
Return;
}
Pe32.dwsize = sizeof (processentry32 );
Printf ("/nprocessname processid ");
If (process32first (hprocesssnap, & pe32 ))
{
Char A [5];
Do
{
ITOA (pe32.th32processid, A, 10 );
Printf ("/n %-20 S % d", pe32.szexefile, pe32.th32processid );
}
While (process32next (hprocesssnap, & pe32 ));
}
Else
{
Printf ("/nprocess32firstt () failed: % d", getlasterror ());
}
Closehandle (hprocesssnap );
Return;
}
Bool killps (dword id) // kill a process function
{
Handle hprocess = NULL, hprocesstoken = NULL;
Bool iskilled = false, Bret = false;
_ Try
{
If (! Openprocesstoken (getcurrentprocess (), token_all_access, & hprocesstoken ))
{
Printf ("/nopen current process token failed: % d", getlasterror ());
_ Leave;
}
// Printf ("/nopen current process token OK! ");
If (! Setprivilege (hprocesstoken, se_debug_name, true ))
{
_ Leave;
}
Printf ("/nsetprivilege OK! ");
If (hprocess = OpenProcess (process_all_access, false, ID) = NULL)
{
Printf ("/nopen process % d failed: % d", ID, getlasterror ());
_ Leave;
}
// Printf ("/nopen process % d OK! ", ID );
If (! Terminateprocess (hprocess, 1 ))
{
Printf ("/nterminateprocess failed: % d", getlasterror ());
_ Leave;
}
Iskilled = true;
}
_ Finally
{
If (hprocesstoken! = NULL) closehandle (hprocesstoken );
If (hprocess! = NULL) closehandle (hprocess );
}
Return (iskilled );
}
Bool setprivilege (handle htoken, lpctstr lpszprivilege, bool benableprivilege) // escalate Permissions
{
Token_privileges TP;
Luid;
If (! Lookupprivilegevalue (null, lpszprivilege, & luid ))
{
Printf ("/nlookupprivilegevalue error: % d", getlasterror ());
Return false;
}
TP. privilegecount = 1;
TP. Privileges [0]. luid = luid;
If (benableprivilege)
TP. Privileges [0]. Attributes = se_privilege_enabled;
Else
TP. Privileges [0]. Attributes = 0;
Adjusttokenprivileges (
Htoken,
False,
& TP,
Sizeof (token_privileges ),
(Ptoken_privileges) null,
(Pdword) null );
If (getlasterror ()! = Error_success)
{
Printf ("adjusttokenprivileges failed: % u/N", getlasterror ());
Return false;
}
Return true;
}