[Javascript] Using Shell to copy text from CMD window

Tim Lewis twlewis at softhome.net
Tue Sep 18 10:17:57 CDT 2007


I am attempting to use JScript to copy the text from a DOS/CMD window. 
The script works fine for a Windows application such as Notepad, but will
not work for the CMD window.  What am I missing?  I have pasted my code.

Thank you for any recommendations.
Tim

<html><head>
<script language=JScript>
<!--
//_______________________________________________________________
function CaptureWindow() {
var WS = new ActiveXObject("WScript.Shell");
var strDOSWindow = "C:\WINDOWS\system32\cmd.exe";
var strSelectAll = "% ES"; //Select all text
var strCopyAll = "% EY"; //Copy all text to the clipboard
    WS.AppActivate(strDOSWindow,10);
    WS.SendKeys(strSelectAll,10);
    WS.SendKeys(strCopyAll,10);
var strData = PasteFromClipboard;
myform.tarOutput.value = strData;
}
//________________________________________________________________
function PasteFromClipboard() {
return window.clipboardData.getData("Text");
}
//________________________________________________________________
-->
</script>
</head>
<body onload=CaptureWindow()>
<form id=myform>
<textarea id=tarOutput rows=28 cols=63></textarea>
</form>
</body></html>





More information about the Javascript mailing list