|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
1 Windows Script Host Windows () Resource Kit . Windows NT/2000/XP cmd.exe - - (script): , Windows .. Microsoft WSH Windows Script Host, , , , ( , (scripting engine), ActiveX Scripting). Visual Basic Script Edition (VBScript) JScript. , , WSH, ActiveX, ActiveX Microsoft. ActiveX , Windows (OLE, Object Linking and Embedding). OLE , () . , ( ), ( ), OLE Automation. OLE OLE Automation Microsoft "" COM (Component Object Model). , , , , . , . , . , - , (), , , . , Microsoft, OLE . Microsoft 1996 ActiveX, WWW (World Wide Web) (), . ActiveX Microsoft. Microsoft Office, Internet Explorer, IIS (Internet Information Service). : VBScript ( Microsoft Office, Internet Explorer, IIS) JScript ( Internet Explorer, IIS). , , , VBScript JScript, . WSH , ( ) (VBScript, JScript, PerlScript, REXX, TCL, Python ..), , , ActiveX. WSH Windows, HTML-. WSH WSH. WSH, Windows 98, 1.0. , JScript VBScript 5.0, Internet Explorer 5.0, WSH WSH 5.0. WSH, Windows 2000, 2.0; JScript VBScript 5.1. , WSH, Windows , Microsoft JScript VBScript WSH 5.6. , "WSH" Microsoft "Windows Scripting Host", "Windows Script Host".
WSH WSH Windows. WSH, , ( ). , . , WSH. ? , - . ? Windows , . ? Microsoft Office, , . ? , , . ? ( ). ? . ? (, ). JScript VBScript WSH-, JScript VBScript, js vbs , , " ".
, . JScript-, "!" (. 1.1). . 1.1. , , Windows (notepad.exe) First.js, : WScript.Echo("!"); VBScript, , : WScript.Echo "!" , , : , , . JScript , , : /*******************************************************************/ /* : First.js */ /* : JScript*/ /* : */ /*******************************************************************/ . 1.2. First.js VBScript : '******************************************************************* ': First.vbs ': VBScript ' : '******************************************************************* WSH .
WSH cscript.exe. , , C:\Script\First.js, cscript :\Script\First.js "!" (. 1.3). . 1.3. First.js (cscript.exe)
() WSH wscript.exe. wscript C:\Script\First.js (. 1.4). , , ( ), . . 1.4. First.js (wscript.exe)
(Run) (Start), (Open) (. 1.5). . 1.5. Windows wscript.exe, .. . Windows (Windows Explorer) Windows (. 1.6). . 1.6. Windows , (Start), wscript.exe.
, . (cscript.exe) (wscript.exe) -. , cscript.exe cscript.exe (. 1.1), WSH ( //). 1.1. cscript.exe
, cscript //Nologo C:\Script\First.js First.js WSH (. 1.7). , ( , WshArguments, WshNamed WshUnnamed). , cscript // C:\Script\First.js / /b First.js , / /b, //Bcscript.exe. . 1.7. First.js WSH , wscript.exe wscript.exe (Script) , Windows (. 1.8). wsh, ini-, : [ScriptFile] Path=C:\Script\First.js [Options] Timeout=0 DisplayLogo=1 Windows wsh- , (wscript.exe cscript.exe) , wsh- , Options .
. 1.8. First.js wscript.exe drag-and-drop Windows , , . WSH5.6 WSH 5.6. WSH : ? ( ) Windows; ? (. . ) , ; ? , , ; ? ; ? ; ? : , ; ? ; ? Windows; ? Windows; ? . WSH 5.6 : ? WScript. WSH, , , Windows. ? WshArguments. Windows. ? WshNamed. . ? WshUnnamed. . ? WshShell. , , , Windows. ? WshSpecialFolders. Windows. ? WshShortcut. Windows. ? WshUrlShortcut. . ? WshEnvironment. , . ? WshNetwork. : , . ? WshScriptExec. , . ? WshController. . ? WshRemote. , . ? WshRemoteError. , , . , FileSystemObject, ( 5). WSH.
WScript
WScript(wscript.exe cscript.exe), , , ( ). , WScript. WScript( ) Windows. , WSH WScript, - , . . . CreateObject, .
WScript. 1.2. 1.2.
WScript, . Arguments ( 1.1) for , . 1.1./*******************************************************************/ /* : ShowArgs.js */ /* : JScript */ /* : */ /*******************************************************************/ var i, objArgs; objArgs = WScript.Arguments; // WshArguments for (i=0; i<=objArgs.Count()-1; i++) WScript.Echo(objArgs(i)); // i- /************* *********************************************/ 1.4, 1.5, 2.22 2.23. StdErr, StdIn, StdOut
StdIn, StdOut StdErr, cscript.exe. wscript.exe, " Invalid Handle" (. 1.9). . 1.9. StdIn
StdOut StdErr Write, WriteLine, WriteBlankLines, StdIn Read, ReadLine, ReadAll, Skip, SkipLine. . 1.3. 1.3.
, Windows ( "|" ). . , , - ( FIND SORT). , example.js sort.txt: cscript //Nologo example.js | sort > sort.txt //Nologo , sort.txt WSH. , , StdIn, , . . . 1.2. 1.2./*******************************************************************/ /* : Interact.js */ /* : JScript */ /* : / 堠 */ /*******************************************************************/ var s; // WScript.StdOut.Write(" : "); // s = WScript.StdIn.ReadLine(); // WScript.StdOut.WriteLine(" " + s); /************* *********************************************/
WScript, . 1.4. 1.4.
, . 1.4. CreateObject CreateObject, (Programmic Identifier, ProgID). MYOBJ_", " OnBegin", " MYOBJ_OnBegin", .
CreateObject WshNetwork: var WshNetwork = WScript.Createobject("WScript.Network"); , WSH. JScript ActiveXObject, : var WshNetwork = new ActiveXObject("WScript.Network"); VBscript CreateObject, : Set WshNetwork = CreateObject("WScript.Network")
WScript.CreateObject. ConnectObject , ConnectObject, .
MyObject" SomeObject", SomeMetod. MyObject" MyEvent" . " Event", MyEvent_Event. DisconnectObject WScript MyObject. var MyObject = WScript.CreateObject("SomeObject"); MyObject.SomeMethod(); WScript.ConnectObject(MyObject, "MyEvent"); function MyEvent_Event(strName) { WScript.Echo(strName); } WScript.DisconnectObject(MyObject); DisconnectObject DisconnectObject(obj). DisconnectObject. Echo Echo, cscript.exe, (). . cscript.exe . Echo , . , EchoExample.js ( 1.3) cscript.exe , (. 1.10). 1.3. EchoExample.js/*******************************************************************/ /* : EchoExample.js */ /* : JScript */ /* : WScript.Echo */ /*******************************************************************/ WScript.Echo(); // WScript.Echo(1,2,3); // WScript.Echo("!"); // /************* *********************************************/ . 1.10. Echo
Echo2 (. 2.1, 2.2, 2.4 2.5). Sleep 5 : WScript.Echo(" , ..."); WScript.Sleep(5000); WScript.Echo(" ");
Sleep- , , WshShell.SendKeys(. 1.13, 2.31, 2.32). - WSH , , : ? Windows ( WshArguments, WshNamed WshUnnamed); ? ( WshEnvironment); ? Windows ( WshSpecialFolders). WshArguments
WshArgumentsWindows. Arguments WScript WshShortcut. , WshArgumentsJScript Enumerator moveNext, item atEnd. , , , ( 1.4). 1.4. ( JScript) /********************************************************************/ /* : EnumArgs.js */ /* : JScript */ /* : */ /********************************************************************/ var objArgs, e, x; objArgs = WScript.Arguments; // WshArguments // Enumerator objArgs e = new Enumerator(objArgs); for (;!e.atEnd();e.moveNext()) { x = e.item(); // WScript.Echo(x); // } /************* *********************************************/
Count Item WshArguments( ItemWSH). Count, . . , Item(n)n- ( ). , WshArguments, .
, ( 1.5). 1.5. ( WSH)/*******************************************************************/ /* : ShowArgs.js */ /* : JScript */ /* : */ /*******************************************************************/ var i, objArgs; objArgs = WScript.Arguments; // WshArguments for (i=0; i<=objArgs.Count()-1; i++) WScript.Echo(objArgs(i)); // i- /************* *********************************************/
WshArguments, (, /Name:Andrey) . , , . . , .
WshArguments: Named Unnamed.
Named WshNamed, Unnamed WshUnnamed. , : ? ( , ) WshArguments; ? , ( ) WshNamed; ? , ( ) WshUnnamed.
WshArguments ShowUsage. ( , ..). , WSH- XML; ShowUsage3 <runtime>, <description>, <example>, <named> <unnamed>. WshNamed
WshNamed, ( ). WSH 5.6 "/", , ":" , : /Name:Andrey , . , , . : /Name:"Andrey Popov" WshNamed Named WshArguments. , .
, MyScript.js : MyScript.js /User:Andrey /Computer:Server1 Name Computer : var objNamedArgs; objNamedArgs=WScript.Arguments.Named; WScript.Echo(" : "+objNamedArgs.Item("User")); WScript.Echo(" : "+objNamedArgs.Item ("Computer"));
var objNamedArgs; objNamedArgs=WScript.Arguments.Named; WScript.Echo(" : "+objNamedArgs("User")); WScript.Echo(" : "+objNamedArgs("Computer")); , , , , , : MyScript.js /User:"Andrey Popov" /Computer:Server1 MyScript.js : WScript.Echo(" : "+ WScript.Arguments.Named("User"));
: Andrey Popov , , Exists WshNamed. , if (WScript.Arguments.Named.Exists("User")) WScript.Echo(" : "+ WScript.Arguments.Named("User")); , WshNamed, 2 (. 2.22 2.23). WshUnnamed
WshUnnamed, ( ). Unnamed WshArguments. , ( ).
, MyScript.js : MyScript.js "Andrey Popov" Server1 MyScript.js : var objUnnamedArgs; obUnnamedArgs=WScript.Arguments.Unnamed; WScript.Echo(" : "+objUnnamedArgs.Item(0)); WScript.Echo(" : "+objUnnamedArgs.Item(1)); var objUnnamedArgs; obUnnamedArgs=WScript.Arguments.Unnamed; WScript.Echo(" : "+objUnnamedArgs(0)); WScript.Echo(" : "+objUnnamedArgs(1)); : : Andrey Popov : Server1 , WshUnnamed, 2 (. 2.22 2.23). WshEnvironment
WshEnvironment, ( , ). Environment WshShell: var WshShell=WScript.Createobject("WScript.Shell"), WshSysEnv=WshShell.Environment, WshUserEnv=WshShell.Environment("User");
WshEnvironment Length, ( ), Count Item. , Item. PATH: var WshShell=WScript.CreateObject("WScript.Shell"), WshSysEnv=WshShell.Environment; WScript.Echo(" :", WshSysEnv.Item("PATH")); : WScript.Echo(" :",WshSysEnv("PATH"); , WshEnvironment Remove(strName), . , 1.6 , ( EXAMPLE_1 EXAMPLE_2) . 1.6. /*******************************************************************/ /* : RemEnv.js */ /* : JScript */ /* : */ /*******************************************************************/ // WshShell var WshShell = WScript.CreateObject("WScript.Shell"); // WshEnvironment var WshUsrEnv = WshShell.Environment("User"); // WshUsrEnv.Remove("EXAMPLE_1"); WshUsrEnv.Remove("EXAMPLE_2"); /************* *********************************************/ WshSpecialFolders
WshSpecialFolders, Windows (, (Start)); , , . Windows 9 : ? Desktop; ? Favorites; ? Fonts; ? MyDocuments; ? NetHood; ? PrintHood; ? Programs; ? Recent; ? SendTo; ? StartMenu; ? Startup; ? Templates. Windows NT/2000/XP , : ? AllUsersDesktop; ? AllUsersStartMenu; ? AllUsersPrograms; ? AllUsersStartup.
WshSpecialFoldersc SpecialFolders WshShell: var WshShell=WScript.CreateObject("WScript.Shell"), WshSpecFold=WshShell.SpecialFolders; WSH, WshSpecialFolders Length Count Item. , ( 1.7). 1.7. WshSpecialFolders /*******************************************************************/ /* : ShowSpecFold.js */ /* : JScript */ /* : Windows */ /* ( WshSpecialFolders) */ /*******************************************************************/ var WshShell, WshFldrs, i; // WshShell WshShell = WScript.CreateObject("Wscript.Shell"); // WshSpecialFolders WshFldrs = WshShell.SpecialFolders; WScript.Echo(" ..."); // Desktop WScript.Echo("Desktop="+ WshFldrs.item("Desktop")); // Favorities WScript.Echo("Favorites="+ WshFldrs("Favorites")); // Programs WScript.Echo("Programs="+ WshFldrs("Programs")); WScript.Echo(""); WScript.Echo(" ..."); for (i=0;i<= WshFldrs.Count()-1;i++){ // i- WshFldrs WScript.Echo(WshFldrs(i)); } /************* *********************************************/ Windows 2 (. 2.392.42). Windows Windows ( , , ) WshNetwork WshShell. WshNetwork
WshNetwork; .
WshNetwork: var objNet=WScript.CreateObject("WScript.Network"); . 1.5. 1.5.
1.8. WshNetwork /*******************************************************************/ /* : ShowNetwork.js */ /* : JScript */ /* : 蠠 */ /* */ /*******************************************************************/ var objNet; // WshNetwork objNet = WScript.CreateObject("WScript.Network"); // ComputerName UserName WScript.Echo(" :",objNet.ComputerName); WScript.Echo(" :",objNet.UserName); /************* *********************************************/
WshNetwork. 1.6. 1.6.
. 1.6 . AddPrinterConnection True, .
AddPrinterConnection \\Server1\Epson LPT1: var WshNetwork = CreateObject("WScript.Network"); WshNetwork.AddPrinterConnection("LPT1", "\\Server1\Epson"); AddWindowsPrinterConnection LPT1). Windows NT/2000/XP strPort.
AddWindowsPrinterConnection LPT1( ): varWshNetwork=CreateObject("WScript.Network"); PrinterPath="\\printserv\DefaultPrinter"; PrinterDriver="Lexmark Optra S 1650"; WshNetwork.AddwindowsPrinterConnection(PrinterPath, PrinterDriver); EnumNetworkDrives , , . , ; . , , ( 1.9). 1.9.EnumNetworkDrives /*******************************************************************/ /* : ShowNetDrives.js */ /* : JScript */ /* : */ /* ⠠ */ /*******************************************************************/ var WshNetwork,oDrives,i; // WshNetwork WshNetwork = WScript.CreateObject("WScript.Network"); // oDrives = WshNetwork.EnumNetworkDrives(); for (i=0; i<=oDrives.Count()-1; i++) WScript.Echo(oDrives.Item(i)); // i- /************* *********************************************/ EnumPrinterConnections , . , , EnumNetworkDrives. , ( 1.10). 1.10.EnumPrinterConnections /*******************************************************************/ /* : ShowNetPrn.js */ /* : JScript */ /* : */ /* ⠠ */ /*******************************************************************/ // WshNetwork var WshNetwork = WScript.CreateObject("WScript.Network"); // var oPrinters = WshNetwork.EnumPrinterConnections(); for (i=0; i<=oPrinters.Count()-1; i++) WScript.Echo(oPrinters.Item(i)); // i- /************* *********************************************/ MapNetworkDrive True, . " z" \\Server1\Programs: var WshNetwork = WScript.CreateObject("WScript.Network"); WshNetwork.MapNetworkDrive("Z:","\\Server1\Programs"); RemoveNetworkDrive True, , . True, . "z" , ( 1.11). 1.11./*******************************************************************/ /* : MapDrive.js */ /* : JScript */ /* : / ࠠ */ /*******************************************************************/ // WshNetwork var WshNetwork = WScript.CreateObject("WScript.Network"); // Z:\ \\Server1\Programs WshNetwork.MapNetworkDrive("Z:","\\Server1\Programs"); // Z:\ WshNetwork.RemoveNetworkDrive("Z:"); /************* *********************************************/ RemovePrinterConnection RemoveNetworkDrive. , LPT1: var WshNetwork = WScript.CreateObject("WScript.Network"); WshNetwork.RemovePrinterConnection("LPT1:"); SetDefaultPrinter
AddPrinterConnectionLPT1: \\Server1\Epson, ( 1.12). 1.12. SetDefaultPrinter /*******************************************************************/ /* : DefPrn.js */ /* : JScript */ /* : */ /*******************************************************************/ // WshNetwork var WshNetwork = WScript.CreateObject("WScript.Network"); // LPT1 \\Server1\Epson WshNetwork.AddPrinterConnection("LPT1:","\\Server1\Epson"); // WshNetwork.SetDefaultPrinter("\\Server1\Epson"); /************* *********************************************/ , WshNetwork, 2 (. 2.472.52). WshShell
WshShell, , , Windows. : var WshShell=WScript.CreateObject("WScript.Shell");
WshShell, . 1.7. 1.7.
, WshShell(. 1.8). 1.8.
, . 1.8, . Activate
AppActivate( ), . , Run WshShell. , , title. , , title. , , . , ( ).
AppActivate1.13 RunCalc.js, Windows ( SendKeys). 1.13. RunCalc.js /*****************************************************************/ /* : RunCalc.js */ /* : JScript */ /* : ࠠ */ /*****************************************************************/ // WshShell var WshShell = WScript.CreateObject("WScript.Shell"); // WshShell.Run("calc"); // 0,1 WScript.Sleep(100); // WshShell.AppActivate("Calculator"); // 0,1 WScript.Sleep(100); // WshShell.SendKeys("1{+}"); WScript.Sleep(500); WshShell.SendKeys("2"); WScript.Sleep(500); WshShell.SendKeys("~"); WScript.Sleep(2500); /************* *********************************************/ 2 AppActivate(. 2.31 2.32). CreateShortcut . 1.14 , ( oShellLink( oUrlLink). 1.14. CreateShortcut /*****************************************************************/ /* : MakeShortcuts.js */ /* : JScript */ /* : */ /*****************************************************************/ var WshShell,oShellLink,oUrlLink; // WshShell WshShell=WScript.CreateObject("WScript.Shell"); // oShellLink=WshShell.CreateShortcut("Current Script.lnk"); // oShellLink.TargetPath=WScript.ScriptFullName; // oShellLink.Save(); // oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL"); // URL oUrlLink.TargetPath = "http://www.microsoft.com"; // oUrlLink.Save(); /************* *********************************************/ 1.191.24, 2.43 2.44. Environment WshEnvironment; "System" ( ), "User" ( ), "Volatile" ( ) "Process" ( ).
, Windows NT/2000/XP ( NUMBER_OF_PROCESSORS), Windows ( 1.15). 1.15. ( WshShell.Environment) /*****************************************************************/ /* : ShowEnvir.js */ /* : JScript */ /* : */ /*****************************************************************/ var WshShell,WshSysEnv; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // WshEnvironment WshSysEnv = WshShell.Environment("SYSTEM"); WScript.Echo(WshSysEnv("NUMBER_OF_PROCESSORS")); WScript.Echo(WshShell.Environment.Item("WINDIR")); /************* *********************************************/ ExpandEnvironmentString Windows ( 1.16). 1.16. (ExpandEnvironmertStrings) /*****************************************************************/ /* : ExpEnvStr.js */ /* : JScript */ /* : Windows */ /* : */ /* ExpandEnvironmentString */ /*****************************************************************/ var WS = WScript.CreateObject("WScript.Shell"); WScript.Echo(" Windows:"+WS.ExpandEnvironmentStrings("%WinDir%")); /************* *********************************************/ LogEvent Windows NT/2000/XP , Windows 9 WSH.log, Windows. WSH.log , . . 1.9. 1.9. (
( , , RunLoginScripttrue, false): var WshShell = WScript.CreateObject("WScript.Shell"); rc = RunLoginScript(); if (rc) WshShell.LogEvent(0,"Logon Script Completed Successfully"); else WshShell.LogEvent(1,"Logon Script failed"); Popup
nType, MessageBoxMicrosoft Win32 API. . 1.10 nType ( MessageBox Windows API). 1.10.
, VBScript, vbOkCancel. JScript-, (, var vbOkCancel=1;). , .
Popup, . 1.10. , : var WshShell = WScript.CreateObject("WScript.Shell"); WshShell.Popup(" ", 5, "",65); , . 1.11, 5 . . 1.11. , Popup Popup , , (. 1.11). 1.11.
Popup2 (. 2.13 2.14). RegDelete \\, ( ), . strName(. 1.12). 1.12.
, RegDelete, 2 (. 2.45 2.46). RegRead : REG_SZ, REG_EXPAND_SZ, REG_DWORD, REG_BINARY REG_MULTI_SZ. , RegRead DISP_E_TYPEMISMATCH. \\, ( ), .
RegRead( 1.17). 1.17. /********************************************************************/ /* : RegRead.js */ /* : JScript */ /* : */ /********************************************************************/ var WS,s; // WshShell WS = WScript.CreateObject("WScript.Shell"); s=" \n"; s+="HKCU\\Control Panel\\Keyboard\\KeyboardSpeed = "; // s+=WS.RegRead("HKCU\\Control Panel\\Keyboard\\KeyboardSpeed")+"\n\n"; s+=" \n"; s+="HKCU\\Control Panel\\Keyboard\\ = "; // s+=WS.RegRead("HKCU\\Control Panel\\Keyboard\\"); // WScript.Echo(s); /************* ***********************************************/ RegWrite \\, ; , . strName \\, ; , . REG_SZ", " REG_EXPAND_SZ", " REG_DWORD" " REG_BINARY". strType, RegWrite E_INVALIDARG. , REG_SZ" " REG_EXPAND_SZ", RegWrite anyValue. strType" REG_DWORD", anyValue. strType " REG_BINARY", anyValue. , RegWrite, 2 (. 2.45 2.46). Run 1.13. (
false, ( ). bWaitOnReturn true, . true, Run. bWaitOnReturn false, Run. (notepad.exe) : var WshShell = WScript.CreateObject("WScript.Shell"); WshShell.Run("%windir%\\notepad" + WScript.ScriptFullName); ( 1.18). 1.18./********************************************************************/ /* : RetCode.js */ /* : JScript */ /* : */ /********************************************************************/ // WshShell var WshShell = WScript.CreateObject("WScript.Shell"); // Return = WshShell.Run("notepad " + WScript.ScriptFullName, 1, true); // WScript.Echo(" :", Return); /************* ***********************************************/ Run 2 (. 2.31 2.32). SendKeys . , , , SendKeys"": string="AB". SendKeys : +, ^, %, ~, (, ). , {}. , {+}. []SendKeys , . , : {{}( ) {}}( ). , <Enter> <Tab> , SendKeys, . 1.14. 1.14.
<Shift>, <Ctrl> <Alt>, . 1.15. 1.15. <Shift>, <Ctrl> <Alt>
, , <Shift>, <trl> <Alt>, . , <G> <S> <Shift>, " +(GS)". , <Shift>+<G>, <S> ( <Shift>), " +GS". SendKeys . , . , {LEFT 42}<<> 42 ; {h 10}<h> 10 .
, SendKeys, 1.13, 2.31, 2.32.
Windows WSH: WshShortcut WshUrlShortcut. WshShortcut
WshShortcutWindows . CreateShortcut WshShell. 1.19 , ( ). 1.19. /*****************************************************************/ /* : MakeShortcut1.js */ /* : JScript */ /* : 頠 */ /*****************************************************************/ var WshShell,oShellLink; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // oShellLink = WshShell.CreateShortcut("Current Script.lnk"); // oShellLink.TargetPath = WScript.ScriptFullName; // oShellLink.Save(); /************* *********************************************/
WshShortcut. 1.16. 1.16.
WshShortcut. Arguments 1.20 , . 1.20./*****************************************************************/ /* : MakeShortcut2.js */ /* : JScript */ /* : */ /* 蠠 */ /*****************************************************************/ var WshShell,oShellLink; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // oShellLink = WshShell.CreateShortcut("Current Script.lnk"); // oShellLink.TargetPath = WScript.ScriptFullName; // oShellLink.Arguments = "-a abc.txt"; // oShellLink.Save(); /************* *********************************************/ HotKey "" , HotKey, , " +".
( 1.21) , "" <Ctrl>+ +<Alt>+<D>. 1.21. ""/*****************************************************************/ /* : MakeShortcut3.js */ /* : JScript */ /* : */ /* */ /*****************************************************************/ var WshShell,strDesktop,oMyShortcut; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // strDesktop = WshShell.SpecialFolders("Desktop"); // oMyShortcut = WshShell.CreateShortcut(strDesktop+"\\a_key.lnk"); // oMyShortcut.TargetPath = WshShell.ExpandEnvironmentStrings("%windir%\\notepad.exe"); // oMyShortcut.Hotkey = "CTRL+ALT+D"; // oMyShortcut.Save(); WScript.Echo(" : "+oMyShortcut.Hotkey); /************* *********************************************/ IconLocation , IconLocation: ", ". , , ( ). ( 1.22) ( 0) notepad.exe. 1.22. notepad.exe/*****************************************************************/ /* : MakeShortcut4.js */ /* : JScript */ /* : 頠 */ /* notepad.exe */ /*****************************************************************/ var WshShell,oShellLink; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // oShellLink = WshShell.CreateShortcut("Current Script.lnk"); // oShellLink.TargetPath = WScript.ScriptFullName; // notepad.exe oShellLink.IconLocation = "notepad.exe, 0"; // oShellLink.Save(); /************* *********************************************/ WindowStyle
WindowStyle intWindowStyle, , . 1.17. 1.17.
WorkingDirectory ( 1.23) , :. 1.23./*****************************************************************/ /* : MakeShortcut5.js */ /* : JScript */ /* : */ /* ࠠ */ /*****************************************************************/ var WshShell,oShellLink; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // oShellLink = WshShell.CreateShortcut("Notepad.lnk"); // oShellLink.TargetPath = "notepad.exe"; // oShellLink.WorkingDirectory = "c:\\"; // oShellLink.Save(); /************* *********************************************/
WshShortcut Save, , FullName. WshUrlShortcut
WshUrlShortcut. , WshShortcut, CreateShortcut WshShell. ( 1.24) www.microsoft.com. 1.24./*****************************************************************/ /* : MakeShortcut6.js */ /* : JScript */ /* : www.microsoft.com */ /*****************************************************************/ var WshShell,oUrlLink; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // oUrlLink = WshShell.CreateShortcut("Microsoft Web Site.URL"); // oUrlLink.TargetPath = "http://www.microsoft.com"; // oUrlLink.Save(); /************* *********************************************/
WshUrlShortcut: FullName TargetPath, WshShortcut.
WshUrlShortcut Save, , FullName.
WshShortcut2 (. 2.43 2.44).
WSH 5.6 , / . WshScriptExec. , , , . , , WshController, WshRemote WshRemoteError. WshScriptExec WSH 5.6 WshShell.Exec, .. , -. WshShell.Exec, , WScriptExec, / ( , , , ). , WshShell.ExecWindows-. WshScriptExec, (Process ID, PID), WshShell.AppActivate.
WScriptExec Terminate, . : var WshShell=WScript.CreateObject("WScript.Shell"); var ChildJob = WshShell.Exec("cscript ChildScript.js"); ChildJob.Terminate();
Terminate, WM_CLOSE. , . Terminate, .. , , . , , , .
WshScriptExec. 1.18. 1.18.
ProcessID ( MakeCalc.js) ProcessIDWindows. , WshShell.AppActivate"Calculator". 1.25. PID /*****************************************************************/ /* : MakeCalc.js */ /* : JScript */ /* : PID */ /*****************************************************************/ var WshShell, theCalculator; // WshShell WshShell = WScript.CreateObject("WScript.Shell"); // theCalculator = WshShell.Exec("calc"); // , // WScript.Sleep(500); // WshShell.AppActivate(theCalculator.ProcessID); // WshShell.SendKeys("1{+}"); WScript.Sleep(500); WshShell.SendKeys("2"); WScript.Sleep(500); WshShell.SendKeys("~"); /************* *********************************************/ Status - , , , . Status: Status0, , , Status1, . , 1.26 ChildStatus.js " " (. 1.12). 1.26. /*****************************************************************/ /* : ChildStatus.js */ /* : JScript */ /* : ࠠ */ /*****************************************************************/ var WshShell,theJob; // WshShell WshShell=WScript.CreateObject("WScript.Shell"); // theJob = WshShell.Exec("xcopy /?"); for (;;) { if (theJob.status==1) // break; // else WScript.Echo(" "); } WScript.Echo(" "); /************* *********************************************/ . 1.12. ChildStatus.js StdOut, StdIn StdErr c StdOut, StdIn StdErr WshScriptExec, WScript(. . 1.3). , 1.27 ConToWin.js wscript.exe, cscript.exe (. 1.13). . 1.13. ConToWin.js , cscript.exe DOS-, Windows-. DosToWin, : Windows-, : function DosToWin(s) { var i,ss; // //, RusDict if (typeof(RusDict)=="undefined") // RusDict , MakeRusDict(); ss=""; for (i=0;i<s.length;i++) { // if (RusDict.Exists(s.charAt(i))) // // i- Windows- ss+=RusDict.Item(s.charAt(i)); else ss+=s.charAt(i); } return ss; }
DosToWin Dictionary RusDict. MakeRusDict"""aee" , DOS-, , Windows-. // Dictionary "-", //""- DOS-, ""- , // Windows- function MakeRusDict() { // Dictionary RusDict = WScript.CreateObject("Scripting.Dictionary"); // "" ( DOS-)- "" ( //Window-) RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); }1.27. StdOut /*****************************************************************/ /* : ConToWin.js */ /* : JScript */ /* : DOS */ /* : StdOut ࠠ */ /*****************************************************************/ var WshShell,theJob,s,IsBreak,RusDict; // // Dictionary "-", //""- DOS-, ""- , // Windows- function MakeRusDict() { // Dictionary RusDict = WScript.CreateObject("Scripting.Dictionary"); // "" ( DOS-)- "" ( //Window-) RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); RusDict.add("", ""); } // DOS- Windows- function DosToWin(s) { var i,ss; // //, RusDict if (typeof(RusDict)=="undefined") // RusDict , MakeRusDict(); ss=""; for (i=0;i<s.length;i++) { // if (RusDict.Exists(s.charAt(i))) // // i- Windows- ss+=RusDict.Item(s.charAt(i)); else ss+=s.charAt(i); } return ss; } /************* *********************************************/ // WshShell WshShell=WScript.CreateObject("WScript.Shell"); // theJob = WshShell.Exec("cscript"); IsBreak=false; for (;;) { if (!theJob.StdOut.AtEndOfStream) // , StdOut // s+=theJob.StdOut.ReadAll(); if (IsBreak) break; if (theJob.status==1) //, IsBreak=true; else WScript.Sleep(100); } // Windows- // WScript.Echo(DosToWin(s)); /************* *********************************************/ , Exec , StdIn StdOut ( 2.37 2.38). WshController
WshController CreateScript- .
WshController : var WshController=WScript.CreateObject("WshController");
CreateScript WshRemote, . WSH : ? ; ? DCOM WshRemote; ? Execute WshRemote.
CreateScript: CreateScript(CommandLine, [MachineName]) WshRemote
WshRemote, . , , WshRemote, , . WshRemote CreateScript WshController: var Controller,RemoteScript; Controller=WScript.CreateObject("WshController"); RemoteScript=Controller.CreateScript("d: WscriptsWMyScript.js", "Server1");
WshRemote: Error Status.
Error WshRemoteError, , .
Status, . Status. 1.19. 1.19.
WshRemote( Execute) ( Terminate); . Terminate, WshScriptExec, , WM_CLOSE( , ). , WshRemote , . 1.20. 1.20.
, . 1.20, WshRemote ConnectObject WScript ( 1.28). 1.28. WshRemote (JScript)/**********************************************************************/ /* : RemoteEvents.js */ /* : JScript */ /* : , */ /* */ /**********************************************************************/ Var Controller,RemScript,IsQuit; // // WshController Controller = WScript.CreateObject("WshController"); // ( WshRemote) RemScript = Controller.CreateScript("D:\RemoteScript.js ", "stand"); // WshRemote WScript.ConnectObject(RemScript, "RemoteScript_"); RemScript.Execute(); // IsQuit = False; while (!IsQuit) WScript.Sleep(100); // 0,1 WScript.Quit(); // /*************** - ***********************/ function RemoteScript_End { // End WScript.Echo(" "); IsQuit = True; } function RemoteScript_Error { // Error // WScript.Echo(" : " + RemScript.Error.Description); IsQuit = True; } function RemoteScript_Start { // Start WScript.Echo(" "); } /************* *********************************************/ WshRemoteError
WshRemoteError. WshRemoteError Error WshRemote.
WshRemoteError. 1.21 ( ). 1.21.
Error WshRemote; 1.28, 2.56 2.57. |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | | | |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|