### Initialize NWinfo Context with libnw (C) Source: https://context7.com/a1ive/nwinfo/llms.txt Initializes the NWinfo context for hardware information retrieval. Configures output format, enables specific hardware modules (System, CPU, Disk, Network), and sets filtering flags. Requires libnw.h and COM initialization. ```c #include int main(int argc, char* argv[]) { NWLIB_CONTEXT nwContext; ZeroMemory(&nwContext, sizeof(NWLIB_CONTEXT)); // Configure output format nwContext.NwFormat = FORMAT_JSON; nwContext.BinaryFormat = BIN_FMT_BASE64; nwContext.CodePage = CP_UTF8; nwContext.HumanSize = TRUE; nwContext.Debug = FALSE; nwContext.HideSensitive = FALSE; nwContext.NwFile = stdout; // Enable specific information modules nwContext.SysInfo = TRUE; nwContext.CpuInfo = TRUE; nwContext.DiskInfo = TRUE; nwContext.NetInfo = TRUE; // Network filtering flags nwContext.NetFlags = NW_NET_ACTIVE | NW_NET_PHYS | NW_NET_IPV4; // Disk filtering flags nwContext.DiskFlags = NW_DISK_PHYS | NW_DISK_HD | NW_DISK_NVME; // Initialize COM CoInitializeEx(0, COINIT_APARTMENTTHREADED); // Initialize library NW_Init(&nwContext); // Generate and print report NW_Print("hardware_report.json"); // Cleanup NW_Fini(); CoUninitialize(); return 0; } ``` -------------------------------- ### Query Individual Hardware Components with libnw (C) Source: https://context7.com/a1ive/nwinfo/llms.txt Queries individual hardware information modules using libnw. Initializes a context, sets output to YAML to stdout, and then calls specific functions like NW_Cpuid(), NW_Disk(), etc. to retrieve data for each component. Requires libnw.h and COM initialization. ```c #include void query_hardware_modules(void) { NWLIB_CONTEXT ctx; ZeroMemory(&ctx, sizeof(NWLIB_CONTEXT)); ctx.NwFormat = FORMAT_YAML; ctx.NwFile = stdout; CoInitializeEx(0, COINIT_APARTMENTTHREADED); NW_Init(&ctx); // Query individual modules - each returns a node tree PNODE cpu_node = NW_Cpuid(); // CPU information PNODE disk_node = NW_Disk(); // Disk and S.M.A.R.T. PNODE smbios_node = NW_Smbios(); // SMBIOS tables PNODE net_node = NW_Network(); // Network interfaces PNODE pci_node = NW_Pci(); // PCI devices PNODE usb_node = NW_Usb(); // USB devices PNODE acpi_node = NW_Acpi(); // ACPI tables PNODE edid_node = NW_Edid(); // Display EDID PNODE gpu_node = NW_Gpu(); // GPU monitoring PNODE battery_node = NW_Battery(); // Battery status PNODE uefi_node = NW_Uefi(); // UEFI info PNODE spd_node = NW_Spd(); // Memory SPD PNODE system_node = NW_System(); // System info // Export individual nodes if (cpu_node) { NW_Export(cpu_node, stdout); NWL_NodeFree(cpu_node, 1); } NW_Fini(); CoUninitialize(); } ``` -------------------------------- ### PowerShell: Execute nwinfo to gather system information Source: https://context7.com/a1ive/nwinfo/llms.txt This PowerShell script first checks if it's running with administrator privileges and elevates if necessary. It then detects the correct nwinfo executable (64-bit or 32-bit), sets up various arguments for comprehensive system data collection (JSON format, UTF8 encoding, system, CPU, UEFI, GPU, display, SMBIOS, network, disk, audio), executes nwinfo, captures the JSON output, parses it, and displays key information such as computer name, OS, CPU brand and cores, motherboard details, and disk information including size and health status. It also groups SMBIOS data by table type. ```powershell if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltInRole] 'Administrator')) { Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`"" Exit } # Detect appropriate executable if (([Environment]::Is64BitOperatingSystem) -And (Test-Path ".\nwinfox64.exe")) { $programPath = ".\nwinfox64.exe" } else { $programPath = ".\nwinfo.exe" } # Configure arguments $programArgs = @( "--format=json", "--cp=utf8", "--human", "--sys", "--cpu", "--uefi", "--gpu", "--display", "--smbios", "--net=phys", "--disk=phys", "--audio" ) # Execute nwinfo and capture output $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.FileName = (Resolve-Path $programPath).Path $psi.Arguments = $programArgs -join " " $psi.RedirectStandardOutput = $true $psi.UseShellExecute = $false $psi.StandardOutputEncoding = [System.Text.Encoding]::UTF8 $proc = [System.Diagnostics.Process]::Start($psi) $jsonOutput = $proc.StandardOutput.ReadToEnd() $proc.WaitForExit() # Parse JSON $parsedJson = $jsonOutput | ConvertFrom-Json # Access data Write-Host "Computer: $($parsedJson.System.'Computer Name')" Write-Host "OS: $($parsedJson.System.'Os')" Write-Host "CPU: $($parsedJson.CPUID.CPU0.'Brand')" Write-Host "Cores: $($parsedJson.CPUID.CPU0.'Cores')" # Group SMBIOS by type $dmiTable = @{} foreach ($smbiosTable in $parsedJson.'SMBIOS') { $tableType = $smbiosTable.'Table Type' if ($tableType -ne $null) { if (-not $dmiTable.ContainsKey($tableType)) { $dmiTable[$tableType] = @() } $dmiTable[$tableType] += $smbiosTable } } # Access Base Board (Type 2) if ($dmiTable.ContainsKey(2)) { Write-Host "Motherboard: $($dmiTable[2][0].'Manufacturer') $($dmiTable[2][0].'Product Name')" } # List disks foreach ($disk in $parsedJson.'Disks') { Write-Host "Disk: $($disk.'HW Name') - $($disk.'Size') - $($disk.'Health Status')" } ``` -------------------------------- ### Create and Manipulate Node Tree with libnw (C) Source: https://context7.com/a1ive/nwinfo/llms.txt Demonstrates creating a custom node tree structure programmatically using libnw functions like NWL_NodeAlloc, NWL_NodeAppendNew, and NWL_NodeAttrSet. It shows how to add attributes to nodes, create table structures, and export the tree to a JSON file. Requires format.h and libnw. ```c #include "format.h" void create_custom_node_tree(void) { // Create root node PNODE root = NWL_NodeAlloc("Hardware", 0); // Create child node for CPU information PNODE cpu_node = NWL_NodeAppendNew(root, "CPU", 0); // Add attributes to CPU node NWL_NodeAttrSet(cpu_node, "Brand", "Intel Core i9-13900K", NAFLG_FMT_STRING); NWL_NodeAttrSetf(cpu_node, "Cores", NAFLG_FMT_NUMERIC, "%d", 24); NWL_NodeAttrSetf(cpu_node, "Threads", NAFLG_FMT_NUMERIC, "%d", 32); NWL_NodeAttrSetBool(cpu_node, "HyperThreading", TRUE, 0); // Create table node for memory modules PNODE memory_table = NWL_NodeAppendNew(root, "Memory", NFLG_TABLE); // Add memory module rows PNODE dimm0 = NWL_NodeAppendNew(memory_table, "DIMM0", NFLG_TABLE_ROW); NWL_NodeAttrSet(dimm0, "Slot", "DIMM_A1", 0); NWL_NodeAttrSet(dimm0, "Size", "16 GB", 0); NWL_NodeAttrSet(dimm0, "Type", "DDR5", 0); NWL_NodeAttrSetf(dimm0, "Speed", NAFLG_FMT_NUMERIC, "%d", 5600); PNODE dimm1 = NWL_NodeAppendNew(memory_table, "DIMM1", NFLG_TABLE_ROW); NWL_NodeAttrSet(dimm1, "Slot", "DIMM_B1", 0); NWL_NodeAttrSet(dimm1, "Size", "16 GB", 0); NWL_NodeAttrSet(dimm1, "Type", "DDR5", 0); NWL_NodeAttrSetf(dimm1, "Speed", NAFLG_FMT_NUMERIC, "%d", 5600); // Export to file in JSON format FILE* fp = fopen("custom_report.json", "w"); if (fp) { // Set output format (would need access to context) NW_Export(root, fp); fclose(fp); } // Free the node tree NWL_NodeFree(root, 1); // 1 = deep free (all children) } ``` -------------------------------- ### Monitor Disk S.M.A.R.T. Data with libcdi (C) Source: https://context7.com/a1ive/nwinfo/llms.txt This C function, monitor_disk_smart, utilizes the libcdi library to detect and monitor S.M.A.R.T. data for all disks in the system. It initializes the S.M.A.R.T. instance, retrieves disk counts, and iterates through each disk to update and display essential information such as model, serial number, firmware, type (SSD/HDD), temperature, power-on hours, size, RPM, health status, and detailed S.M.A.R.T. attributes. Dependencies include the libcdi library. The function returns no specific value but prints information to the console. ```c #include "libcdi/libcdi.h" void monitor_disk_smart(void) { // Create S.M.A.R.T. instance CDI_SMART* smart = cdi_create_smart(); if (!smart) { printf("Failed to create S.M.A.R.T. instance\n"); return; } // Initialize with specific detection flags UINT64 flags = CDI_FLAG_DEFAULT | CDI_FLAG_ADVANCED_SEARCH; cdi_init_smart(smart, flags); // Get number of detected disks INT disk_count = cdi_get_disk_count(smart); printf("Detected %d disk(s)\n", disk_count); // Iterate through all disks for (INT i = 0; i < disk_count; i++) { // Update S.M.A.R.T. data DWORD result = cdi_update_smart(smart, i); if (result != 0) { printf("Failed to update disk %d\n", i); continue; } // Get disk model WCHAR* model = cdi_get_string(smart, i, CDI_STRING_MODEL); wprintf(L"Disk %d: %s\n", i, model); cdi_free_string(model); // Get serial number WCHAR* serial = cdi_get_string(smart, i, CDI_STRING_SN); wprintf(L" Serial: %s\n", serial); cdi_free_string(serial); // Get firmware version WCHAR* firmware = cdi_get_string(smart, i, CDI_STRING_FIRMWARE); wprintf(L" Firmware: %s\n", firmware); cdi_free_string(firmware); // Get disk attributes BOOL is_ssd = cdi_get_bool(smart, i, CDI_BOOL_SSD); INT temperature = cdi_get_int(smart, i, CDI_INT_TEMPERATURE); INT power_on_hours = cdi_get_int(smart, i, CDI_INT_POWER_ON_HOURS); DWORD size = cdi_get_dword(smart, i, CDI_DWORD_DISK_SIZE); DWORD rotation = cdi_get_dword(smart, i, CDI_DWORD_ROTATION_RATE); printf(" Type: %s\n", is_ssd ? "SSD" : "HDD"); printf(" Temperature: %d C\n", temperature); printf(" Power On Hours: %d\n", power_on_hours); printf(" Size: %u MB\n", size); if (!is_ssd) { printf(" RPM: %u\n", rotation); } // Get health status INT status = cdi_get_int(smart, i, CDI_INT_DISK_STATUS); printf(" Health: %s\n", cdi_get_health_status(status)); // Get S.M.A.R.T. attributes INT attr_count = cdi_get_dword(smart, i, CDI_DWORD_ATTR_COUNT); printf(" S.M.A.R.T. Attributes (%d):\n", attr_count); for (INT j = 0; j < attr_count; j++) { BYTE id = cdi_get_smart_id(smart, i, j); WCHAR* name = cdi_get_smart_name(smart, i, id); WCHAR* value = cdi_get_smart_value(smart, i, j, FALSE); INT attr_status = cdi_get_smart_status(smart, i, j); wprintf(L" [%02X] %s = %s (Status: %d)\n", id, name, value, attr_status); cdi_free_string(name); cdi_free_string(value); } } // Cleanup cdi_destroy_smart(smart); } ``` -------------------------------- ### Python: Parse JEP106 Manufacturer ID PDF Source: https://context7.com/a1ive/nwinfo/llms.txt This Python script, designed to be run from the command line, parses a JEP106 PDF document to extract manufacturer ID codes and their corresponding names. It utilizes the PyMuPDF library to open and read the PDF, skipping initial pages and stopping at a specified appendix. The script identifies bank transitions and parses lines containing manufacturer codes and names, cleaning up extraneous information. The extracted data is then written to an output text file in a structured format, including document metadata and categorized manufacturer IDs. Dependencies include `sys` and `fitz` (PyMuPDF). ```python import sys import fitz # PyMuPDF import re # Added import for re def parse_jep106_pdf(input_path, output_path): """ Parse JEP106 PDF document and extract manufacturer ID codes. Args: input_path: Path to JEP106*.pdf file output_path: Output file for manufacturer ID database Output format: # JEP106BM # Version: 2024.01.15 1 1 AMD 2 AMI ... 2 1 Infineon ... """ doc = fitz.open(input_path) output_lines = [] # Extract document metadata output_lines.append('') output_lines.append("# JEP106BM") output_lines.append("# Version: 2024.01.15") current_bank = 0 START_PAGE = 5 for page_num in range(START_PAGE, len(doc)): page = doc.load_page(page_num) text = page.get_text("text") # Stop at appendix if "Annex A (informative) Name Changes" in text: break # Detect bank transitions if "The following numbers are all in bank" in text: current_bank += 1 output_lines.append(str(current_bank)) # Parse manufacturer entries: "123 Company Name" lines = text.split('\n') for line in lines: match = re.match(r'^(\d{1,3})\s+(.*)', line.strip()) if match: id_code, name = match.groups() if "Continuation Code" not in name: clean_name = re.sub(r'(\s+[01])+(\s+[0-9A-Fa-f]{2})?$', '', name) output_lines.append(f"\t{id_code} {clean_name.strip()}") # Write output file with open(output_path, 'w', encoding='ascii') as f: f.write('\n'.join(output_lines)) f.write('\n') print(f"Generated: {output_path}") if __name__ == '__main__': if len(sys.argv) != 3: print("Usage: python parse_jep106.py ") sys.exit(1) parse_jep106_pdf(sys.argv[1], sys.argv[2]) ``` -------------------------------- ### Generate Hardware Report with PowerShell Script Source: https://context7.com/a1ive/nwinfo/llms.txt This PowerShell script, hw_report.ps1, is designed to generate a hardware report for the NWinfo project. The script's primary function is to collect and present hardware-related information, likely leveraging system management tools or WMI. Further details on specific data points collected and output format are not provided in the snippet. ```powershell # hw_report.ps1 - Generate hardware report using NWinfo ``` -------------------------------- ### Retrieve Detailed CPU Information with libcpuid (C) Source: https://context7.com/a1ive/nwinfo/llms.txt This C function, get_detailed_cpu_info, uses the libcpuid library to gather comprehensive information about the CPU. It first retrieves raw CPUID data and then identifies the CPU to populate a struct with details such as vendor, brand, codename, family, model, stepping, core counts, cache sizes, and supported features (SSE, AVX, AES-NI, Hyper-Threading). It also measures and prints the current CPU clock speed. Dependencies include the libcpuid library. The function prints information to the console and returns no value. ```c #include void get_detailed_cpu_info(void) { struct cpu_raw_data_t raw; struct cpu_id_t data; // Get raw CPUID data if (cpuid_get_raw_data(&raw) < 0) { printf("Cannot get CPUID raw data: %s\n", cpuid_error()); return; } // Identify CPU if (cpu_identify(&raw, &data) < 0) { printf("Cannot identify CPU: %s\n", cpuid_error()); return; } // Print CPU information printf("CPU Information:\n"); printf(" Vendor: %s\n", data.vendor_str); printf(" Brand: %s\n", data.brand_str); printf(" Codename: %s\n", data.cpu_codename); printf(" Family: %d\n", data.family); printf(" Model: %d\n", data.model); printf(" Stepping: %d\n", data.stepping); printf(" Cores: %d\n", data.num_cores); printf(" Logical CPUs: %d\n", data.num_logical_cpus); printf(" L1 Cache: %d KB\n", data.l1_data_cache); printf(" L2 Cache: %d KB\n", data.l2_cache); printf(" L3 Cache: %d KB\n", data.l3_cache); // Check CPU features printf("\nFeatures:\n"); printf(" SSE: %s\n", data.flags[CPU_FEATURE_SSE] ? "Yes" : "No"); printf(" SSE2: %s\n", data.flags[CPU_FEATURE_SSE2] ? "Yes" : "No"); printf(" SSE3: %s\n", data.flags[CPU_FEATURE_SSE3] ? "Yes" : "No"); printf(" AVX: %s\n", data.flags[CPU_FEATURE_AVX] ? "Yes" : "No"); printf(" AVX2: %s\n", data.flags[CPU_FEATURE_AVX2] ? "Yes" : "No"); printf(" AES-NI: %s\n", data.flags[CPU_FEATURE_AES] ? "Yes" : "No"); printf(" Hyper-Threading: %s\n", data.flags[CPU_FEATURE_HT] ? "Yes" : "No"); // Get CPU clock speed int freq = cpu_clock_measure(200, 1); printf("\nCurrent Frequency: %d MHz\n", freq); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.