Gather SID of remote user - Windows 7

Discussion in 'Software' started by lepick, Jun 13, 2014.

  1. lepick

    lepick Private E-2

    Hello everyone,

    I'm currently working on a script that requires to gather the SID data of a user on the network on a Variable. The thing is that if I do it locally it works flawlessly

    Here is the Local Script for the local user:
    Code:
    setlocal
    set "RegPath=HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
    for /f "delims=" %%i in ('reg query "%RegPath%"^|findstr /ibc:"%RegPath%\S-"') do (
      reg query "%%i" /v "ProfileImagePath"|findstr /iec:"%USERNAME%" >nul &&set "SID=%%~nxi"
    )
    echo Client SID %SID% 
    
    And for the "Do it remotely", I only altered the RegPath to point to the computer:
    Code:
    setlocal
    set "RegPath=\\%computername%\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"
    for /f "delims=" %%i in ('reg query "%RegPath%"^|findstr /ibc:"%RegPath%\S-"') do (
      reg query "%%i" /v "ProfileImagePath"|findstr /iec:"%USERNAME%" >nul &&set "SID=%%~nxi"
    )
    
    That does not work. It gives nothing. I tried changing the quotes mark, computer name, made sure that Remote Registry was enable on the client computer, changed the username, you name it. And still does not work, it either gives me an Error Network path was not found or nothing at all. Also, if I don't run the script as admin, it will tell me Access Denied, but this is normal.

    Here is the catch! If I want to do it manually (like Go in the registry, connect to remote computer, and get the key manually with the GUI) I am able to get the SID.

    We have a guy who scripts in VBS, and is able to get the Client SID from Active Directory. But I don't want to use his lol

    Anyone has an idea?

    Thank you
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds