执行VB脚本文件
将下列命令保存为test.vbs
Set wmi = GetObject("winmgmts:") Set collection = wmi.ExecQuery("select * from Win32_Process") For Each process in collection WScript.Echo process.getObjectText_ Next
执行 .\test.vbs 会遍历当前Win32进程,并把每个进程的详细信息通过窗口显示出来。
怎样让VB脚本的通过控制台输出呢?
Wscript //H:CScript
怎样还原VB脚本通过窗口输出呢?
WScript //H:WScript
在powershell中执行VB脚本
PS C:\PS> cscript.exe .test.vbs Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. instance of Win32_Process { Caption = "System Idle Process"; CreationClassName = "Win32_Process"; CSCreationClassName = "Win32_ComputerSystem"; CSName = "test-me-01"; Description = "System Idle Process"; Handle = "0"; HandleCount = 0; KernelModeTime = "484113379271"; Name = "System Idle Process"; OSCreationClassName = "Win32_OperatingSystem"; OSName = "Microsoft Windows 7 Enterprise |C:Windows|DeviceHarddisk0Partition2"; OtherOperationCount = "0"; OtherTransferCount = "0"; PageFaults = 0; PageFileUsage = 0; ParentProcessId = 0; PeakPageFileUsage = 0; PeakVirtualSize = "0"; PeakWorkingSetSize = 0; Priority = 0; PrivatePageCount = "0"; ProcessId = 0; QuotaNonPagedPoolUsage = 0; QuotaPagedPoolUsage = 0; QuotaPeakNonPagedPoolUsage = 0; QuotaPeakPagedPoolUsage = 0; ReadOperationCount = "0"; ReadTransferCount = "0"; SessionId = 0; ThreadCount = 2; UserModeTime = "0"; VirtualSize = "0"; WindowsVersion = "6.1.7601"; WorkingSetSize = "24576"; WriteOperationCount = "0"; WriteTransferCount = "0"; };
执行powershell脚本
Powershell拥有自己的脚本,扩展名为“.ps1”
PS C:\PS> echo "dir;Get-PSProvider;help dir" >test.ps1 PS C:\PS> Get-Content ./test.ps1 dir;Get-PSProvider;help dir PS C:\PS> ./test.ps1
初次执行脚本时,可能会碰到一个异常:
File ” C:\PS\test.ps1″ cannot be loaded because the
execution of scripts is disabled on this system. Please see
“get-help about_signing” for more details.
At line:1 char:10
+ .test.ps1