You cannot use exec to return any output from your command.
See this answer.But you can use shell_exec() to return the output of your command.
You can have an array of computer:
$computer = array('comp1', 'comp2');
$comp1 = array();
foreach($computer as $username)
{
$comp1 = shell_exec("wmic /node: ". $username ." computersystem Get UserName");
print_r($comp1);
}
But if there is only one:
$user = shell_exec('wmic /node: <yourcomputername> COMPUTERSYSTEM Get UserName');
print_r($user);
But i suggest to get logged users, there is a tool from sysinternals that i used to do certain task like executing process remotely, list info about the system through command prompt.
Checkout and install PSTools. Then you can use the PsLoggedon.exe