function SystemDceSecurityProvider::getWindowsGid
Returns a group identifier for a user on a Windows system
Since Windows does not have the same concept as an effective POSIX GID for the running script, we will get the local group memberships for the user running the script. Then, we will get the SID (security identifier) for the first group that appears in that list. Finally, we will return the RID (relative identifier) for the group and use that as the GID.
@link https://www.windows-commandline.com/list-of-user-groups-command-line/ List of user groups command line
File
-
vendor/
ramsey/ uuid/ src/ Provider/ Dce/ SystemDceSecurityProvider.php, line 197
Class
- SystemDceSecurityProvider
- SystemDceSecurityProvider retrieves the user or group identifiers from the system
Namespace
Ramsey\Uuid\Provider\DceCode
private function getWindowsGid() : string {
$response = shell_exec('net user %username% | findstr /b /i "Local Group Memberships"');
if ($response === null) {
return '';
}
/** @var string[] $userGroups */
$userGroups = preg_split('/\\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY);
$firstGroup = trim($userGroups[1] ?? '', "* \t\n\r\x00\v");
if ($firstGroup === '') {
return '';
}
$response = shell_exec('wmic group get name,sid | findstr /b /i ' . escapeshellarg($firstGroup));
if ($response === null) {
return '';
}
/** @var string[] $userGroup */
$userGroup = preg_split('/\\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY);
$sid = $userGroup[1] ?? '';
if (($lastHyphen = strrpos($sid, '-')) === false) {
return '';
}
return trim(substr($sid, $lastHyphen + 1));
}