#213139 - 2018-01-12 10:46 PM
Re: Convert Dell service tag to Dell express service code
[Re: Allen]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
|
Top
|
|
|
|
#213142 - 2018-01-15 01:37 PM
Re: Convert Dell service tag to Dell express service code
[Re: Mart]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Hmmm..... does not seem to work ok. It's an older UDF but the conversions should be the same. With the example below I get incorrect results. When I use the example DOC posted in the link above and take out the WMI check part because it fails on Win 10 v1703 (see second code section below) I also get incorrect results. The info it takes from the BIOS is ok but the conversion gives me incorrect data.
I removed the actual service tag and expr. service code to prevent any issues with them in the future. If you want/need them for testing, let me know and I'll PM them to you.
Break on
$rc = SetOption("WrapAtEOL", "On")
$stag = "xxxxxxx"
$expscode = "12345678901"
$conv = BaseConverter($stag, 36, 10)
?$conv
$conv = BaseConverter($expscode, 10, 36)
? $conv
Sleep 15
;Function BaseConverter()
;
;Authors
; Howard Bullock
; BrianTX
; Shawn Tassie
; Jooel Nieminen
;
;Version 1.0.1
;
;Version history
; 1.0.1 (5.6.2004) - fixed annoying variable scope problem
; 1.0 (7.7.2002) - initial kixgolf code
;
;Action Converts bases 2-36 from any to any
;
;Syntax BaseConverter($Value, $From, $To)
;
;Parameters
; $Value - String or Integer, Value to be converted
; $From - Integer, Base where convert from
; $To - Integer, Base to convert to
;
;Remarks
; Code was produces as kixgolf-competition.
; For More info see topics:
; http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=2;t=003447
; http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=2;t=003458
; http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=2;t=003470
; Thanks to:
; Sealeopard - our host on the competition
; Kholm - for participating
;
;Returns
; on success: Value converted to specified base
; on error: nothing. sets error to 1
;
;Dependencies
; None
;
;Example
; "Value 44680832201 is in base10" ?
; "when converted to base36 it's '"
; BaseConverter('44680832201', 10, 36)
; "'"
;
;Source
Function BaseConverter($v, $f, $t)
Dim $, $e, $y, $n, $x, $z
$ = 0
$t = $ + $t
$f = $ + $f
$e = ($f > 36) | ( $t > 36 ) | ( $f < 2 ) | ( $t < 2 )
$y = 1.
For $n = Len($v) to 1 step - 1
$x = Asc(UCase(SubStr($v, $n, 1)))
$z = ($x - 48 - ($x > 64) * 7)
If ($z < 0) | ( ($x > 57) & ( $x < 65 ) ) | $e | ( $z > ( $f - 1 ) )
Exit 1
EndIf
$ = $y * $z + $
$y = $y * $f
Next
$n = ""
While $
$x = Int($ - (Int($ / $t) * $t))
$ = ($ - $x) / $t
$n = Chr($x + 48 + ($x > 9) * 7) + $n
Loop
$BaseConverter = $n
EndFunction
Example based on code DOC posted.
Break On
Dim $SO
$SO = SetOption('Explicit', 'On')
$SO = SetOption('NoVarsInStrings', 'On')
$SO = SetOption('NoMacrosInStrings', 'On')
Dim $Chk, $MyBIOSInfo
Dim $Mfg, $Model, $Ser, $Esc
;$Chk = WMIConfirm('computer name')
;If $Chk
$MyBIOSInfo = GetBIOSInfo()
If VarType($MyBIOSInfo) > 8
$Mfg = $MyBIOSInfo[0]
'Mfg: ' + $Mfg ?
$Model = $MyBIOSInfo[1]
'Model: ' + $Model ?
$Ser = $MyBIOSInfo[2]
'Serial / Tag number: ' + $Ser ?
$Esc = BaseConverter($Ser, 36, 10)
'Express Service Code: ' + $Esc ?
Else
'Error getting BIOS information. ' + @ERROR + ' - ' + @SERROR ?
EndIf
;Else
; 'Error accessing WMI. ' + @ERROR + ' - ' + @SERROR ?
;EndIf
Sleep 20
Function WMIConfirm(optional $sComputer)
Dim $objWMIService, $objWMISetting, $colWMISettings
$sComputer = IIf(Not $sComputer, '', '\\' + Join(Split($sComputer, '\'), '', 3) + '\')
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" + $sComputer + 'root\cimv2')
; Failed - return 0 and exit with error value
If @ERROR
$WMIConfirm = 0
Exit Val('&' + Right(DecToHex(@ERROR), 4))
EndIf
$colWMISettings = $objWMIService.ExecQuery("Select * from Win32_WMISetting")
For Each $objWMISetting in $colWMISettings
$WMIConfirm = $objWMISetting.BuildVersion
Next
Exit 0
EndFunction
Function GetBIOSInfo(optional $sComputer)
Dim $objWMIService, $Mfg, $Model, $Ser
Dim $M, $S, $SerialNumber, $Manufacturer
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" + $sComputer + 'root\cimv2')
If @ERROR
$GetBIOSInfo = 0
Exit Val('&' + Right(DecToHex(@ERROR), 4))
EndIf
$Mfg = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",, 48)
$Ser = $objWMIService.ExecQuery("Select * from Win32_BIOS",, 48)
For Each $M in $Mfg
If $M
$Manufacturer = Trim($M.Manufacturer)
$Model = Trim($M.Model)
EndIf
Next
For Each $S in $Ser
If $S
$SerialNumber = Trim($S.SerialNumber)
EndIf
Next
$GetBIOSInfo = $Manufacturer, $Model, $SerialNumber
Exit 0
EndFunction
Function BaseConverter($v, $f, $t)
Dim $, $e, $y, $n, $x, $z
$ = 0
$t = $ + $t
$f = $ + $f
$e = ($f > 36) | ( $t > 36 ) | ( $f < 2 ) | ( $t < 2 )
$y = 1.
For $n = Len($v) to 1 step - 1
$x = Asc(UCase(SubStr($v, $n, 1)))
$z = ($x - 48 - ($x > 64) * 7)
If ($z < 0) | ( ($x > 57) & ( $x < 65 ) ) | $e | ( $z > ( $f - 1 ) )
Exit 1
EndIf
$ = $y * $z + $
$y = $y * $f
Next
$n = ""
While $
$x = Int($ - (Int($ / $t) * $t))
$ = ($ - $x) / $t
$n = Chr($x + 48 + ($x > 9) * 7) + $n
Loop
$BaseConverter = $n
EndFunction
Edited by Mart (2018-01-15 01:42 PM) Edit Reason: Removed actual service tag and expr. service code.
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#213145 - 2018-01-16 10:53 AM
Re: Convert Dell service tag to Dell express service code
[Re: NTDOC]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
This was interesting and took some hours figuring out, stoke and me had some fun with it and whipped up a UDF.
Function baseN2dec($value, $inBase)
Dim $strValue, $i, $c, $y
$strValue = CStr(UCase($value))
For $i=1 To Len($strValue)
$c = Asc(SubStr($strValue, $i, 1))
If ($i > 1)
$y = CDBL($y) * $inBase
EndIf
If ($c < 65)
$c = $c - 48
Else
$c = $c - 55
EndIf
$y = $y + $c
Next
$baseN2dec = $y
EndFunction
Dim $strServiceTag, $strExpresCode
$strServiceTag = "G51JIC1" ;modified this to a non-existant service tag
$strExpresCode = baseN2dec($strServiceTag,36)
? "Serial Number: " + $strServiceTag
? "Express Code: " + $strExpresCode
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1005 anonymous users online.
|
|
|