Wednesday, July 7, 2010

PSGetSid.exe

Another great utility is PSGetSid.exe.

Have you ever had to change a registry setting in the HKey Users registry hive? It's difficult to tell which is which and makes it difficult to change a setting for a particular logged on user due to the hive masked by the SID of the user. PSGetSid.exe will get the currently logged on user's SID.

We use something similar to the commands below in a batch file in order to make the necessary changes.

In order to automate the batch file without intervention by the user or technician, a registry key has to be altered in order for the utility to be registered in the registry.

REGEDIT /S "\\server\share\getSid.reg"

The getSid.reg contains the following to register the utility:

REGEDIT4

[HKEY_CURRENT_USER\Software\Sysinternals]

[HKEY_CURRENT_USER\Software\Sysinternals\PsGetsid]
"EulaAccepted"=dword:00000001

Copy the above and save as getSid.reg in order to use it in the script above.

REM ** The following code will run the PsGetSid.exe and export to a text file.
"\\server\share\PsGetsid.exe" %username% > \\server\Share\%username%.txt
REM ** The next step is to parse through the information and assign it to a variable
FOR /F "skip=1" %%G IN (\\server\share\%username%.txt) DO set userId=%%G
REM ** Using the variable, we create the registry setting.
reg add "HKU\%userId%\Software\Sonic\Registration\Roxio Easy Media Creator 9" /f

The above example uses the Roxio software due to the necessity of registering it under every user profile on the system. I'm not sure about you, but our users call us for every single pop-up message they receive, even a simple "Never Register" check box. So, we try and eliminate calls by automating the process.

This was just an example of the use of PSGetSid.exe, a great utility to automate registry settings for a logged on user.

At the end of the above batch file, you can add a del \\server\share\%username%.txt in order to delete the file when it is no longer necessary.

PSGetSid.exe is a great utility from SysInternals and provided freely by Microsoft.

Download it here - http://technet.microsoft.com/en-us/sysinternals/bb897417.aspx


Happy scripting and good luck.

3 comments:

  1. the string follow isnt good
    FOR /F "skip=1" %%G IN (\\server\share\%username%.txt) DO set userId=%%G

    the result is :
    HKU\%userId% \Software

    %userId% + one space

    ReplyDelete
  2. There must be a space in the text file following the user names. If you open it up with notepad and do a click and drag with the mouse from top to bottom, highlighting the text, it will reveal if there's a space at the end of the line. If so, delete the space and you'll find that it should work properly.

    Good luck.

    ReplyDelete
  3. Cool and I have a super offer: How Long Does House Renovation Take home addition construction

    ReplyDelete