@@ -396,13 +396,45 @@ function _getMacDeviceID() {
396396 } ) ;
397397}
398398
399+ /**
400+ * Get the Windows device ID (MachineGuid).
401+ * @returns {Promise<string|null> }
402+ *
403+ * In a Windows batch file, you can get this with:
404+ * reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography /v MachineGuid
405+ */
406+ function _getWindowsDeviceID ( ) {
407+ return new Promise ( ( resolve , reject ) => {
408+ exec (
409+ 'reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid' ,
410+ { encoding : 'utf8' } ,
411+ ( err , stdout ) => {
412+ if ( err ) {
413+ console . error ( 'Failed to get Windows device ID:' , err . message ) ;
414+ return reject ( err ) ;
415+ }
416+
417+ // Example output:
418+ // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography
419+ // MachineGuid REG_SZ 4c4c4544-0034-5a10-8051-cac04f305a31
420+ const match = stdout . match ( / M a c h i n e G u i d \s + R E G _ [ A - Z ] + \s + ( [ a - f A - F 0 - 9 - ] + ) / ) ;
421+ if ( match && match [ 1 ] ) {
422+ resolve ( match [ 1 ] . trim ( ) ) ;
423+ } else {
424+ resolve ( null ) ;
425+ }
426+ }
427+ ) ;
428+ } ) ;
429+ }
430+
399431async function getDeviceID ( ) {
400432 if ( process . platform === "linux" ) {
401433 return _getLinuxDeviceID ( ) ;
402434 } else if ( process . platform === "darwin" ) {
403435 return _getMacDeviceID ( ) ;
404436 } else if ( process . platform === "win32" ) {
405- return "not implemented" ; //await _getWindowsDeviceID();
437+ return _getWindowsDeviceID ( ) ;
406438 }
407439 throw new Error ( `Unsupported platform: ${ process . platform } ` ) ;
408440}
0 commit comments