摘要:备忘
代码: ’获取本地IP地址 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set IPConfigSet = objWMIService.ExecQuery _ ("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) WScript.Echo IPConfig.IPAddress(i) Next End If Next
'获取本地电脑名称并和时间组合命名 'GET THE LOCAL MACHINE NAME AND DATETIME COMPOSITE LOG FILENAME Dim strComputer,strComputerName,objWMIService,colComputers,objComputer,Filename strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For Each objComputer in colComputers strComputerName = objComputer.Name Exit For Next
Filename=strComputerName & "-" & year(Now)&"-"&Month(Now)&"-"&day(Now) & ".txt" 'WScript.Echo Filename
'判断文件是否存在 'CHECK THE MAIN PROGRAM EXISTS Dim fso Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FileExists(ExeFile) Then WScript.Echo "Error: Cannot find executable file " & ExeFile 'If the main program does not exist, it means that there is a problem with the installation or it has been deleted Call WriteToLogFile(ErrorMsg, ServerOSCharSet) '此处时一个写log的方法,参数为错误讯息和字集 WScript.Quit End If
'传入2个参数判断本地和远程文件夹是否存在的一个方法,不存在则创建 'CHECK THAT LOCAL AND REMOTE FOLDERS EXIST Function CheckFolder(StrPath, RemotStrPath) Dim fsol 'locel Set fsol=CreateObject("Scripting.FileSystemObject") If Not fsol.folderExists(StrPath) Then fsol.CreateFolder(StrPath) End If
Dim fsor 'remote Set fsor=CreateObject("Scripting.FileSystemObject") If Not fsor.folderExists(RemotStrPath) Then fsor.CreateFolder(RemotStrPath) End If
Set fsor = Nothing Set fsol = Nothing End Function
|
|
一些恶搞电脑的代码就不放上来了,可以自行此文章
例如一些跳窗口,死循环,修改注册表,发出语音以及强制关机等参考
https://zhuanlan.zhihu.com/p/93441299