Setting function keys to perform action

I don't know if this is the correct forum for this; I need a way to set an action(command line preferably) when a certain key is pressed. Basically I want to set one of the function keys to close IE. I was planning on using taskkill from the command line.
I have scripting experience, but not any MS scripting languages. Don't really know where to start.
Thanks for any thoughts
[403 byte] By [landonec] at [2008-2-18]
# 1

You can use WScript.StdIn.Read or ReadLine and check the return string like so:

WScript.StdOut.Write("Please type a command key: ");
var key = WScript.StdIn.Read(1);
if (key == "k") WScript.Echo("Killing <process>");

To kill a process you can use WMI if the target computer supports it:

WScript.StdOut.Write("Please type a process name (with extension) to kill: ");
var name = WScript.StdIn.ReadLine();

var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
var procs = wmi.ExecQuery("select * from Win32_Process where Name = '" + name + "'");
var e = new Enumerator(procs);
for (; !e.atEnd(); e.moveNext()) {
var proc = e.item();
WScript.Echo("Terminating process ID " + proc.ProcessId);
proc.Terminate();
}

You can find more scripting examples at http://www.microsoft.com/technet/scriptcenter/default.mspx.

HeathStewart at 2007-10-6 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...

.NET Development

Site Classified