Forum Discussion

almmatt's avatar
almmatt
Contributor
9 years ago
Solved

Get current Windows user SID

Hello everyone,

 

I am looking for a way to get the current Windows user SID during script execution. Part of our regression testing requires that we verify deleting an item within our application moves it to the Recycle Bin. Online research has uncovered that the path to the recycle bin is C:\$Recycle.bin\<Windows User SID>.

 

So, I could use some help writing a JScript script to get this information. Has anyone done this before?

 

PS: You can see your SID from the command prompt using this:

whoami /user
  • Hi almmatt,

     

    Try this:

     

    function getSID()
    {
      var oWMI = GetObject("winmgmts:");
      var oAccount = oWMI.Get("Win32_UserAccount.Name='" + Sys.UserName + "',Domain='" + Sys.DomainName + "'");
      return oAccount.SID;
    }

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi almmatt,

     

    Try this:

     

    function getSID()
    {
      var oWMI = GetObject("winmgmts:");
      var oAccount = oWMI.Get("Win32_UserAccount.Name='" + Sys.UserName + "',Domain='" + Sys.DomainName + "'");
      return oAccount.SID;
    }
    • almmatt's avatar
      almmatt
      Contributor

      Thank you very much! That is exactly what I needed!