In Windows and , the script worked fine as the two OS have csript. However, in Windows NT 4, it does not seem to have this executable. You need WSH 5. It should be available on Windows Update or you can download it here.
You know NT4 isn't supported any more? There is a newer version, 5. So, perhaps Microsoft removed NT because it has been end-of-lifed? Or perhaps they did a minor update to 5. Stack Overflow for Teams — Collaborate and share knowledge with a private group. The Path property returns the name of the directory containing the host executable file cscript. This returns a read-only string. The ScriptFullName property returns the full path of the currently running script. This property returns a read-only string.
The ScriptName property returns the file name of the currently running script. The following code echoes the name of the script being run, as shown in Figure The StdErr property exposes the write-only error output stream for the current script. It returns an object representing the standard error stream. Note that attempting to access these streams while using wscript. The StdIn property exposes the read-only input stream for the current script. The StdOut property exposes the write-only error output stream for the current script.
The following example makes use of all three of the built-in stream types to print a list of all files matching a particular extension. This is implemented by piping the output from the DOS dir command into the filter script, with an extension string passed as an argument. Since this example uses StdIn , StdOut , and StdErr for all messaging, you could use it not only to print out matching files to the screen, but also to send output to a text file or another application with redirection or additional piping.
For example, you could create a file containing all. This property returns the version of WSH. The following code echoes the current version of WSH, as shown in Figure Objects created with the CreateObject method using the strPrefix argument are connected objects. The object's outgoing interface is connected to the script file after the object is created.
Event functions are a combination of this prefix and the event name. If you create an object and do not provide the strPrefix argument, you can still synchronize events on the object by using the ConnectObject method. When the object fires an event, WSH calls a subroutine with strPrefix attached to the beginning of the event name. Connected objects are useful when you want to synchronize an object's events.
The ConnectObject method connects the object's outgoing interface to the script file after creating the object. Disconnecting an object means that WSH will no longer respond to its events. It is important to note though that the object is still capable of firing events.
Note also that the DisconnectObject method does nothing if the specified object is not already connected. The GetObject method retrieves an existing object with the specified ProgID , or creates a new one from a file.
You use the GetObject method when an instance of the object exists in memory or when you want to create the object from a file. The GetObject method can be used with all COM classes, independent of the scripting language used to create the object. If no current instance exists and you do not want the object created from a file, use the CreateObject method. The Quit method can be used to return an optional error code. If the Quit method is the final instruction in your script and you have no need to return a nonzero value , you can leave it out, and your script will terminate normally.
This method suspends script execution for a specified length of time, and then continues execution. When using this method the thread running the script is suspended and CPU utilization is released. Execution resumes when the interval expires. To be triggered by an event, a script must be continually active because a script that has finished executing will certainly not detect an event.
Events handled by the script will still be executed during a sleep. The use of arguments in programming tasks is a very useful mechanism for providing your script with input on which it can act.
Think about working at a DOS prompt. Most command-line executable files use arguments in order to determine the right thing to do. For example, navigating within a directory structure. In this instance, cd is the name of a DOS command for change directory , while wsh is the name of the directory activated-it is an argument passed to cd. Creating scripts that work with arguments is a good step toward writing reusable code.
Developers creating scripts designed to execute on the command line may immediately see the benefits of working with the Arguments property. However, within WSH, there is another good reason to use this object, as this is how drag-and-drop functionality is implemented. A final justification for the use of this object is that it allows developers to reuse script code within other scripts, by running the script in question as if it were executing on the command line, passing whatever arguments may be necessary at runtime.
The interesting thing here is that this works in both cscript and wscript. You can try this out for yourself using the echoargs. Execute on the command line, passing a few arguments:. Now try dragging a file or two, then dropping them on echoargs. Figure shows the output resulting from this. Windows Script Host provides a convenient way to gain access to system environment variables , create shortcuts, access Windows special folders such as the Windows Desktop, and add or remove entries from the registry.
It is also possible to create more customized dialog boxes for user interaction by using features of the Shell object. Programmers should create an instance of the object WScript. Shell in order to be able to work with the properties listed in the next section.
Further references to the WshShell object will refer to this created instance. The CurrentDirectory property returns a string that contains the fully qualified path of the current working directory of the active process. The Environment property contains the WshEnvironment object a collection of environment variables.
If strType is supplied, it specifies where the environment variable resides with possible values of:. If strType is not supplied, the Environment property returns different environment variable types depending on the operating system. None of the others can be used in scripts. The following table lists some of the variables that are provided with the Windows operating system. Note that scripts can access environment variables that have been set by other applications and that none of the variables listed above are available from the Volatile type.
Here is an example of how to use the variables listed in the table in your code. This returns the number of processors present on the system. The WshSpecialFolders object is a collection. This contains the entire set of Windows special folders, which include the Desktop folder, the Start Menu folder, and the My Documents folder.
The special folder name is used to index into the collection to retrieve the special folder you want. The SpecialFolders property returns an empty string if the requested folder strFolderName is not available. The WshShell object has 11 methods. All these methods relate to the operating system shell and allow you control over the Windows registry, as well as being able to create pop-ups and shortcuts and activate and control running applications:.
The AppActivate method returns a Boolean value that identifies whether the procedure call is successful. This method is used to change the focus to the named application or window. It does not affect whether it is maximized or minimized. Specifies batch mode, which does not display alerts, scripting errors, or input prompts. Specifies the engine that is used to run the script. This lets you run scripts that use a custom file name extension.
For example, if you try to run this command: cscript test. One advantage of using nonstandard file name extensions is that it guards against accidentally double-clicking a script and running something you really did not want to run. This does not create a permanent association between the. Each time you run a script that uses a. This utility works within the Windows 9x graphic environment.
In Windows NT and , however, the utility you use is called Ipconfig. Winipcfg vs. Figure D Because Internet Explorer sees that the script that it is running is about to write a file to the hard drive, it displays this security warning.
0コメント