ComradG Цитата:
Например можно так, но предупреждения не отобразится на мониторе пользователя, а наоборот отобразится на мониторе сервера. А требуется что именно пользователь был предупрежден. Ест варианты?. Заранее спасибо всем.
----------------------------------------------------
Dim strComputer, OperationMode, strUsername, strPassword
'Remote computername or IP
strComputer="172.5.5.155"
'Specify the OperationMode (0 = Restart, 1 = Logoff, 2 = Shutdown)
OperationMode = 2
'Credentials
strUsername = "Administrator"
strPassword = "password"
'put computername into uppercase
strComputer = UCase(strComputer)
'Perform the operation on remote PC
Call OperationAction
Sub OperationAction
On Error GoTo 0
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer _
(strComputer, "root\cimv2", strUsername, strPassword)
objSWbemServices.Security_.ImpersonationLevel = 3
'Call WMI query to collect parameters for reboot action
'Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//"_
'& strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem"_
'& " where Primary=true")
Set OpSysSet = objSWbemServices.ExecQuery("select * from Win32_OperatingSystem"_
& " where Primary=true")
Dim OpSysSet, OpSys
'Set PC to reboot
If OperationMode = 0 Then
For each OpSys in OpSysSet
opSys.Reboot()
Next
'Set PC to logoff
ElseIf OperationMode = 1 Then
Const EWX_LOGOFF = 0
For each OpSys in OpSysSet
opSys.win32shutdown EWX_LOGOFF
Next
'Set PC to shutdown
ElseIf OperationMode = 2 Then
For each OpSys in OpSysSet
WScript.Echo("Power failure. The computer will be automatically shutting down after 3 min. Please save your work.")
WScript.Sleep(180000)
opSys.Shutdown()
Next
End If
End Sub