Blog Archives

Shortcuts that everyone must absolutely know

Whether you are beginners who just want to survive in the post-2012 computing ecosystem that Microsoft created or a computer guru, there are shortcuts that you must absolutely know.

A backspace key on a rock, having been removed from a keyboard.

As soon as you see these shortcuts, you’ll be laughing and saying: “Ha! I knew them!” But I am not sure that would be the case when you are done reading.

Read the rest of this entry

Windows 8.1 – An update fiasco

Windows 8.1, advertised as a free update, has arrived. But it is neither free nor an update.

Windows 8.0 in comparison to Windows 8.1.

Windows 8.0 in comparison to Windows 8.1

Read the rest of this entry

Windows 8.1 Preview: Hits and misses

Windows 8.1 Preview has both new features and flops, some of which are bugs that will be solved by the time it is released to manufacturing (RTM) and some are flops by design and will never get fixed.
Screenshot: Windows 8.1 error  on small screen
Here is the first: Windows 8.1 Preview still does not run Metro-style apps on screens whose vertical resolution is lower than 768. That means, they do not run on your 720p High Definition TV (1280×720) .

Read the rest of this entry

Autoruns 11.42: The case of missing list items

While performing my duties as a computer and network administrator, I have often used Sysinternals Autoruns to manage computer programs that automatically start with the computer. Frankly, it is the most advanced startup management tool I have known to date. Therefore, it came as a shock to me when I observed that myriads of startup entries cease to show up after enabling digital signature verification. Was it a bug or was it my fault?

Read the rest of this entry

Windows 8.1 Preview: First startup

Windows 8.1 Start screen on a 16:9 display

Windows 8.1 Start screen features new apps, a downward arrow button for accessing all apps, new sizes of tiles and an animated background

As I said in my previous post, Windows 8.1 Preview is released for the public to test. Let’s see what it is and how does it look. Read the rest of this entry

Exit Windows using keyboard

This slideshow requires JavaScript.

You can shut down, restart or log out of Windows with just a standard keyboard; this method works on all popular versions of Windows for PCs, i.e. Windows XP, Windows 7 and the upcoming Windows 8. Although I have not tested, but I believe this method should work in Windows Vista and all members of Windows Server family of operating systems. Read the rest of this entry

Windows 8 Beta – First impression

Finally, I managed to download a copy of Windows 8 Consumer Preview and try it out. Not an easy feat for one who is constantly roaming and is away from home. I am afraid it did not leave a good impression on me. Here is why.

Windows 8 Basic theme

Windows 7 Basic theme

Read the rest of this entry

Shutting down, restarting or logging out via shortcuts, batch files and scripts – Part 2

Introducing PsShutdown.exe

In the previous episode, we saw Shutdown.exe, a command-line tool that could perform shutdown, restart or logout. We also saw that the earlier version of Shudown.exe included with Windows XP suffers from certain discrepancies that severely limit its usage scenarios.

In addition to Shutdown.exe, a freeware called PsShutdown.exe is also available from Microsoft that features additional capabilities over Shutdown.exe in Windows XP. It can hibernate a computer or lock a user session. (Locking a user session returns the user to the logon screen without logging out. The user can return to work by logging back on.) However, as of 2 August 2010, the latest version of this tool (2.52.0.0) also suffered from a crippling shortcoming: Only users with administrative privileges could use it. Hence, I will no longer elaborate on it. In fact, if you are using Windows 7 or Windows Server 2008, you are already in possession of the improved version of Shutdown.exe which should be more than enough to handle automatic shutdown of your local machine.

Creating our own shutdown tool

If you are using Windows XP or Windows Server 2003, you do not have to cope with the discrepancies of Shutdown.exe: You can create your own shutdown tool. To do so, you use Windows Script Host (WSH), a Windows component that allows you to run scripts that you yourself have created in JScript and VBScript languages.

Composing the scripts

Familiarize yourself with the icon of VBScript script files. These files have .VBS file name extension.

You don’t need to create an entire script by yourself: I have already written the scripts for you. Follow the following instructions to import them to your computer.

  1. Start Notepad. You should find it in the Start menu.
  2. Look below and find the script for the task (shutdown, restart or log out) that you need. (Some tasks may have two scripts written for them. You can choose either of them.)
  3. Copy the entire script into clipboard. To do so, highlight the script using your mouse. Then, right-click on you selection and from the menu that appears, select Copy.
  4. Paste the entire script into Notepad. To do so, right-click somewhere in the Notepad and from the menu that appears, select Paste.
  5. Save the entire script under a name of your liking but with .vbs filename extension. If you do not know what I mean, follow these instructions carefully:
    1. In Notepad menu bar, click File, and then select Save As…
    2. Browse to the location in which you’d like to save the file. For example, Desktop.
    3. Click inside File Name field.
    4. Type a quotation mark (“).
    5. Type a name for your script. Anything will do, but I suggest you type a suitable name.
    6. Type: .vbs (Do not forget the dot.)
    7. Type another quotation mark (“).
    8. Optional: Make sure that Encoding field contains either ANSI or Unicode. It should not contain UTF-8 or Unicode Big Endian.
    9. Press Save button.
  6. Prepare to test the script: Close all your open applications and save any unsaved changes.

Your script should now be ready. If you have named it correctly, it should look like as displayed in the picture. Repeat the steps above to create other scripts that perform other tasks.

Executing the scripts

You can now execute these scripts as you execute normal apps: Just double-click on them!

You might also like to ask other software to run these scripts. For example, I have a 3D rendering application that lets me run an application when the rendering is complete. Sometimes, rendering a piece of 3D work takes a long time, so it might be a good idea to ask this application to use these scripts to shutdown the system after the work is complete. That way, I can leave the system alone.

Running these scripts from within third-party software, however, is slightly more complicated. You must tell such software to run Windows Script Host with the path to your script as the argument. For example, if your shutdown script, called Shutdown.vbs, is saved in C:\Program Files\Admin Scripts, you can tell your third-party software to run this command:

"%systemroot%\system32\wscript.exe" "%ProgramFiles%\Admin Scripts\Shutdown.vbs"

Script codes

Blog software have a bad reputation of corrupting blog posts. If in the future, you found that these scripts are corrupted, you can find a copy of them on GitHub.

Shutdown

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, "Shutdown via script"


Const LOGOFF = 0
Const SHUTDOWN = 1
Const REBOOT = 2
Const POWEROFF = 8

Const LOGOFF_FORCE = 4
Const SHUTDOWN_FORCE = 5
Const REBOOT_FORCE = 6
Const POWEROFF_FORCE = 12

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
 ObjOperatingSystem.Win32Shutdown(POWEROFF)
Next

Shutdown (Alternative)

This scripts does exactly what the one above does, only using a different code.

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, "Shutdown via script"


strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Shutdown()
Next

Restart

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, "Restart via script"


Const LOGOFF = 0
Const SHUTDOWN = 1
Const REBOOT = 2
Const POWEROFF = 8

Const LOGOFF_FORCE = 4
Const SHUTDOWN_FORCE = 5
Const REBOOT_FORCE = 6
Const POWEROFF_FORCE = 12

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
 ObjOperatingSystem.Win32Shutdown(REBOOT)
Next

Restart (Alternative)

Like the script above, the following script also restarts the computer:

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, "Restart via script"


strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Reboot()
Next

Logging off

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, "Logging off via script"


Const LOGOFF = 0
Const SHUTDOWN = 1
Const REBOOT = 2
Const POWEROFF = 8

Const LOGOFF_FORCE = 4
Const SHUTDOWN_FORCE = 5
Const REBOOT_FORCE = 6
Const POWEROFF_FORCE = 12

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
 ObjOperatingSystem.Win32Shutdown(LOGOFF)
Next

Further reading

For more information about these scripts, see:

  1. “Shutting Down Computers and Logging Off Users”. Scripting Center. Microsoft Corporation. 22 October 2009.
  2. “Shutting Down a Computer”. Scripting Center. Microsoft Corporation. 22 October 2009.
  3. “Restarting a Computer”. Scripting Center. Microsoft Corporation. 22 October 2009.
  4. “Win32Shutdown Method of the Win32_OperatingSystem Class”. Windows Dev Center. Microsoft Corporation. 9 September 2010.
  5. “Reboot Method of the Win32_OperatingSystem Class”. Windows Dev Center. Microsoft Corporation. 9 September 2010.
  6. “Shutdown Method of the Win32_OperatingSystemClass”. Windows Dev Center. Microsoft Corporation. 9 September 2010.

What’s next?

I promised to blog about PowerShell cmdlets that allows system administrators to perform shutdown and restart. I will leave that to another blog post.

%d bloggers like this: