Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Gets new available Windows license from a .json with a list of MAK keys, updates that db, and executes Windows licensing process with it
- Dependencies:
- - node.exe : executable only, no installation needed, put the exe in the same folder of this .js
- - .json : file with licenses:
- example json DB:
- {
- "sinUsar": [
- "XXXXX-XXXXX-XXXXX-XXXXX-XXXX1",
- "XXXXX-XXXXX-XXXXX-XXXXX-XXXX2",
- ],
- "usadas": [
- "XXXXX-XXXXX-XXXXX-XXXXX-XXXX3"
- ]
- }
- example of .bat file to execute in a client pc, from a shared network folder where this .js and node.exe are chared
- REM cd /d %~dp0/licenciarWindows
- net use k: \\SOME-COMPUTER\compartida
- cd /d k:\licenciarWindows
- node.exe licenciarWindows.js
- */
- async function main() {
- const fs = require('fs')
- // abrir db de licencias
- const licenciasFile = __dirname + '/licenciasWin7Pro2018.json'
- let licencias = JSON.parse( fs.readFileSync(licenciasFile, 'UTF8') )
- // conseguir la siguiente licencia sinUSAR
- let unaLicencia = licencias.sinUsar.pop()
- // console.log(unaLicencia)
- // meter la licencia en 'usadas' y guardar bd de licencias actualizada
- licencias.usadas.push( unaLicencia )
- fs.writeFileSync( licenciasFile, JSON.stringify(licencias,null,2).replace(/\n/g, '\r\n'), 'UTF8' ) // use windows CRLF to be notepad.exe friendly
- // licenciar Windows
- execCmdSync(`slmgr /ipk ${unaLicencia}`)
- execCmdSync(`slmgr /ato`)
- // si necesitas cosas asíncronas, así de facil
- // var respuesta = await readLine('¿pregunta?')
- // console.log('pues si', respuesta)
- }
- main().then(process.exit) // así para poder usar await comodamente en main()
- // --------------------------------------------------------- HELPERS
- function execCmdSync (command) {
- console.log(command)
- var child_process = require('child_process')
- let result = child_process.spawnSync(
- process.env.comspec,
- `/c ${command.trim()}`.split(' '),
- {stdio: 'inherit'}
- ).status
- console.log(result)
- return result
- }
- async function readLine (question) {
- const readline = require('readline')
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
- let answer = await new Promise(resolve=>{
- rl.question(question + " ", (answer) => {
- rl.close();
- resolve(answer)
- })
- })
- return answer
- }
Add Comment
Please, Sign In to add comment