Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

567
Vistas
¿Ejecutar el comando CMD desde el archivo por lotes hta?

Tengo un script hta (archivo por lotes), que me muestra varios botones y cuando hago clic en estos quiero que se ejecute un comando en mi cmd. Por ejemplo, cuando presiono el botón "Dirección IP", el comando "ipconfig" debe ingresarse en el cmd y ejecutarse. ¿Que puedo hacer? ¿O es eso posible o hay otras opciones para ejecutar un comando a través de este script hta?

Saludos cordiales, jcjms

Aquí está mi código:

 <!-- :: Batch section @echo off setlocal echo Select an option: for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a" echo End of HTA window, reply: "%HTAreply%" goto :EOF --> <HTML> <HEAD> <HTA:APPLICATION SCROLL="no" SYSMENU="no" > <body bgcolor="black"> <TITLE>HTA Buttons</TITLE> <SCRIPT language="JavaScript"> window.resizeTo(374,400); function sleepFor( sleepDuration ){ var now = new Date().getTime(); while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } } function callShellApplication(command){ var args=document.getElementById('args').value; var r = new ActiveXObject("WScript.Shell"); var res=r.Exec(command +" "+args); var out=""; while (res.Status == 0) { sleepFor(100); } while (!res.StdOut.AtEndOfStream){ out=out+"\r\n"+res.StdOut.ReadLine(); } var StS=new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1); StS.Write(out); //new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(res.StdOut.ReadLine()); window.close(); } function closeHTA(reply){ var fso = new ActiveXObject("Scripting.FileSystemObject"); fso.GetStandardStream(1).WriteLine(reply); window.close(); } </SCRIPT> </HEAD> <BODY> Aruments:<textarea name="args" style="display:none; cols="40" rows="1"></textarea> <h1 style="color:white;font-size:40px;">Commands</h1> <hr> <button style="background-color:black; border-color:white; color:white" onclick='[what to do here? I want to shutdown other PCs in my local network over the window that opens in cmd (shutdown /iCODELOCK)]'>PC shutdown</button> <button style="background-color:black; border-color:white; color:white" onclick='[what to do here? I want to get the PCs IP in cmd (ipconfig)]'>IP-Adress</button> <button style="background-color:black; border-color:white; color:white" onclick="closeHTA(1);">close</button> </BODY> </HTML>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

En resumen, necesitas:

 onclick="callShellApplication('ipconfig')"

Un ejemplo de trabajo podría verse así:

 <html> <head> <HTA:APPLICATION SCROLL="yes" SYSMENU="no" /> <title>HTA Buttons</title> <script language="JScript"> //window.resizeTo(374,400); function callShellApplication(command){ var shell = new ActiveXObject("WScript.Shell"), exec = shell.Exec(command); output.innerHTML = exec.StdOut.ReadAll().replace(/\r\n/g, '<br>'); } </script> <style> *{color:white} button{background-color:black; border-color:white} </style> </head> <body bgcolor="black"> <h1 style="font-size:40px;">Commands</h1> <hr> <button onclick="callShellApplication('shutdown /s')">PC shutdown</button> <button onclick="callShellApplication('ipconfig')">IP-Adress</button> <button onclick="window.close()">close</button> <hr> <pre id="output"></pre> </body> </html>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Tenga cuidado, se supone que esos métodos se están depreciando, es un archivo de diseño html con seguridad relajada, por lo tanto, debe tener cuidado con la forma en que crea sus comandos cmd, javascript, vb script o PowerShell.

El método más fácil en ese formato híbrido es usar un método vb para generar y ejecutar botones, no hay problema para mezclar y combinar

Use una estructura de cuerpo más simple como esta, pero asegúrese de que su JavaScript funcione para pasar parámetros

 <HTML> <HEAD> <TITLE>HTA Example</TITLE> </HEAD> <BODY> <FORM> <INPUT TYPE="Run" NAME="Button" VALUE="Click Me"> <SCRIPT FOR="Button" EVENT="onClick" LANGUAGE="VBScript"> Set WshShell = CreateObject("WScript.Shell") WshShell.Run "cmd.exe /k echo off & echo/ & echo this could run IPconfig &IPconfig /? |more +38" </SCRIPT> </FORM> </BODY> </HTML>

ingrese la descripción de la imagen aquí

Para obtener más información sobre seguridad y mejoras como gráficos SVG, debe consultar https://docs.microsoft.com/en-us/previous-versions/ms536496(v=vs.85)

Cambió la pregunta agregando el código que debería haber estado en OP , por lo que sigo sugiriendo que lo más fácil es adaptar sus llamadas a vbscript simple

ingrese la descripción de la imagen aquí

en tu cabeza agrega para probar

 <SCRIPT FOR="shutdown" EVENT="onClick" LANGUAGE="VBScript"> Set WshShell = CreateObject("WScript.Shell") WshShell.Run "cmd.exe /k echo change /k to /c and remove this comment including echo's SHUTDOWN /iCODELOCK" </SCRIPT> <SCRIPT FOR="ipconfig" EVENT="onClick" LANGUAGE="VBScript"> Set WshShell = CreateObject("WScript.Shell") WshShell.Run "cmd.exe /k IPconfig" </SCRIPT>

cambia tus botones a

 <button style="background-color:black; border-color:white; color:white" name="shutdown">PC shutdown</button> <button style="background-color:black; border-color:white; color:white" name="ipconfig">IP-Adress</button> <button style="background-color:black; border-color:white; color:white" onclick="closeHTA(1);">close</button>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda