|
-
September 6th, 2015, 06:57 AM
#1
Reading Windows 10 product ID with code.
I am trying to read the product ID with Windows 10.
With Windows 95 to windows 7, I could read the OEM number from the registry.
Using RegEdit.exe, I can read the value and it is still at the old Windows 7 OEM number location.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductID
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductID
The same code that worked with Windows 7 now returns an error value of 2.
I can create a WMIC file to read the product ID and save it to a file,
but this will display the WMIC file for a fraction of a second.
Dose anybody know of a good way to get the product ID?
Or code to read the registry at this location.
I am using Visual Basic 5.
Code:
regErrorValue = fReadValue("HKLM", "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductID", "S", "<Unknown ProductID>", sSetting)
OEM_number = sSetting
If OEM_number = "<Unknown ProductID>" Then
OEM_number = OEM_number_from_WMIC()
End If
'''
Private Function OEM_number_from_WMIC(Optional ByVal errorValue As String = "") As String
' Get the OEM / Product ID / OS Serial number.
' Note: This code will not work with Windows 7 or before.
' This code works with Windows 10.
' Not tested with Windows 8.0 or Windows 8.1
Const FileBytesOver = 10
Const FileOverXHours = 2
Dim InfoFile As String
Dim WMIC_bat_File As String
Dim fileHandle As Integer
Dim fileData As String
OEM_number_from_WMIC = errorValue
On Error GoTo WMIC_Error
InfoFile = "OEM_Information.txt"
WMIC_bat_File = App.path + "\_Read_OEM_value.bat"
' Step 1: Check if the 'InfoFile' file exists and is not too old.
' If GetFileSize(InfoFile) < 0 Then ' <0 = not found
' If GetFileSize(InfoFile) = 0 Then ' =0 = found but empty
If (frm_MainWindow.GetFileSize(InfoFile) < FileBytesOver) Or (DateDiff("H", frm_MainWindow.GetFileDate(InfoFile), Now) > FileOverXHours) Then
' File not found or under 10 bytes or over 5 hours old.
' Step 2: Create the WMIC_bat_File.
fileHandle = FreeFile
Open WMIC_bat_File For Output As #fileHandle
Print #fileHandle, "@REM Add @ to start of line to hide command line."
Print #fileHandle, "@REM Batch file " + WMIC_bat_File
Print #fileHandle, "@REM reads and saves the computer product id to file " + InfoFile
Print #fileHandle, "@REM This file was created on; " + Format$(Now, "d/mm/yyyy - h:nn:ssampm")
Print #fileHandle, ""
Print #fileHandle, "@REM Code by Mark A. Agius, (c)2015"
Print #fileHandle, ""
Print #fileHandle, "@CLS"
Print #fileHandle, "@WMIC /OUTPUT:" + InfoFile + " OS GET SERIALNUMBER"
' Print #fileHandle, "@ECHO File created..."
' Print #fileHandle, "@pause"
Close #fileHandle
fileHandle = 0
' Step 3: Run the WMIC_bat_File. (This will create the InfoFile file)
Call mod_FileOpen.Load_File_or_URL(WMIC_bat_File, "", 0)
End If
' Step 4: Read the InfoFile file and return the last line of text.
fileHandle = FreeFile
Open App.path + "\" + InfoFile For Input As #fileHandle
While Not EOF(fileHandle)
'Line Input #fileHandle, fileData ' Line input keeps spaces at end of line.
Input #fileHandle, fileData
fileData = Trim$(fileData)
If fileData <> "" Then
' Computer product id is 23 characters long with Windows 10.
If Len(fileData) >= 20 And Len(fileData) <= 45 Then
OEM_number_from_WMIC = fileData
End If
End If
Wend
Close #fileHandle
fileHandle = 0
Exit Function
WMIC_Error:
' Error code.
' OEM_number_from_WMIC = "<" + Error + " (" & Err & ")>"
Exit Function
End Function
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|