找回密码
 加入
搜索
查看: 588421|回复: 88

[转贴] AU3-实用脚本大全

 火... [复制链接]
发表于 2010-11-25 16:23:14 | 显示全部楼层 |阅读模式
AU3-实用脚本大全
得到适配器信息

$strComputer = "."
$objWMIService = ObjGet( _
"winmgmts:\" & $strComputer & "\root\cimv2")
$IPConfigSet= $objWMIService.ExecQuery ("Select IPAddress from Win32_NetworkAdapterConfiguration" _
& " where IPEnabled=TRUE")

For $IPConfig in $IPConfigSet
If Not $IPConfig.IPAddress Then
For $i=0 To UBound($IPConfig.IPAddress)
ConsoleWrite( $IPConfig.IPAddress( $i) & @CRLF )
Next
EndIf
Next

禁用网络连接

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colNetCards = $objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True";)
For $objNetCard in $colNetCards
$objNetCard.ReleaseDHCPLease()
Next

进行磁盘整理

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" _
& $strComputer & "\root\cimv2")
$colVolumes = $objWMIService.ExecQuery ("Select * from Win32_Volume Where Name = 'K:\'")
For $objVolume in $colVolumes
$errResult = $objVolume.Defrag()
Next

检查磁盘的可用空间

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colDisks = $objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For $objDisk in $colDisks
ConsoleWrite( "DeviceID: " & $objDisk.DeviceID & @CRLF )
ConsoleWrite( "Free Disk Space: " _
& $objDisk.FreeSpace & @CRLF )
Next

检查PCMCIA接口数量

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_PCMCIAController")

ConsoleWrite( "Number of PCMCIA slots: " _
& $colItems.Count)

检查系统信息处理器数目

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colSettings = $objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For $objComputer in $colSettings
ConsoleWrite( "System Name: " & $objComputer.Name & @CRLF )
ConsoleWrite( "Number of Processors: " & _
$objComputer.NumberOfProcessors )
Next

查看可用的物理内存

$strComputer = "."

$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")

$colSettings = $objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For $objOperatingSystem in $colSettings
ConsoleWrite( "可用物理内存: " & _
$objOperatingSystem.FreePhysicalMemory )
Next

获取U盘盘符

$var = DriveGetDrive( "REMOVABLE" )
Dim $DriveNumber[2]
$i = 1
If NOT @error Then
     For $i = 1 to $var[0]
         $state = DriveStatus($var[$i])
         If $state = "READY"     Then     
             $DriveNumber[$i] = Asc($var[$i]) - 96
             $i += 1
             ReDim $DriveNumber[$i]
         EndIf
     Next
     $DriveNumber[0] = $i
     $var = 0
EndIf

For $i = 1 To $i
     MsgBox(0,"阁下的U盘:",$DriveNumber[$i])
Next

调用windows自带的格式化工具

;
;
Local $DriveNumber=3   ;A盘为0,B盘为1,C盘为2,D盘为3,依次类推……
Local $FormatOptions=1 ;1为快速格式化,0为完全格式化
DllCall("shell32.dll","int","SHFormatDrive","hwnd",0,"int",$DriveNumber,"int",0,"int",$FormatOptions)
;
;

枚举文件

_filelist("F:\movie")

Func _filelist($searchdir)                           ;;;函数名(形参)
$search = FileFindFirstFile($searchdir & "\*.*")       ;;;;查找c:根目下的文件
If $search = -1 Then return -1                   ;;;;如果找不到,返回值 -1
While 1
     $file = FileFindNextFile($search)         ;;;查找下一个文件
     If @error Then                                         ;;;如果找不到文件

         FileClose($search)                             ;;;则关闭此句柄
         return                                                   ;;;返回
     Elseif   $file = "."   or $file = ".." Then     ;;如果找到的文件名为.或..则 ContinueLoop
         ContinueLoop                                     ;;;在某些版本的AU3里面可以不需要上行和这行。
     ElseIf stringinstr(FileGetAttrib($searchdir & "\" & $file),"D") then         ;;如果找到的是一个文件夹,则
         _filelist($searchdir & "\" & $file)     ;;递归调用filelist函数,并传参数   "$searchdir & "\" & $file"

     EndIf                                                           ;;;$file为查找到的文件夹名称,上一行意思就是进入此文件夹继续查找文件.如此循环
     ConsoleWrite( $searchdir & "\" & $file & @crlf )
WEnd
EndFunc

返回字符串的字节数

$var = "AutoIt 中文论坛"

MsgBox(64, "文本长度", "是:" & ChrLenFixed($var))

Func ChrLenFixed($c)
     Dim $ChrL = 0, $AscNum
     For $i = 1 To StringLen($c)
         $AscNum = AscW(StringMid($c, $i, 1))
         If $AscNum < 0 Then $AscNum = $AscNum + 65536
         If $AscNum > 255 Then
             $ChrL = $ChrL + 2
         Else
             $ChrL = $ChrL + 1
         EndIf
     Next
     Return $ChrL
EndFunc

列出A-Z

For $i=65 To 90
     MsgBox(0,"",chr($i))
Next


检查驱动器的文件系统类型

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colDisks = $objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For $objDisk in $colDisks
ConsoleWrite( "DeviceID: " & $objDisk.DeviceID & @CRLF )
ConsoleWrite( "File System: " _
& $objDisk.FileSystem & @CRLF )
Next

检查软驱里是否有软盘

$strComputer = "."
$objWMIService = ObjGet( _
"winmgmts:\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DeviceID = 'A:'")

For $objItem in $colItems
$intFreeSpace = $objItem.FreeSpace
If $intFreeSpace = "" Then
ConsoleWrite( "There is no disk in the floppy drive." & @CRLF )
Else
ConsoleWrite( "There is a disk in the floppy drive." & @CRLF )
EndIf
Next

判断磁盘是否为可移动驱动器

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colDisks = $objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For $objDisk in $colDisks
ConsoleWrite( "DeviceID: "& @Tab _
& $objDisk.DeviceID & @CRLF )
Switch $objDisk.DriveType
Case 1
ConsoleWrite( "No root directory. " _
& "Drive type could not be " _
& "determined." & @CRLF )
Case 2
ConsoleWrite( "DriveType: "& @Tab _
& "Removable drive." & @CRLF )
Case 3
ConsoleWrite( "DriveType: "& @Tab _
& "Local hard disk." & @CRLF )
Case 4
ConsoleWrite( "DriveType: "& @Tab _
& "Network disk." & @CRLF )
Case 5
ConsoleWrite( "DriveType: "& @Tab _
& "Compact disk." & @CRLF )
Case 6
ConsoleWrite( "DriveType: "& @Tab _
& "RAM disk." & @CRLF )
Case Else
ConsoleWrite( "Drive type could not be" _
& " determined." & @CRLF )
EndSwitch
Next

列出每个用户所占用的磁盘空间

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colQuotas = $objWMIService.ExecQuery _
("Select * from Win32_DiskQuota")
For $objQuota in $colQuotas
ConsoleWrite( "Volume: "& @Tab _
& $objQuota.QuotaVolume & @CRLF )
ConsoleWrite( "User: "& @Tab & $objQuota.User & @CRLF )
ConsoleWrite( "Disk Space Used: " _
& @Tab & $objQuota.DiskSpaceUsed & @CRLF )
Next

列出每个进程所占用的内存

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colProcesses = $objWMIService.ExecQuery _
("Select * from Win32_Process")
For $objProcess in $colProcesses
ConsoleWrite( "Process: " & $objProcess.Name & @CRLF )
$sngProcessTime = (String($objProcess.KernelModeTime) + _
String($objProcess.UserModeTime)) / 10000000
ConsoleWrite( "Processor Time: " & $sngProcessTime & @CRLF )
ConsoleWrite( "Process ID: " & $objProcess.ProcessID & @CRLF )
ConsoleWrite( "Working $Size: " _
& $objProcess.WorkingSetSize & @CRLF )
ConsoleWrite( "Page File Size: " _
& $objProcess.PageFileUsage & @CRLF)
ConsoleWrite( "Page Faults: " & $objProcess.PageFaults & @CRLF & @CRLF )
Next

修改进程的优先权

Const $ABOVE_NORMAL = 32768
$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colProcesses = $objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")
For $objProcess in $colProcesses
$objProcess.SetPriority($ABOVE_NORMAL)
Next

检查系统同时运行了多少个au3脚本

$strComputer = "."
$objWMIService = ObjGet( _
"winmgmts:\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process" & _
" WHERE Name = 'AutoIt3.exe'")
For $objItem in $colItems
ConsoleWrite( "-------------------------------------------" & @CRLF )
ConsoleWrite( "CommandLine: " & $objItem.CommandLine & @CRLF )
ConsoleWrite( "Name: " & $objItem.Name & @CRLF & @CRLF )
Next

检查开机自启动项

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colStartupCommands = $objWMIService.ExecQuery _
("Select * from Win32_StartupCommand")
For $objStartupCommand in $colStartupCommands
ConsoleWrite( "Command: " & $objStartupCommand.Command & @CRLF _
& "Description: " & $objStartupCommand.Description & @CRLF _
& "Location: " & $objStartupCommand.Location & @CRLF _
& "Name: " & $objStartupCommand.Name & @CRLF _
& "SettingID: " & $objStartupCommand.SettingID & @CRLF _
& "User: " & $objStartupCommand.User & @CRLF & @CRLF )
Next

重启或关闭远程计算机

$strComputer = "atl-dc-01"
$objWMIService = ObjGet("winmgmts:" _
& "!\" & _
$strComputer & "\root\cimv2")
$colOperatingSystems = $objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For $objOperatingSystem in $colOperatingSystems
$ObjOperatingSystem.Shutdown(1)
Next

获取系统开机的时间

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colOperatingSystems = $objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For $objOS in $colOperatingSystems
ConsoleWrite( $objOS.LastBootUpTime)
Next

获取屏幕分辨率

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery( "Select * from Win32_DesktopMonitor")
For $objItem in $colItems
ConsoleWrite( "Screen Height: " _
& $objItem.ScreenHeight & @CRLF )
ConsoleWrite( "Screen Width: " _
& $objItem.ScreenWidth & @CRLF )
Next

检查屏幕保护是否需要密码

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Desktop")
For $objItem in $colItems
ConsoleWrite( "Screen Saver Secure: " _
& $objItem.ScreenSaverSecure & @CRLF )
Next


判断系统是否启动在安全模式的网络状态下

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colSettings = $objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For $objComputer in $colSettings
ConsoleWrite( "System Name: " _
& $objComputer.Name & @CRLF )
ConsoleWrite( "Registered owner: " _
& $objComputer.PrimaryOwnerName & @CRLF )
Next

列出全部的已安装的软件

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colSoftware = $objWMIService.ExecQuery _
("Select * from Win32_Product")

For $objSoftware in $colSoftware
ConsoleWrite( "Name: " & $objSoftware.Name & @CRLF )
ConsoleWrite( "Version: " & $objSoftware.Version & @CRLF & @CRLF )
Next

卸载软件

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" _
& "!\" _
& $strComputer & "\root\cimv2")
$colSoftware = $objWMIService.ExecQuery _
("Select * from Win32_Product " _
& "Where Name = 'Personnel database'")
For $objSoftware in $colSoftware
$objSoftware.Uninstall()
Next

列出所有鼠标的信息

.$strComputer = "."
$objWMIService = ObjGet( _
"winmgmts:\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery( _
"Select * from Win32_PointingDevice")
For $objItem in $colItems
ConsoleWrite( "Description: " & $objItem.Description & @CRLF )
ConsoleWrite( "Device ID: " & $objItem.DeviceID & @CRLF )
ConsoleWrite( "Device Interface: " _
& $objItem.DeviceInterface & @CRLF )
ConsoleWrite( "Double Speed Threshold: " _
& $objItem.DoubleSpeedThreshold & @CRLF )
ConsoleWrite( "Handedness: " & $objItem.Handedness & @CRLF )
ConsoleWrite( "Hardware Type: " & $objItem.HardwareType & @CRLF )
ConsoleWrite( "INF File Name: " & $objItem.InfFileName & @CRLF )
ConsoleWrite( "INF Section: " & $objItem.InfSection & @CRLF )
ConsoleWrite( "Manufacturer: " & $objItem.Manufacturer & @CRLF )
ConsoleWrite( "Name: " & $objItem.Name & @CRLF )
ConsoleWrite( "Number Of Buttons: " _
& $objItem.NumberOfButtons & @CRLF )
ConsoleWrite( "PNP Device ID: " & $objItem.PNPDeviceID & @CRLF )
ConsoleWrite( "Pointing Type: " & $objItem.PointingType & @CRLF )
ConsoleWrite( "Quad Speed Threshold: " _
& $objItem.QuadSpeedThreshold & @CRLF )
ConsoleWrite( "Resolution: " & $objItem.Resolution & @CRLF )
ConsoleWrite( "Sample Rate: " & $objItem.SampleRate & @CRLF )
ConsoleWrite( "Synch: " & $objItem.Synch & @CRLF & @CRLF )
Next

列出没有工作的硬件

$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery _
("Select * from Win32_PnPEntity " _
& "WHERE ConfigManagerErrorCode <> 0")

For $objItem in $colItems
ConsoleWrite( "Class GUID: " & $objItem.ClassGuid & @CRLF )
ConsoleWrite( "Description: " & $objItem.Description & @CRLF )
ConsoleWrite( "Device ID: " & $objItem.DeviceID & @CRLF )
ConsoleWrite( "Manufacturer: " & $objItem.Manufacturer & @CRLF )
ConsoleWrite( "Name: " & $objItem.Name & @CRLF )
ConsoleWrite( "PNP Device ID: " & $objItem.PNPDeviceID & @CRLF )
ConsoleWrite( "Service: " & $objItem.Service & @CRLF & @CRLF )
Next

评分

参与人数 2金钱 +30 贡献 +1 收起 理由
msold5 + 20 赞一个!
fuldho + 10 + 1 不错!值得收藏备用!

查看全部评分

发表于 2010-11-25 16:50:50 | 显示全部楼层
不错不错。挺实用经典!
发表于 2010-11-25 18:17:44 | 显示全部楼层
强人呀,占个位
发表于 2010-11-25 18:50:53 | 显示全部楼层
回复 1# pyj521

看看先  谢谢
发表于 2010-12-3 13:07:52 | 显示全部楼层
看看先  谢谢
发表于 2010-12-12 21:58:55 | 显示全部楼层
真的是个牛人哦  收藏了 谢谢 分享
发表于 2011-2-12 21:04:29 | 显示全部楼层
呵呵,利用wmi,这个跟VBS的差不多。
发表于 2011-2-13 13:52:03 | 显示全部楼层
变量类型怎么抱错?
发表于 2011-2-24 00:46:42 | 显示全部楼层
先学习学习。
发表于 2011-3-2 16:43:25 | 显示全部楼层
頂 ~ 牛阿
學習 學習
发表于 2011-3-3 01:28:24 | 显示全部楼层
不错不错。挺实用
发表于 2011-3-4 15:19:41 | 显示全部楼层
谢谢楼主 挺实用
发表于 2011-3-15 16:01:45 | 显示全部楼层
好东西。谢谢楼主
发表于 2011-3-16 21:13:44 | 显示全部楼层
不错不错。挺实用!
感谢分享!!!!!!!!!!
发表于 2011-3-17 07:45:35 | 显示全部楼层
这么多好东西啊,谢谢分享啊!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-21 16:47 , Processed in 0.077179 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表