Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Last active August 29, 2015 14:19
Get service SID from service name
open System.Security.Cryptography
open System.Security.Principal
open System.Text
open System
// 1st arg (index [0]) is this script
let name = fsi.CommandLineArgs.[1]
let hash = new SHA1CryptoServiceProvider()
let tail = name.ToUpper()
|> Encoding.Unicode.GetBytes
|> (fun x -> hash.ComputeHash(x))
let head = [|1uy; 6uy; 0uy; 0uy; 0uy; 0uy; 0uy; 5uy; 80uy; 0uy; 0uy; 0uy |]
let binary = Array.append head tail
let sid = new SecurityIdentifier(binary, 0)
Console.WriteLine(sid.ToString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment