您好,欢迎访问三七文档
VBS代码片断大全[一]1VBS取得本机IPstrComputer=.SetobjWMIService=GetObject(winmgmts:\&strComputer&\root\cimv2)SetIPConfigSet=objWMIService.ExecQuery(SelectIPAddressfromWin32_NetworkAdapterConfigurationWhereIPEnabled=TRUE)ForEachIPConfiginIPConfigSetIfNotIsNull(IPConfig.IPAddress)ThenForEachstrAddressinIPConfig.IPAddressWScript.EchostrAddressNextEndIfNext--------------------------------------------------------------------------------2取得本机计算机名strComputer=.SetobjWMIService=GetObject(winmgmts:\&strComputer&\root\cimv2)SetcolComputers=objWMIService.ExecQuery(Select*fromWin32_ComputerSystem)ForEachobjComputerincolComputersWscript.EchoobjComputer.NameNext--------------------------------------------------------------------------------4检查升级包strComputer=.SetobjWMIService=GetObject(winmgmts:\&strComputer&\root\cimv2)SetcolOperatingSystems=objWMIService.ExecQuery(Select*fromWin32_OperatingSystem)ForEachobjOperatingSystemincolOperatingSystemsWscript.EchoobjOperatingSystem.ServicePackMajorVersion&.&objOperatingSystem.ServicePackMinorVersionNext--------------------------------------------------------------------------------5检查HotFixstrComputer=.SetobjWMIService=GetObject(winmgmts:\&strComputer&\root\cimv2)SetcolQuickFixes=objWMIService.ExecQuery(Select*fromWin32_QuickFixEngineering)ForEachobjQuickFixincolQuickFixesWscript.EchoDescription:&objQuickFix.DescriptionWscript.EchoHotFixID:&objQuickFix.HotFixIDNext--------------------------------------------------------------------------------6检查本地管理员数目SetobjNetwork=CreateObject(Wscript.Network)strComputer=objNetwork.ComputerNameSetobjGroup=GetObject(WinNT://&strComputer&/Administrators,group)ForEachobjUserinobjGroup.MembersWscript.EchoobjUser.NameNext--------------------------------------------------------------------------------7磁盘系统strComputer=.SetobjWMIService=GetObject(winmgmts:\&strComputer&\root\cimv2)SetcolDisks=objWMIService.ExecQuery(Select*fromWin32_LogicalDiskWhereDriveType=3)ForEachobjDiskincolDisksWscript.EchoDiskdrive:&objDisk.DeviceID&--&objDisk.FileSystemNext--------------------------------------------------------------------------------8检测自动登录是否开启ConstHKEY_LOCAL_MACHINE=&H80000002strComputer=.SetobjReg=GetObject(winmgmts:\&strComputer&\root\default:StdRegProv)strKeyPath=Software\Microsoft\WindowsNT\CurrentVersion\WinLogonstrValueName=AutoAdminLogonobjReg.GetDWORDValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValueIfdwValue=1ThenWscript.EchoAutologonisenabled.ElseWscript.EchoAutologonisdisabled.EndIf--------------------------------------------------------------------------------9关闭自动登录ConstHKEY_LOCAL_MACHINE=&H80000002strComputer=.SetobjReg=GetObject(winmgmts:\&strComputer&\root\default:StdRegProv)strKeyPath=Software\Microsoft\WindowsNT\CurrentVersion\WinLogonstrValueName=AutoAdminLogondwValue=0oReg.SetDWORDValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue-------------------------------------------------------------------------10检查Guest是否禁用SetobjNetwork=CreateObject(Wscript.Network)strComputer=objNetwork.ComputerNameSetobjUser=GetObject(WinNT://&strComputer&/Guest)IfobjUser.AccountDisabledThenWscript.EchoTheGuestaccountisdisabled.ElseWscript.EchoTheGuestaccountisenabled.EndIf-------------------------------------------------------------------------11关闭GuestSetobjNetwork=CreateObject(Wscript.Network)strComputer=objNetwork.ComputerNameSetobjUser=GetObject(WinNT://&strComputer&/Guest)IfobjUser.AccountDisabledThenWscript.EchoTheGuestaccountisalreadydisabled.ElseobjUser.AccountDisabled=TrueobjUser.SetInfoWscript.EchoTheGuestaccounthasbeendisabled.EndIf--------------------------------------------------------------------------------12检索本地共象strComputer=.SetobjWMIService=GetObject(winmgmts:\\&strComputer&\root\cimv2)SetcolShares=objWMIService.ExecQuery(Select*fromWin32_Share)ForeachobjShareincolSharesWscript.EchoName:&objShare.NameWscript.EchoPath:&objShare.PathWscript.EchoType:&objShare.TypeNext--------------------------------------------------------------------------------13脚本检索一个文件夹下.txt文件汗哦值得学习SetobjWMIService=GetObject(winmgmts:\\.\root\cimv2)SetcolFiles=objWMIService.ExecQuery(SELECT*FROMCIM_DataFileWHEREPath='\\DocumentsandSettings\\Administrator\\桌面\\'ANDDrive='E:'ANDExtension='txt')Wscript.EchoNumberof.txtfilesfound:&colFiles.CountforeachaaincolFilesNL=NL&vbcrlf&aa.namenextWscript.EchoNL作者:60.13.134.*2005-4-2119:39回复此发言--------------------------------------------------------------------------------14我如何向用户显示一个用来选择文件的对话框?问:嗨,ScriptingGuy!有没有什么方法可以让我使用脚本向用户显示一个对话框,供用户选择文件使用?--BF答:您好,BF。如果您使用的是Windows2000,我们不知道实现此操作的方法,至少操作系统中没有内置这样的方法。但如果您使用的是WindowsXP,情况就不同了。在WindowsXP上,您可以使用“UserAccounts.CommonDialog”对象向用户显示一个标准的“文件打开”对话框。可以用类似以下代码的脚本:SetobjDialog=CreateObject(UserAccounts.CommonDialog)objDialog.Filter=AllFiles|*.*objDialog.InitialDir=C:\intResult=objDialog.ShowOpenIfintResult=0ThenWscript.QuitElseWscript.EchoobjDialog.FileNameEndIf这是一个小脚本,所以让我们逐行进行解释吧。我们首先创建一个对UserAccounts.CommonDialog对象的对象引用(名为“objDialog”)。接着,我们设置对话框的“筛选”属性。我们要显示所有文件,所以我们将筛选设置成这样:objDialog.Filter=Al
本文标题:VBS经典代码大全
链接地址:https://www.777doc.com/doc-4371341 .html