Programming Field

Schtasks /ShowSid - DOS/Command Prompt Reference

[Windows Vista or later] Calculates the security identifier (SID) corresponding to the specified task name. This is one of the commands (options) of Schtasks.

Syntax

schtasks[.exe] /ShowSid /TN <task-name> [/HRESULT]

Options

/TN <task-name>

Specifies the name of the task. If the task name contains space characters, you need to enclose it with ‘" "’. If the task exists within a folder hierarchy, include the path to the task as well.

Note that the task name that does not used for existing tasks is acceptable.

/HRESULT [Windows 10? or later] Changes the exit code of the Schtasks command to HRESULT. This is used when you want to perform detailed handling in case of errors.

Details

The security identifier (SID) corresponding to a task is strictly in the form of the ‘NT TASK\<converted-task-name>’ group, where ‘<converted-task-name>’ is the task name with the character ‘\’ replaced by ‘-’ since ‘\’ is not allowed in usernames. This SID is used as a group for processes when the task is configured to run under the ‘NT AUTHORITY\NETWORK SERVICE’ or ‘NT AUTHORITY\LOCAL SERVICE’ groups, and the ‘ProcessTokenSidType’ is unspecified or set to ‘unrestricted’.
This indicates that during task execution, the task has access to objects (such as files) for which access rights have been granted to the SID calculated with "/ShowSid". For example, if the task ‘Piyo’ is configured to run under ‘LOCAL SERVICE’, adding the SID ‘S-1-5-87-3647662311-3586884399-309657888-2945673006-409376041’ to the file's access permissions would allow programs executed by the task ‘Piyo’ to access that file within the specified access rights. Using the Icacls command is convenient for granting access permissions.

References:

The SID calculated with ‘/ShowSid’ is unique for each name. Regardless of which computer you run ‘/ShowSid’ on, the same task name will yield the same SID. (In this case, the task doesn't need to exist.)

Samples

Sample

schtasks /showsid /tn "Hoge Piyo"

Outputs the SID corresponding to the task ‘Hoge Piyo’. (In this case, the SID ‘S-1-5-87-792629802-3193705368-3856631695-2842567315-2114608075’ is obtained.)

See also