# Ruby script that will restart a Windows server

**URL:** <https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848>\
**Category:** Ruby\
**Created:** [June 26, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848 "2007-06-26T21:26:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![grooveska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@grooveska](https://www.ruby-forum.com/u/grooveska)\
**Post date:** [June 26, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848/1 "2007-06-26T21:26:27Z")

</div>

I have been researching on how to write a script that will restart a  
Windows 2003 server. I haven’t had much luck yet and was wondering if  
anyone else had done anything similar, and how you went about creating  
that script.

Thanks!

---

<div class="post-metadata">

**Author:** ![grooveska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@grooveska](https://www.ruby-forum.com/u/grooveska)\
**Post date:** [June 26, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848/2 "2007-06-26T21:49:28Z")

</div>

On 6/26/07, grooveska [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have been researching on how to write a script that will restart a  
> Windows 2003 server. I haven’t had much luck yet and was wondering if  
> anyone else had done anything similar, and how you went about creating  
> that script.

Hi,

it depends whether you want a local restart or a remote one.

these can be useful:  
[Shutdown & Restart Shortcuts](http://www.aumha.org/win5/a/shutcut.php) (use `` to call)  
[ExitWindowsEx function (winuser.h) - Win32 apps | Microsoft Learn](http://msdn2.microsoft.com/en-us/library/aa376868.aspx) (use Win32API to  
call it)  
[http://groups.google.co.nz/group/ruby-talk-google/browse\_thread/thread/a0f7ec27d255ed63](http://groups.google.co.nz/group/ruby-talk-google/browse_thread/thread/a0f7ec27d255ed63)

Maybe WMI has something as well… (use Win32OLE to access WMI)

finally have a look at win32utils project at [rubyforge.org](http://rubyforge.org) - it may  
already wrap the function for you. (if not, and you succeed with  
wrapping, you may consider posting a patch for others to enjoy)

Jano

---

<div class="post-metadata">

**Author:** ![grooveska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@grooveska](https://www.ruby-forum.com/u/grooveska)\
**Post date:** [June 26, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848/3 "2007-06-26T21:58:30Z")

</div>

You could just do `shutdown /r`

On 6/26/07, grooveska [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > already wrap the function for you. (if not, and you succeed with  
> > wrapping, you may consider posting a patch for others to enjoy)
> > 
> > Jano

–  
“Hey brother christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![grooveska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@grooveska](https://www.ruby-forum.com/u/grooveska)\
**Post date:** [June 26, 2007, 9:55pm UTC](https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848/4 "2007-06-26T21:55:28Z")

</div>

Thanks for the reply Jano.

I am just looking to create a ruby script that will do a local  
restart. Just write the ruby script, create a task in task scheduler  
and be done with it. I’ll check out the links you’ve posted below.

I’ll take a look at the win32utils. I had forgotten about that  
project.

---

<div class="post-metadata">

**Author:** ![grooveska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@grooveska](https://www.ruby-forum.com/u/grooveska)\
**Post date:** [June 27, 2007, 12:35pm UTC](https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848/5 "2007-06-27T12:35:45Z")

</div>

cygwin also has a package with a reboot / restart command. And you can  
even schedule cron jobs with cygwin.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![grooveska](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@grooveska](https://www.ruby-forum.com/u/grooveska)\
**Post date:** [June 26, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/ruby-script-that-will-restart-a-windows-server/107848/6 "2007-06-26T22:17:33Z")

</div>

I just found that. Using that is probably much simpler than trying to  
access the WMI and all that stuff.

Thanks!
