Skip to content

Commit

Permalink
Fix USBPcapCMD on Windows XP
Browse files Browse the repository at this point in the history
Since the initial extcap implementation, the USBPcapCMD was not working in
Windows XP. This is because minimum Windows version for TOKEN_ELEVATION is
Windows Vista.

Add a fallback administrator priviledge check for Windows XP.
  • Loading branch information
desowin committed Jul 30, 2018
1 parent 78b2a39 commit 102264f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions USBPcapCMD/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ static BOOL IsElevated()
{
fRet = Elevation.TokenIsElevated;
}
else
{
DWORD err = GetLastError();
if (err == ERROR_INVALID_PARAMETER)
{
/* Running on Windows XP.
* Check if executed as administrator by reading Local Service key.
*/
HKEY key;
if (ERROR_SUCCESS == RegOpenKey(HKEY_USERS, "S-1-5-19", &key))
{
fRet = TRUE;
}
else
{
/* If we were executed with SW_HIDE then the runas window won't be shown.
* In such case pretend here that we are running as administrator so
* the process will fail (and not simply be waiting indefinitely
* without giving any clue).
*/
STARTUPINFO info;
GetStartupInfo(&info);
if (info.wShowWindow == SW_HIDE)
{
fRet = TRUE;
}
}
}
else
{
fprintf(stderr, "GetTokenInformation failed with code %d\n", err);
}
}
}

if (hToken)
Expand Down

0 comments on commit 102264f

Please sign in to comment.