22-3 �I�s�䥦���ε{��

­Y­n°õ¦æ¨ä¥LÀ³¥Îµ{¦¡¡A¥i¥H¥ý²£¥Í¤@­Ó WSH ªº shell ª«¥ó¡AµM«á¦A¨Ï¥Î run() ¨ç¼Æ¨Ó©I¥s¨ä¥LÀ³¥Îµ{¦¡¡C

¨Ò¦p¡A­Y­n¼½©ñ¤@­ÓÁn­µÀɮסA§Ú­Ì¥i¥H©I¥s¿ý­µ¾÷¦b­I´º¼½©ñ¡A½d¨Ò¦p¤U¡G

­ì©lÀÉ¡]audioPlay01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¼½©ñ­µ°TÀÉ®×
audioFile = "chimes.wav";
shell = new ActiveXObject("Wscript.Shell");
command = "sndrec32 /play /close \"" + audioFile + "\"";
command = "soundRecorder /play /close \"" + audioFile + "\"";
command = "start " + audioFile;
WScript.echo(command);
shell.Run(command, 0);

°õ¦æ¤W­z½d¨Ò¡A´N¥i¥HÅ¥¨ì windows ±Ò°Êªº­µ®Ä¡C¡]½Ð°O±o­n§â³â¥z¥´¶}¡A¤~¯àÅ¥¨ì­µ®Ä¡C¡^¦b¤W­z½d¨Ò¤¤¡Ashell.Run(command, 0) ªº²Ä¤G­Ó°Ñ¼Æ 0¡A¥Nªí¤£¶}±Ò©Ò©I¥sÀ³¥Îµ{¦¡ªºµøµ¡¡C¦pªG§A©¿²¤¦¹°Ñ¼Æ¡]©Î±N¦¹°Ñ¼Æ³]©w¬° 1¡^¡A´N¥i¥H¬Ý¨ì¿ý­µ¾÷ªºµøµ¡¡C

Hint
§Ú­Ì·íµM¤]¥i¥H©I¥s´CÅé¼½©ñ¾¹¨Ó¼½©ñ¡A¦ý¬O³o¬O¡u±þÂû¥Î¤û¤M¡v¡A¦]¬°´CÅé¼½©ñ¾¹¤ÓªÎ¤ÓºC¤F¡I¨Ï¥Î¿ý­µ¾÷¨Ó¼½©ñÁn­µÀɮסA¤w¸g°÷§Ö°÷¦n¤F¡C

Hint
¤W­z½d¨Ò¥u¾A¥Î©ó Windows XP¡C¦pªGªº§@·~¨t²Î¬O Vista¡A§A¥²¶·±N sndrec32.exe §ï¦¨ SoundRecorder.exe¡C

§Ú­Ì¤]¥i¥H¨Ï¥ÎÃþ¦ü¤è¦¡¨Ó¶}±Ò¤pµe®a¡A¦ý¦¹®É shell.Run ªº²Ä¤G­Ó°Ñ¼Æ´N¥²¶·³]©w¦¨ 1¡A§_«h§A·|¬Ý¤£¨ì¤pµe®aªºµe­±¡A½d¨Ò¦p¤U¡G

­ì©lÀÉ¡]imageDisplay01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¨Ï¥Î¤pµe®aÅã¥Ü¼v¹³ÀÉ®×
imageFile = "annie.jpg";
shell = new ActiveXObject("Wscript.Shell");
command = "mspaint " + imageFile;
shell.Run(command, 1); 

¶}±Ò«áªºµe­±¦p¤U¡G

¤U¦C³o­Ó½d¨Ò¡A·|¶}±Ò DOS ©R¥Oµøµ¡¡]¨Ã¦C¥X°õ¦æ dir ªºµ²ªG¡^¥H¤Î¶}±Ò°O¨Æ¥»¡]¨Ã¸ü¤J run01.js¡^¡Aµ{¦¡½X¦p¤U¡G

­ì©lÀÉ¡]run01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¦p¦ó¥Ñ WSH °õ¦æ¨ä¥LÀ³¥Îµ{¦¡

shell = WScript.CreateObject("WScript.Shell");	// ²£¥Í WSH Shell
shell.Run("cmd /K dir");			// ¶}±Ò DOS ©R¥Oµøµ¡¨Ã°õ¦æ dir
shell.Run("wordpad.exe run01.js");		// ¶}±Ò°O¨Æ¥»¨Ã¸ü¤J¥»ÀÉ®×

¦b¤W­z½d¨Ò¤¤¡A©Ò¶}±ÒªºÀ³¥Îµ{¦¡·|«O«ù¶}±Òª¬ºA¡A¦Ó WSH ·|«ùÄò°õ¦æ¨ä«áªºµ{¦¡½X¡C­Y­nµ¥«ÝÀ³¥Îµ{¦¡³QÃö³¬«á¡A¤~Ä~Äò°õ¦æ¨ä«áªº WSH µ{¦¡½X¡A¥i¥H¦b run() ¤§«á¦A¥[¤W²Ä¤T­Ó°Ñ¼Æ¡A½Ð¸Õ¸Õ³o­Ó½d¨Ò¡G

­ì©lÀÉ¡]run02.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¦p¦ó¥Ñ WSH °õ¦æ¨ä¥LÀ³¥Îµ{¦¡¡A¨Ãµ¥«ÝÀ³¥Îµ{¦¡µ²§ô«á¤~Ä~Äò°õ¦æ WSH µ{¦¡½X

shell = new ActiveXObject("WScript.Shell");
intReturn = shell.Run("notepad " + WScript.ScriptFullName, 1, true);
shell.Popup("°O¨Æ¥»¤w¸g³QÃö³¬¡I");

¦b°õ¦æ¤W­z½d¨Ò®É¡AWSH ·|¥ý¶}±Ò°O¨Æ¥»¡A¨Ã°±¯d¦b°O¨Æ¥»¡Aª½¨ì°O¨Æ¥»³QÃö³¬«á¡A¤~·|Åã¥Üĵ§iµøµ¡¡C

Hint
¥H JScript ¼¶¼g WSH ®É¡A¤U­±¨â¦Cµ{¦¡½X³£¥i¥H²£¥Í shell ª«¥ó¡G
  1. shell = WScript.CreateObject("WScript.Shell");
  2. shell = new ActiveXObject("WScript.Shell");

§Ú­Ì¤]¥i¥H¨Ï¥Î Exec() ¨ç¼Æ¨Ó°õ¦æ¥t¤@­ÓÀ³¥Îµ{¦¡¡A¤U­Ó½d¨Ò¥´¶}¤pºâ½L¡A¨ÃÅã¥Ü¬ÛÃöªº¸ê°T¡G

­ì©lÀÉ¡]exec01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¥Ñ WSH ©I¥s­pºâ¾÷

WshShell = new ActiveXObject("WScript.Shell");
oExec = WshShell.Exec("calc.exe");
// ­Y¥¼¶}±Ò¡A«ùÄòµ¥«Ý¡Aª½¦Ü¶}±Ò§¹²¦
while (oExec.Status == 0)
	WScript.Sleep(100);
// ¦L¥X¬ÛÃö°T®§
WScript.Echo("Status = " + oExec.Status);
WScript.Echo("ProcessID = " + oExec.ProcessID);
WScript.Echo("ExitCode = " + oExec.ExitCode);


JScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©ó³æ¾÷ªº WSH Àô¹Ò