Home Web Front-end JS Tutorial Some tips of wmi scripting in jscript (1)_javascript技巧

Some tips of wmi scripting in jscript (1)_javascript技巧

May 16, 2016 pm 07:15 PM
in jscript of wmi

The concept of collection is very commonly used in Windows scripts, especially in WMI scripts, collection operations are basically encountered.
The method of traversing a collection in vbscript is very simple, the For Each loop can achieve the purpose. However, how to use collections in jscript has troubled me for a long time. I can't even find a good example in msdn, which made me pessimistically think that
jscript cannot perform collection operations.

When I was almost giving up, I dug out another vbscript wmi e-book and looked at it, and found jscript
The method of using collections is the Enumerator object, which is specially used for Enumeration collection. What do you
think about when you see this object? Does it look familiar? If you have used jscript to call FSO, how to enumerate Drives Files
and Folders? The FSO examples are clearly written. When you used them, did you move the examples into your program like a zombie? At that time, I also felt strange why it was so troublesome to write to traverse a collection, but I didn't delve into why
was written like this. At that time, because your method for arrays didn't work, traversing a collection in jscript could only do this.

At this time you may still have questions, what is the difference between sets and arrays? To quote the original words in MS Script Help: The difference between a set and a
group is that the members of the set cannot be accessed directly. Unlike using subscripts when working with arrays, this only moves the current item
pointer to the next or previous element in the collection. If you think a little deeper here, you can understand it this way. An array is equivalent to the array concept in the C
language. It is a linear storage space that can be easily accessed through subscripts, while a set is a complex
When accessing a data structure, such as a linked list, you can only access the previous or next element through the pointing relationship between nodes.

The usage of Enumerator is very simple. After passing the collection you want to traverse as a parameter to the constructor of the Enumerator object,
you can enumerate the members of the collection. The atEnd method determines whether the end has been reached. The moveFirst method can Move the pointer
to the first element, the moveNext method moves the current pointer position to the next element, and returns a single element in the set
through the item method.

Example 1: Enumerate all drives


/**//*
* cscript ListDrive.js
*/
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var enDrives = new Enumerator(oFSO.Drives);
var oDrive;
while (! enDrives.atEnd()) {
oDrive = enDrives.item();

if (oDrive .IsReady) {
               WScript.Echo(oDrive.DriveLetter    ":");                                                                                                                                                                                                                     . The process of


/**//*
* cscript ListProcess.js
*/
var sComputerName = ".";
var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");
var oSvc = oLoc.ConnectServer(sComputerName, "root\cimv2");
var colItems = oSvc.ExecQuery("SELECT * FROM Win32_Process");
var enProcesses = new Enumerator(colItems);

while (! enProcesses.atEnd()) {
WScript.Echo(enProcesses.item().Name);
enProcesses.moveNext();
}

A few days ago it was still Long discussed the advantages and disadvantages between vbscript and jscript. vbscript is much worse than jscript in terms of language functions and code style, but jscript also has some shortcomings in functional implementation, such as the inability to perform byte operations. , but in general jscript is a smart language, which can be seen from Enumerator, hehe.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

4 Quick Tips to Fix WMI Provider Host High CPU on Windows 11 4 Quick Tips to Fix WMI Provider Host High CPU on Windows 11 Apr 18, 2023 pm 08:25 PM

The WMIProviderHost process plays a vital role in Windows 11. It enables other applications to request information about your computer. Processes related to WMIProviderHost typically run in the background; therefore, they typically do not consume large amounts of system resources. However, the service reportedly uses more than 50% of CPU power at times due to other applications. It is worrisome to run your computer's processor at nearly maximum capacity for an extended period of time, as this can lead to overheating and damage to system components. In today's tutorial, we will look at why WMIProviderHost works in C on Windows 11

What do out and in interfaces mean? What do out and in interfaces mean? Sep 28, 2021 pm 04:39 PM

The out interface refers to the output interface, and the in interface refers to the input interface. The out interface generally represents the audio source line output interface, which is used to connect loads, such as speakers, headphones, etc.; while the in interface generally represents the audio source line input interface, which is used to connect CD players, mobile phones, MP3 players, computers, etc.

Tips for using i18n to implement multi-language switching in Vue Tips for using i18n to implement multi-language switching in Vue Jun 25, 2023 am 09:33 AM

With the continuous development of internationalization, more and more websites and applications need to support multi-language switching functions. As a popular front-end framework, Vue provides a plug-in called i18n that can help us achieve multi-language switching. This article will introduce common techniques for using i18n to implement multi-language switching in Vue. Step 1: Install the i18n plug-in First, we need to install the i18n plug-in using npm or yarn. Enter the following command at the command line: npminst

What to do if wmi occupies very high cpu_Win10_WmiProviderHost occupies cpu solution What to do if wmi occupies very high cpu_Win10_WmiProviderHost occupies cpu solution Mar 20, 2024 pm 02:10 PM

The running speed of the win10 system becomes laggy. When I open the task manager, I find that WMIProviderHost takes up too much CPU resources. No wonder the system is so laggy. Let’s take a look at the detailed solution. 1. Press the Win+R key combination on the keyboard to open Run , enter the services.msc command and press OK or Enter to open the service; 2. In the service window, find and double-click the service item named WindowsManagementInstrumentation; 3. In the properties (local computer) window of WindowsManagementInstrumentation, switch to the Dependencies tab, you can See IPHelper component dependencies

What should I do if my win10 system crashes and displays out of memory? What should I do if my win10 system crashes and displays out of memory? Feb 09, 2024 pm 03:00 PM

Win10 system crashes and displays outofmemory. Recently, many users have encountered this prompt when using their computers, which requires frequent restarts to repair. So how should we deal with this situation? To address this problem, this issue’s win10 tutorial is here Share the complete operation steps with the majority of users, hoping to help more friends solve their problems. What to do if win10 system crashes and displays outofmemory 1. Right-click this computer on the desktop and select "Properties" in the option list. 2. After entering the new window interface, click the "Advanced System Settings" option in the upper left corner. 3. In the window that opens, switch to the "

What is the difference between on, in, as, and where in Mysql? What is the difference between on, in, as, and where in Mysql? Jun 03, 2023 am 11:37 AM

The difference between Mysqlon, in, as, and where Answer: Where query conditions, use on for internal and external connections, as as an alias, in to query whether a certain value creates 2 tables in a certain condition: student, scorestudent: score: whereSELECT*FROMstudentWHEREs_sex=' Male'For example: onSELECT*FROMstudentLEFTJOINscoreonstudent.s_id=score.s_id; combination of on and where: SELECT*FROMstudentLEFTJOINs

Can wmi provider host end the process? Can wmi provider host end the process? Feb 21, 2024 am 09:10 AM

When cleaning the background, many friends must have seen the wmiproviderhost process in the task manager. What everyone is most curious about is whether it can end this process. In fact, it can end the process, but it is highly not recommended~wmiproviderhost can end the process. ?: Answer: wmiproviderhost can end the process. However, it is strongly not recommended that users forcefully close it, because this is a system process, and if it is closed directly, it may affect subsequent use. How to end the wmiproviderhost process: 1. First, right-click your taskbar, and then enter "Task Manager". 2. Then find the wmiproviderhost process. 3.

Five ways to fix Thread Stuck in Device Driver blue screen Five ways to fix Thread Stuck in Device Driver blue screen Mar 25, 2024 pm 09:40 PM

Some users reported that after installing Microsoft's March Win11 update patch KB5035853, a blue screen of death error occurred, with "ThreadStuckinDeviceDriver" displayed on the system page. It is understood that this error may be caused by hardware or driver issues. Here are five fixes that will hopefully resolve your computer blue screen problem quickly. Method 1: Run system file check. Run the [sfc/scannow] command in the command prompt, which can be used to detect and repair system file integrity issues. The purpose of this command is to scan and repair any missing or damaged system files, helping to ensure system stability and normal operation. Method 2: 1. Download and open the "Blue Screen Repair Tool"

See all articles