code_junkie

Getting user name/password of the logged in user in Windows

Nov 11th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. var wmiService, compSystem;
  2.  
  3.  
  4. wmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2");
  5. // the '.' denotes local system, it can be replaced with the name of the remote machine
  6.  
  7. compSystem = wmiService.ExecQuery("Select * from Win32_ComputerSystem");
  8.  
  9. var enumItems = new Enumerator(compSystem);
  10.  
  11. for (; !enumItems.atEnd(); enumItems.moveNext())
  12. {
  13. var item = enumItems.item();
  14. WScript.echo("Logged in user: " + item.UserName);
  15. }
Add Comment
Please, Sign In to add comment