vbs脚本大全配有实例 DOS命令批处理 脚本 代码.docx
《vbs脚本大全配有实例 DOS命令批处理 脚本 代码.docx》由会员分享,可在线阅读,更多相关《vbs脚本大全配有实例 DOS命令批处理 脚本 代码.docx(9页珍藏版)》请在冰豆网上搜索。
vbs脚本大全配有实例DOS命令批处理脚本代码
vbs脚本大全,配有实例DOS命令,批处理脚本代码
VBS
取得本机IP
strComputer='.'
SetobjWMIService=GetObject('winmgmts:
\\'&strComputer&'\root\cimv2')
SetIPConfigSet=objWMIService.ExecQuery('SelectIPAddressfrom
Win32_NetworkAdapterConfigurationWhereIPEnabled=TRUE')
ForEachIPConfiginIPConfigSet
IfNotIsNull(IPConfig.IPAddress)Then
ForEachstrAddressinIPConfig.IPAddress
WScript.EchostrAddress
Next
EndIf
Next
2取得本机计算机名
strComputer='.'
SetobjWMIService=GetObject('winmgmts:
\\'&strComputer&'\root\cimv2')
SetcolComputers=objWMIService.ExecQuery('Select*fromWin32_ComputerSystem')
ForEachobjComputerincolComputers
Wscript.EchoobjComputer.Name
Next
4检查升级包
strComputer='.'
SetobjWMIService=GetObject('winmgmts:
\\'&strComputer&'\root\cimv2')
SetcolOperatingSystems=objWMIService.ExecQuery('Select*fromWin32_OperatingSystem')
ForEachobjOperatingSystemincolOperatingSystems
Wscript.EchoobjOperatingSystem.ServicePackMajorVersion&'.'&
objOperatingSystem.ServicePackMinorVersion
Next
5检查HotFix
strComputer='.'
SetobjWMIService=GetObject('winmgmts:
\\'&strComputer&'\root\cimv2')
SetcolQuickFixes=objWMIService.ExecQuery('Select*fromWin32_QuickFixEngineering')
ForEachobjQuickFixincolQuickFixes
Wscript.Echo'Description:
'&objQuickFix.Description
Wscript.Echo'HotFixID:
'&objQuickFix.HotFixID
Next
6检查本地管理员数目
SetobjNetwork=CreateObject('Wscript.Network')
strComputer=objNetwork.ComputerName
SetobjGroup=GetObject('WinNT:
//'&strComputer&'/Administrators,group')
ForEachobjUserinobjGroup.Members
Wscript.EchoobjUser.Name
Next
7磁盘系统
strComputer='.'
SetobjWMIService=GetObject('winmgmts:
\\'&strComputer&'\root\cimv2')
SetcolDisks=objWMIService.ExecQuery('Select*fromWin32_LogicalDiskWhereDriveType=
3')
ForEachobjDiskincolDisks
Wscript.Echo'Diskdrive:
'&objDisk.DeviceID&'--'&objDisk.FileSystem
Next
8检测自动登录是否开启
ConstHKEY_LOCAL_MACHINE=&H80000002
strComputer='.'
SetobjReg=GetObject('winmgmts:
\\'&strComputer&'\root\default:
StdRegProv')
strKeyPath='Software\Microsoft\WindowsNT\CurrentVersion\WinLogon'
strValueName='AutoAdminLogon'
objReg.GetDWORDValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
IfdwValue=1Then
Wscript.Echo'Autologonisenabled.'
Else
Wscript.Echo'Autologonisdisabled.'
EndIf
9关闭自动登录
ConstHKEY_LOCAL_MACHINE=&H80000002
strComputer='.'
SetobjReg=GetObject('winmgmts:
\\'&strComputer&'\root\default:
StdRegProv')
strKeyPath='Software\Microsoft\WindowsNT\CurrentVersion\WinLogon'
strValueName='AutoAdminLogon'
dwValue=0
oReg.SetDWORDValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
10检查Guest是否禁用
SetobjNetwork=CreateObject('Wscript.Network')
strComputer=objNetwork.ComputerName
SetobjUser=GetObject('WinNT:
//'&strComputer&'/Guest')
IfobjUser.AccountDisabledThen
Wscript.Echo'TheGuestaccountisdisabled.'
Else
Wscript.Echo'TheGuestaccountisenabled.'
EndIf
11关闭Guest
SetobjNetwork=CreateObject('Wscript.Network')
strComputer=objNetwork.ComputerName
SetobjUser=GetObject('WinNT:
//'&strComputer&'/Guest')
IfobjUser.AccountDisabledThen
Wscript.Echo'TheGuestaccountisalreadydisabled.'
Else
objUser.AccountDisabled=True
objUser.SetInfo
Wscript.Echo'TheGuestaccounthasbeendisabled.'
EndIf
12检索本地共象
strComputer='.'
SetobjWMIService=GetObject('winmgmts:
\\'&strComputer&'\root\cimv2')
SetcolShares=objWMIService.ExecQuery('Select*fromWin32_Share')
ForeachobjShareincolShares
Wscript.Echo'Name:
'&objShare.Name
Wscript.Echo'Path:
'&objShare.Path
Wscript.Echo'Type:
'&objShare.Type
Next
13脚本检索一个文件夹下.txt文件汗哦值得学习
SetobjWMIService=GetObject('winmgmts:
\\.\root\cimv2')
SetcolFiles=objWMIService.ExecQuery('SELECT*FROMCIM_DataFileWHEREPath='\\Documents
andSettings\\Administrator\\桌面\\'ANDDrive='E:
'ANDExtension='txt'')
Wscript.Echo'Numberof.txtfilesfound:
'&colFiles.Count
foreachaaincolFiles
NL=NL&vbcrlf&aa.name
next
Wscript.EchoNL
14我如何向用户显示一个用来选择文件的对话框?
问:
嗨,ScriptingGuy!
有没有什么方法可以让我使用脚本向用户显示一个对话框,供用户选择文件使用?
--BF
答:
您好,BF。
如果您使用的是Windows2000,我们不知道实现此操作的方法,至少操作系统中没有内置这
样的方法。
但如果您使用的是WindowsXP,情况就不同了。
在WindowsXP上,您可以使用
“UserAccounts.CommonDialog”对象向用户显示一个标准的“文件打开”对话框。
可以用类似以下代码
的脚本:
SetobjDialog=CreateObject('UserAccounts.CommonDialog')
objDialog.Filter='AllFiles|*.*'objDialog.InitialDir='C:
\'intResult=
objDialog.ShowOpen
IfintResult=0ThenWscript.QuitElseWscript.EchoobjDialog.FileNameEndIf
这是一个小脚本,所以让我们逐行进行解释吧。
我们首先创建一个对UserAccounts.CommonDialog对象
的对象引用(名为“objDialog”)。
接着,我们设置对话框的“筛选”属性。
我们要显示所有文件,所
以我们将筛选设置成这样:
objDialog.Filter='AllFiles|*.*'
假如我们只想显示文本文件,那该怎么办?
在这种情况