Pregunta

Estoy tratando de encontrar una manera de forzar el reinicio de Windows, y me encuentro con problemas. Lo he intentado

Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _
     & "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_
     & "Primary=true")
for each OpSys in OpSysSet
    retVal = OpSys.Reboot()
next

También intenté usar el comando shutdown -f -r , y en ambos casos a veces no obtengo respuesta, y si lo intento de nuevo recibo un error que dice "La acción no se pudo completar porque el sistema se está cerrando " aunque no importa cuánto tiempo lo deje, no se apaga, todavía me permite iniciar nuevos programas y hacer un shutdown -a da el mismo error. ¿Cómo se puede usar un script para obligar a Windows a reiniciarse?

¿Fue útil?

Solución

Intente reemplazar:

retVal = OpSys.Reboot()

Con:

retVal = OpSys.Win32Shutdown(6)

Otros consejos

Bueno, esto usa VBScript, aunque en verdad invoca el mismo cierre de línea de comando que estás intentando hacer. Lo he probado y funciona.

Dim oShell 
Set oShell = CreateObject("WScript.Shell")

'restart, wait 5 seconds, force running apps to close
oShell.Run "%comspec% /c shutdown /r /t 5 /f", , TRUE

¿Con qué sistema operativo se está ejecutando? Esta prueba fue contra XP. Me pregunto si el sistema operativo del servidor requiere un código de apagado ...

También puede probar la utilidad de línea de comandos psShutdown de Sysinternals ahora Microsoft. http://technet.microsoft.com/en-us/sysinternals/bb897541. aspx

'*********************************************************

Option Explicit

Dim objShell

Set objShell = WScript.CreateObject("WScript.Shell")

objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"

'*********************************************************

Este pequeño script reinicia la computadora local después de 0 segundos.

Set Reset= WScript.CreateObject ("WScript.Shell")

Reset.run "shutdown -r -t 00", 0, True

O ..

Shell "shutdown -r -t 00"   ' for restart

Shell "shutdown -s -t 00"  ' for Shutdown

Shell "shutdown -l -t 00"   ' for log off

Shell "shutdown -a -t 00"  ' for abort
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top