If you are writing a JScript and need a way to copy some text to the clipboard, you can use the following definition:

// Uses Internet Explorer to copy text to the clipboard.
function copyToClipboard(text)
	var objIE;
		objIE = new ActiveXObject("InternetExplorer.Application");
		objIE.document.parentWindow.clipboardData.setData("Text", text);
		WScript.echo("The following error occurred while trying to "
		  + "access the system's clipboard using Internet Explorer:\n"
		 + e.description);
		return false;
	return true;

Here is an example code block that calls this function:

msg = "This message has just been copied to the system's clipboard.";

This function relies on the existence of Internet Explorer on the PC. Of course, this function is only guaranteed to work for stand-alone JS files or WSF files.

Categories: BlogJScript

Leave a Reply

Your email address will not be published. Required fields are marked *