CodeHog Posted October 3, 2025 Posted October 3, 2025 I am trying to automate assigning custom names to my Windows ShellNew templates. Most are located in user SID hives that have a unique identifier number and, therefore, I can't write a registry script to modify them. Is there a way to acquire that registry key number with an Autoit script and then modify values under the key?
WildByDesign Posted October 3, 2025 Posted October 3, 2025 Is it the actual SID's that you are trying to get? Do you have the usernames to perform the lookups? Something like this: #include <Security.au3> Local $sAccount = @UserName Local $tSID = _Security__GetAccountSid($sAccount) Local $sStringSID = _Security__SidToStringSid($tSID) ConsoleWrite("User = " & $sAccount & @CRLF & "SID = " & $sStringSID & @CRLF) Local $sAccount = 'NetworkService' Local $tSID = _Security__GetAccountSid($sAccount) Local $sStringSID = _Security__SidToStringSid($tSID) ConsoleWrite("User = " & $sAccount & @CRLF & "SID = " & $sStringSID & @CRLF) Local $sAccount = 'LocalService' Local $tSID = _Security__GetAccountSid($sAccount) Local $sStringSID = _Security__SidToStringSid($tSID) ConsoleWrite("User = " & $sAccount & @CRLF & "SID = " & $sStringSID & @CRLF) Local $sAccount = 'System' Local $tSID = _Security__GetAccountSid($sAccount) Local $sStringSID = _Security__SidToStringSid($tSID) ConsoleWrite("User = " & $sAccount & @CRLF & "SID = " & $sStringSID & @CRLF) If this is what you are looking for, you can substitute that for the registry values under HKEY_USERS. Permissions for some of these keys are a whole different ballgame though. The Permissions UDF may be beneficial if needed.
Solution CodeHog Posted October 7, 2025 Author Solution Posted October 7, 2025 (edited) @WildByDesign The #include <Security.au3> did the trick. This script now identifies the current user's SID and inserts it into the $sSID template, enabling the addition of the value data needed to change the ShellNew template name. If you don't need msgbox confirmation, comment it out. So this is what I ended up with: expandcollapse popup#RequireAdmin #include <Security.au3> #include <Array.au3> #include <WinAPIFiles.au3> #include <WinAPISys.au3> ; Retrieve the current user SID Local $sUserName = @UserName Local $sComputer = @ComputerName Local $aUserSID = _Security__LookupAccountName(@UserName) If @error Or Not IsArray($aUserSID) Then MsgBox(16, "Error", "Unable to retrieve the current user SID.") Exit EndIf Local $sSID = $aUserSID[0] ; Show SID for verification MsgBox(64, "Detected SID", $sSID) ; .CMD Batch Script Template RegWrite('HKCR\.cmd\ShellNew', 'NullFile', 'REG_SZ', '') RegWrite('HKCR\.cmd\ShellNew', 'FileName', 'REG_SZ', 'C:\Windows\ShellNew\CMDSCRIPT.cmd') RegWrite('HKCR\.cmd\ShellNew', 'IconPath', 'REG_SZ', 'C:\Icons\Cmd.ico') Local $sRegPath1 = 'HKU\' & $sSID & '_Classes\Local Settings\MuiCache\129\52C64B7E' RegWrite($sRegPath1, '@C:\WINDOWS\System32\acppage.dll,-6003', 'REG_SZ', 'Batch Script Template') ; .DOCX Biz Letter Template RegWrite('HKCR\.docx\ShellNew', 'ItemName', 'REG_EXPAND_SZ', 'Biz Letter') RegWrite('HKCR\.docx\ShellNew', 'FileName', 'REG_SZ', 'C:\Windows\ShellNew\BIZLETTER.docx') RegWrite('HKCR\.docx\ShellNew', 'IconPath', 'REG_EXPAND_SZ', 'C:\Icons\Word.ico') Local $sRegPath2 = 'HKU\' & $sSID & '_Classes\Local Settings\MuiCache\129\52C64B7E' RegWrite($sRegPath2, '@C:\Program Files\Common Files\Microsoft Shared\Office16\oregres.dll,-123', 'REG_SZ', 'Formal Letter Template') ; .XLS Purchase Order Template RegWrite('HKCR\.xls\Excel.Sheet.8\ShellNew', 'FileName', 'REG_SZ', 'C:\Windows\ShellNew\PO.xls') RegWrite('HKCR\.xls\Excel.Sheet.8\ShellNew', 'IconPath', 'REG_EXPAND_SZ', 'C:\Icons\PO.ico') RegWrite('HKCR\.xls\Excel.Sheet.8\ShellNew', '', 'REG_SZ', 'Purchase Order') Local $sRegPath3 = 'HKU\' & $sSID & '\Software\Classes\Local Settings\MuiCache\129\52C64B7E' RegWrite($sRegPath3, '@C:\Program Files\Common Files\Microsoft Shared\Office16\oregres.dll,-101', 'REG_SZ', 'Invoice Template') Exit Also, just to complete the result I was trying to achieve here by modifying the shellnew menu, I created a new entry that links to the Nirsoft app ShellMenuNew v1.02 where you can configure ShellNew menu entries. Since Windows does not allow ShellNew entries to be actual executables, I created a new dummy template with the ".sn" extension that is basically an AutoIt .ax3 file that executes the Nirsoft app and then deletes itself after ShellMenuNew v1.02 appears. Now if I could just figure out a way to put this entry at the bottom of the ShellNew menu (which doesn't appear to be possible) my work would be complete: ; .SN Shell New Template-------------------------------- ; Associate .sn with new ProgID AutoIt3.SN RegWrite('HKCR\.sn', '','REG_SZ','AutoIt3.SN') ; Define the AutoIt3.SN file type (display name) RegWrite('HKCR\AutoIt3.SN', '','REG_SZ','~ShellNew App~ ') ; Icon for .sn files (change path to your true icon) RegWrite('HKCR\AutoIt3.SN\DefaultIcon', '','REG_SZ','C:\IconPath\MyShellNewico') ; Set open command to launch the .sn file using AutoIt RegWrite('HKCR\AutoIt3.SN\Shell\Open\Command', '','REG_SZ','"C:\Program Files\AutoIt3\AutoIt3.exe" "%1"') ; Add ShellNew entry for creating .sn files RegWrite('HKCR\.sn\ShellNew', 'FileName','REG_SZ','ShellEdit.a3x') ; ----------------------------------------------------------------------- ; .SN script to call ShellNew executable & then delete the template #RequireAdmin ; Execute ShellNewHandler.exe ShellExecute("C:\PATH-TO\ShellNewHandler.exe") ; Delete the script file after execution FileDelete(@ScriptFullPath) Exit Edited October 7, 2025 by CodeHog WildByDesign 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now