#197205 - 2009-12-23 04:40 AM
Re: HEX numbers larger than 7FFFFFFF
[Re: Bonji]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
|
Try this:Function ToHex($_V)
Dim $_Hc ; hex charset
Dim $_aD[0], $_aV ; array segments
Dim $_Dv ; intermediate value
Dim $_sH ; hex string
$_Hc = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
If VarType($_V) <> 5 Exit 87 EndIf ; must get a double!
$_I = -1 ; index pointer
$_Dv = 1.0 ; initial value
While $_V > $_Dv ; determine required multipliers
$_I = $_I + 1
ReDim Preserve $_aD[$_I]
$_aD[$_I] = $_Dv
$_Dv = 256.0 * $_Dv
Loop
; evaluate each hex octet and convert to a hex string
For $_I = UBound($_aD) To 0 Step -1
If $_V > $_aD[$_I]
$_aV = Int($_V / $_aD[$_I])
$_V = $_V - 1.0 * ($_aD[$_I] * $_aV)
$_sH = $_sH + $_Hc[$_aV / 16] + $_Hc[$_aV Mod 16]
Else
$_sH = $_sH + '00'
EndIf
Next
$ToHex = $_sH
Exit 0
EndFunction The function requires a double - either $V = 4048423081.0
ToHex($V) ? or$V = '4048423081'
$V = CDbl($V)
ToHex($V) ? It returns hex strings, not hex values. Since you're converting decimal to hex string to write to the registry, this should be fine. It seems to work fine with arbitrarily large numbers - I tested with small values and large values up to 750,000,000,000,000 (didn't test anything larger). I verified by using Calc in scientific mode.
It's imperative that it get a double-precision value.
If this works for you, I'll wrap it in a header and put it in the UDF section.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#197220 - 2009-12-24 09:17 PM
Re: HEX numbers larger than 7FFFFFFF
[Re: Bonji]
|
Bonji
Starting to like KiXtart
Registered: 2001-09-28
Posts: 169
Loc: Virginia
|
I will post what I ended up with to push UltraVNC ACLs (New MS Logon) directly to the registry without using the MSLogonACL.exe tool. This code isn't as pretty as it should be, but I just wanted to throw it out there as a resource in case it could help anyone. The 3rd and 5th binary values (which are passed as decimal) need to be changed depending on the number of entries you want to include. The values I include are for a single entry.
Since the local Administrator account is the only one I push that changes per machine, I programmatically determine the registry value for it and hard code the registry values for my domain accounts. I just configure VNC for the users I want, export the hex values out of the registry, and plug in the decimal equivalents into my code. After exporting various ACL configurations, you can figure out which hex values are static and must be included per user/group account.
Break On
$Computer = "TestComp"
$SID = AddLocalAdmin2VNC($Computer)
Function AddLocalAdmin2VNC($Computer)
Dim $oWMI, $oAccount, $LocalAdminSID, $arySID, $Hex4, $Hex5, $Hex6, $Hex7
Dim $ProcessSID, $oReg, $HKEY_LOCAL_MACHINE, $RegKey, $RegValueName, $RegValue, $aryBinarySID
$oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
If @Error
$ = MessageBox("Could not connect to " + $Computer + ".","Error")
Return
EndIf
$oAccount = $oWMI.Get("Win32_UserAccount.Name='Administrator',Domain='" + $Computer + "'")
$LocalAdminSID = $oAccount.SID
$arySID = Split($LocalAdminSID,"-")
$Hex4 = CDbl($arySID[4])
$Hex4 = ToHex($Hex4)
$Hex4 = ConvertSID($Hex4)
$Hex5 = CDbl($arySID[5])
$Hex5 = ToHex($Hex5)
$Hex5 = ConvertSID($Hex5)
$Hex6 = CDbl($arySID[6])
$Hex6 = ToHex($Hex6)
$Hex6 = ConvertSID($Hex6)
$Hex7 = CDbl($arySID[7])
$Hex7 = ToHex($Hex7)
$Hex7 = ConvertSID($Hex7)
$ProcessSID = $Hex4 + "," + $Hex5 + "," + $Hex6 + "," + $Hex7
$oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\default:StdRegProv")
If @Error
$ = MessageBox("Could not connect WMI Registry to " + $Computer + ".","Error")
Return
EndIf
$HKEY_LOCAL_MACHINE = CInt(2147483650.0)
$RegKey = "SOFTWARE\ORL\WinVNC3"
$RegValueName = "ACL"
$RegValue = "2,0,44,0,1,0,0,0,0,0,36,0,3,0,0,0,1,5,0,0,0,0,0,5,21,0,0,0," + $ProcessSID + ",0,0"
$aryBinarySID = Split($RegValue,",")
$ = $oReg.CreateKey($HKEY_LOCAL_MACHINE, $RegKey)
If @Error
$ = MessageBox("Could not create VNC Security registry key on " + $Computer + ".","Error")
Return
EndIf
$ = $oReg.SetBinaryValue($HKEY_LOCAL_MACHINE, $RegKey, $RegValueName, $aryBinarySID)
If @Error
$ = MessageBox("Could not modify VNC Security on " + $Computer + ".","Error")
Return
EndIF
EndFunction
Function ConvertSID($Hex)
Dim $Start, $HexStr, $NewHex, $aryTmp, $Element, $tmpElement
While Len($Hex) < 4
$Hex = "" + "0" + $Hex
Loop
$Start = 1
$HexStr = SubStr($Hex,$Start,2)
While $HexStr <> ""
$NewHex = $NewHex + $HexStr + ","
$Start = $Start + 2
$HexStr = SubStr($Hex,$Start,2)
Loop
$Hex = SubStr($NewHex,1,Len($NewHex) - 1)
ReDim $NewHex
$aryTmp = Split($Hex,",")
For Each $Element In $aryTmp
$tmpElement = Execute("Exit &" + $Element)
$NewHex = "" + $tmpElement + "," + $NewHex
Next
$ConvertSID = SubStr($NewHex,1,Len($NewHex) - 1)
EndFunction
Function ToHex($_V)
Dim $_Hc, $_aD[0], $_aV, $_Dv, $_sH
$_Hc = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
If VarType($_V) <> 5 ; must get a double!
Exit 87
EndIf
$_I = -1 ; index pointer
$_Dv = 1.0 ; initial value
While $_V > $_Dv ; determine required multipliers
$_I = $_I + 1
ReDim Preserve $_aD[$_I]
$_aD[$_I] = $_Dv
$_Dv = 256.0 * $_Dv
Loop
;Evaluate each hex octet and convert to a hex string
For $_I = UBound($_aD) To 0 Step -1
If $_V > $_aD[$_I]
$_aV = Int($_V / $_aD[$_I])
$_V = $_V - 1.0 * ($_aD[$_I] * $_aV)
$_sH = $_sH + $_Hc[$_aV / 16] + $_Hc[$_aV Mod 16]
Else
$_sH = $_sH + '00'
EndIf
Next
$ToHex = $_sH
Exit 0
EndFunction
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 581 anonymous users online.
|
|
|