Tag:WMI

  • Code for VBS to obtain CPU utilization through WMI

    Time:2022-6-30

    Python is powerful, but callingWMIStill useVBSCompare “authentic”. Copy codeThe codes are as follows: On Error Resume Next strComputer = “.” Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”) Set colItems = objWMIService.ExecQuery(“Select * from Win32_Processor”,,48) For Each objItem in colItems WScript.Echo “LoadPercentage: ” & objItem.LoadPercentage Next   Reference link:Win32_Processor Class Original: http://demon.tw/programming/vbs-wmi-cpu-usage.html

  • WMI creates the implementation code of system service (automatic)

    Time:2022-4-5

    Copy codeThe code is as follows: Const OWN_PROCESS = &H10 Const ERR_CONTROL = &H2 Const INTERACTIVE = False   ServiceName = “TestService” DisplayName = “This is a test service.” InstallPath = “c:\windows\system32\Test.exe” Set ObjWMI = GetObject(“winmgmts:” & “{impersonationLevel=impersonate, (Security)}!\\.\root\cimv2”) Set ObjSvr = ObjWMI.Get(“Win32_Service”) Return = ObjSvr.Create(ServiceName, DisplayName, InstallPath, OWN_PROCESS, ERR_CONTROL, “Automatic”, INTERACTIVE, “LocalSystem”, “”) If […]

  • VBS modify NTFS permissions of files and folders through WMI

    Time:2022-3-29

    Modify NTFS permissions of files and folders using WMI, code: Copy codeThe code is as follows: strUser = “guests” strPath = “D:\\abc.txt” RetVal = AddPermission(strUser,strPath,”R”,True)   ‘————————————————————————- ‘used to add a permission setting to files and folders Return value: 0 – success, 1 – account does not exist, 2 – path does not exist‘struser indicates […]

  • C# more efficient WMI access through wbemtest and WMI code cretor

    Time:2022-1-19

    catalogue Step 1: Step 2: Step 3: Step 1: Find the WMI information you need on the official website (or communicate with the hardware developer about the interface and Parameter definitions you need. If you are negotiating the WMI interface with the hardware developer, see Step 2 directly); For example, I need to get display […]

  • VBS calls WMI to search hard disk files and count

    Time:2021-12-12

    A VBS written many years ago called WMI to traverse the function of searching hard disk files and counting. Today, I sorted the network disk, saw it and sent it Core code: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 […]

  • SQL Server 2012 cannot connect to the WMI provider solution

    Time:2021-10-27

    Today, a colleague encountered the following error when starting the SQL Server 2012 configuration manager of his working machine: Unable to connect to WMI provider. You do not have permission or the server cannot be accessed. Note that you can only use SQL Server Configuration Manager to manage SQL Server 2005 servers. The specified module […]

  • Explain the solution of the unavailable WMI RPC server

    Time:2021-5-6

    This paper introduces the solution of the unavailable WMI RPC server, and shares it with you. The details are as follows: ConnectionOptions connectionOptions = new ConnectionOptions(); connectionOptions.Username = userName; connectionOptions.Password = password; ManagementScope managementScope = new ManagementScope(“\\\\” + host + “\\root\\cimv2”, connectionOptions); try { managementScope.Connect(); } catch { } Solution in case of “RPC server […]

  • On WMI_ VBS scripting tutorial Supplement 1 / 2

    Time:2020-9-12

    Today, I would like to introduce a friend to you. It is Microsoft Windows Management Instrumentation (WMI). The Chinese name is windows management specification. Since Windows 2000, WMI (Windows Management specification) has been built into the operating system, and has become an important part of windows system management. So it’s easy to see it, because […]

  • An example of acquiring computer hardware information by VBS WMI

    Time:2020-7-21

    Set wmi=GetObject(“winmgmts:\\”) Set board=wmi.instancesof(“win32_baseboard”) For Each b In board msg=”main board:”&b.Manufacturer&vbTab&b.product&vbTab&Chr(13) Next msg=msg&Chr(13)&”—“+Chr(13) Set cpus=wmi.instancesof(“win32_processor”) MSG = MSG & “CPU characteristics:” Chr (13)For Each cpu In cpus msg=msg+cpu.deviceid&vbTab&cpu.name&Chr(13) _ &vbtab&cpu.SocketDesignation&vbtab&cpu.CurrentClockSpeed&”MHz”&vbtab&cpu.l2cachesize&”Kb_L2″&Chr(13) Next msg=msg&Chr(13)&”—“+Chr(13) Set mem=wmi.instancesof(“win32_physicalmemory”) MSG = MSG & “memory capacity:” Chr (13)For Each    m In mem msg=msg&m.tag&space(10)&m.capacity&+Chr(13) Next Set mem=wmi.instancesof(“win32_computersystem”) For Each m In mem MSG = MSG & “total memory:” round ((m.totalphysicalmemory / 1024 ^ 2), 2) & “m” + Chr (13)Next msg=msg&Chr(13)&”—“+Chr(13) Set display=wmi.instancesof(“Win32_videocontroller”) MSG = […]

  • Vbs script code to operate registry using WMI page 1 / 2

    Time:2020-7-7

    oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath    oReg.SetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue    oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue    oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue    oReg.SetBinaryValue HKEY_LOCAL_MACHINE,strPath,strValueName,uBinary    oReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrStringValues    oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath    oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName    oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue    oReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue    oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,uBinary    oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrStringValues    ‘——————————————————————————————-    Const HKEY_CLASSES_ROOT = &H80000000    Const HKEY_CURRENT_USER = &H80000001    Const HKEY_LOCAL_MACHINE = &H80000002    Const HKEY_USERS = &H80000003    Const HKEY_CURRENT_CONFIG = &H80000005    ‘create a registry keyconst HKEY_LOCAL_MACHINE = &H80000002    strComputer = “.”   Set StdOut = WScript.StdOut    Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_     strComputer & “\root\default:StdRegProv”)    strKeyPath = “SOFTWARE\System Admin Scripting Guide”   oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath    ‘create a multi string valueconst HKEY_LOCAL_MACHINE = &H80000002    strComputer = “.”   Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_     strComputer & “\root\default:StdRegProv”)    strKeyPath = “SOFTWARE\System Admin Scripting Guide”   strValueName = “Multi String Value Name”   arrStringValues = Array(“first string”, “second string”,_     “third string”, “fourth string”)    oReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,_    strValueName,arrStringValues       ‘create an extended string valueconst HKEY_LOCAL_MACHINE = &H80000002    strComputer = “.”   Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_     strComputer & “\root\default:StdRegProv”)    strKeyPath = “SOFTWARE\System Admin Scripting Guide”   strValueName = “Expanded String Value Name”   strValue = “%PATHEXT%”   […]

  • VBS calls WMI to quickly close ie script

    Time:2020-6-29

    VBS calls WMI to kill IESave the following file as KillIE.vbs When you want to close all web pages opened with ie, double-click to execute, Set wmi=GetObject(“winmgmts:\\.”) Set pro_s=wmi.instancesof(“win32_process”) For Each p In pro_s  if p.name=”iexplore.exe” then p.terminate() Next This is to extract because: I usually open a lot of web pages, close also to close half a day, with this is really good. […]

  • Use WMI change ie proxy

    Time:2020-5-8

    Save the following code as vbs Copy codeThe code is as follows: If WScript.Arguments.Count = 0 Then GetI = -1 Else GetI = CInt(WScript.Arguments(0)) End If Call YourCode() ‘write all the agents you get in a text file (IP. Txt), one line at a time: IP: PortIPS = CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“IP.txt”, 1, True).ReadAll IPS = Split(IPS, vbCrLf) […]