用vbs脚本写一个随机抽签的命令 
时间: 2023-05-23 18:03:01 浏览: 30
这是一段用VBScript实现的随机抽签的脚本代码:
```
Dim arr, num
arr = Array("大吉", "中吉", "小吉", "吉", "末吉", "凶", "大凶") ' 定义抽签结果
num = Int((UBound(arr) - LBound(arr) + 1) * Rnd + LBound(arr)) ' 随机生成数组下标
WScript.Echo "您抽到的签是:" & arr(num) ' 输出结果
```
你可以将此代码保存成扩展名为 `.vbs` 的文件,然后双击运行即可看到抽签结果。
注意,由于 VBScript 本身的限制,该脚本只能在 Windows 系统中运行。
相关问题
用vbs脚本写一个每次打开都弹窗显随机内容
可以参考以下的代码:
```
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile("content.txt",1)
arrContent=Split(objFile.ReadAll, vbCrLf)
objFile.Close
Randomize
intIndex=Int(Rnd*UBound(arrContent))
strContent=arrContent(intIndex)
Set objShell=CreateObject("WScript.Shell")
objShell.Popup strContent, 0, "随机内容", 0
```
这段代码会从文件 "content.txt" 中读取内容,然后随机选择一条内容显示在弹窗中。弹窗的标题为 "随机内容",显示时间为 0 毫秒(也就是一直显示直到用户手动关闭)。其中 content.txt 的格式为每行一个内容。
用vbs脚本写一个局域网扫描
我可以回答这个问题。您可以使用以下vbs脚本来扫描局域网:
```
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * 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)
strIP = IPConfig.IPAddress(i)
If InStr(strIP, ".") > Then
strPrefix = Left(strIP, InStrRev(strIP, "."))
For j=1 To 254
strTestIP = strPrefix & j
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address='" & strTestIP & "'")
For Each objStatus in objPing
If objStatus.StatusCode = Then
WScript.Echo "IP Address: " & strTestIP & " is online."
End If
Next
Next
End If
Next
End If
Next
```
这个脚本将扫描您的局域网,并显示在线的IP地址。请注意,您需要以管理员身份运行此脚本。
相关推荐








