Getting SID, renaming all names associated with ahk Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Botsy
Posts: 19
Joined: 25 Aug 2020, 16:59

Getting SID, renaming all names associated with ahk

Post by Botsy » 09 Nov 2020, 14:34

I think to bind the script to the SID, to avoid multi-use.
- Is it possible to get the SID in the code not through the registry? For example via cmd / powershell -> whoami / user? Maybe this is a better option.

Code: Select all

#NoEnv 

F10::

regSID := rgtSID() 
msgbox, %regSID%

rgtSID()
{
	loop,HKLM,SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList,1,1
	{
		if(a_loopRegName="ProfileImagePath")
		{
		regRead,rProf
		if(inStr(rProf,a_userName))
		stringReplace,SID,a_loopRegSubKey,SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\,,
		}
	}
	return % SID
}

return
I thought not to create two topics, but write in one. All the same, this refers to the preservation of information.
- How can you rename everything related to AHK? For example, the name of the process, change the icon and the rest, than you can associate the program with AHK.

It seems logical to rename it in order to slow down the definition of what exactly the program was written on.
If you already have this information somewhere, I will be grateful for the link or tip.

User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Getting SID, renaming all names associated with ahk  Topic is solved

Post by TheDewd » 09 Nov 2020, 17:19

Botsy wrote:
09 Nov 2020, 14:34
Is it possible to get the SID in the code not through the registry?

Code: Select all

; autohotkey.com/board/topic/73256-solvedwhy-executing-the-method-of-wmi-is-failure/?p=465005

strComputer := "."
strNamespace := "\root\cimv2"
strClass := "Win32_Process"
strHandle := DllCall("GetCurrentProcessId")    

objSWbemServices := ComObjGet("winmgmts:\\"  strComputer  strNamespace)
objService := objSWbemServices.Get("Win32_Process.Handle='" strHandle "'")
Sid := ComVar()
Result := objService.GetOwnerSid(Sid.ref)
if !Result
  MsgBox, % sid[]


ComVar(Type=0xC)
{
    static base := { __Get: "ComVarGet", __Set: "ComVarSet", __Delete: "ComVarDel" }
    ; Create an array of 1 VARIANT.  This method allows built-in code to take
    ; care of all conversions between VARIANT and AutoHotkey internal types.
    arr := ComObjArray(Type, 1)
    ; Lock the array and retrieve a pointer to the VARIANT.
    DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(arr), "ptr*", arr_data)
    ; Store the array and an object which can be used to pass the VARIANT ByRef.
    return { ref: ComObjParameter(0x4000|Type, arr_data), _: arr, base: base }
}
ComVarGet(cv, p*) { ; Called when script accesses an unknown field.
    if p.MaxIndex() = "" ; No name/parameters, i.e. cv[]
        return cv._[0]
}
ComVarSet(cv, v, p*) { ; Called when script sets an unknown field.
    if p.MaxIndex() = "" ; No name/parameters, i.e. cv[]:=v
        return cv._[0] := v
}
ComVarDel(cv) { ; Called when the object is being freed.
    ; This must be done to allow the internal array to be freed.
    DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(cv._))
}

Botsy
Posts: 19
Joined: 25 Aug 2020, 16:59

Re: Getting SID, renaming all names associated with ahk

Post by Botsy » 11 Nov 2020, 04:33

TheDewd Thanks for the alternative method, works great!

Post Reply

Return to “Ask for Help (v1)”