The following is a small command line utility I wrote to terminate a remote machine. You can alter this as necessary and then use a simple batch file to run the program repeatedly, once for every machine you want to shutdown (obviously you need administrator rights on the machines you want to shut down)
#include <stdio.h>
#include <stdos.h>
#include <windows.h>
LRESULT CALLBACK EXPORT wincallback (HWND hwnd, MESSAGE message, WPARAM warg, LPARAM larg);
HWND applnwinhdl = NULL;
HBRUSH bkbrush = NULL;
HINSTANCE applninstance = NULL;
CCHAR *applntitle = "Remote Terminationn";
BOOL parsecmdline(CHAR *cmdline, CHAR *machine, CHAR *message);
BOOL killmachine (CHAR *machine, CHAR *closemsg);
INT WINAPI WinMain (HINSTANCE currinstance, HINSTANCE previnstance, LPSTR cmdline, INT showmode)
{ MSG msg;
INT msgret;
INT ok = 1;
DWORD err;
WNDCLASS WC;
CHAR machine[100];
CHAR message[500];
const CHAR *winclassname = "SHUTDOWN";
applninstance = currinstance;
// Register class:
bkbrush = CreateSolidBrush (GetSysColor(COLOR_BTNFACE));
WC.style = CS_HREDRAW | CS_VREDRAW;
WC.lpfnWndProc = (LPVOID) wincallback;;
WC.cbClsExtra = 0;
WC.cbWndExtra = 0;
WC.hInstance = applninstance;
WC.hIcon = NULL;
WC.hCursor = LoadCursor (NULL, IDC_ARROW);
WC.hbrBackground = bkbrush;
WC.lpszMenuName = NULL;
WC.lpszClassName = winclassname;
RegisterClass (&WC);
// Create window - We need a window and a message pump but need do nothing with them :
if ((applnwinhdl = CreateWindowEx (0, winclassname, applntitle, WS_OVERLAPPEDWINDOW | DS_3DLOOK, 0,0,700,350, NULL, NULL, applninstance, NULL)) == NULL)
MessageBox(applnwinhdl,"Initialisation Failure - window not created.", NULL,MB_OK|MB_SYSTEMMODAL|MB_ICONHAND);
// Parse the command line args :
if ((ok = parsecmdline(cmdline,machine,message)) == FALSE)
MessageBox(applnwinhdl,"Incorrect command line.\n Usage: 'shutdown -c:<computer name> -m:<message>'", NULL,MB_OK|MB_SYSTEMMODAL|MB_ICONHAND);
else
{ // Call System Shutdown :
if ((ok = killmachine(machine,message)) == FALSE)
MessageBox(applnwinhdl,"Unable to remotely close computer.\n Permissions are too high or computer is already off.", NULL,MB_OK|MB_SYSTEMMODAL|MB_ICONHAND);
}
// Send close message to kill the window etc. :
SendMessage(applnwinhdl,WM_CLOSE,0,0);
// Default Message Loop:
if (applnwinhdl != NULL)
{ while( (msgret = GetMessage( &msg, NULL, 0, 0 )) != 0)
{ if (msgret == -1)
{ // error
MessageBox(applnwinhdl,"Unrecognised or malformed Message - error occurred in pump while processing message.", NULL,MB_OK|MB_SYSTEMMODAL|MB_ICONHAND);
}
else
{ TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
// Unregister the window class and exit :
UnregisterClass (WC.lpszClassName, currinstance);
return 0;
}
LRESULT CALLBACK EXPORT wincallback (HWND hwnd, MESSAGE message, WPARAM warg, LPARAM larg)
{ switch (message)
{ case WM_CLOSE :
DestroyWindow(hwnd);
PostQuitMessage(0);
return 0;
default :
return DefWindowProc (hwnd,message,warg,larg);
}
}
BOOL parsecmdline (CHAR *cmdline, CHAR *machine, CHAR *message)
// Parse Command Line Arguments to determine the network computer name and
// the display message.
// Note that args must be in order : -c:<computer name> -m:<message>.
{ CHAR cmd[500];
INT size = 0;
CHAR *cptr = NULL;
CHAR *space = NULL;
// First take a copy of the command line:
strcpy(cmd,cmdline);
// Find the start and end of the computer name :
if ((cptr = strstr(cmd,"-c:"

) == NULL)
return FALSE;
if ((space = strchr(cmd,' ')) == NULL)
return FALSE;
// Copy and null terminate:
size = space - (cptr+3);
strncpy(machine,cptr+3,size);
*(machine+size) = '\0';
// Advance command line pointer and find message:
cptr += size;
if ((cptr = strstr(cmd,"-m:"

) == NULL)
return FALSE;
// Copy the message and return:
strcpy(message,cptr+3);
return TRUE;
}
BOOL killmachine (CHAR *machine, CHAR *closemsg)
// Terminate the local machine or any network machine. We need to first acquire
// shutdown privilages on the machine in order to successfully force a close :
{ HANDLE token; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL result; // system shutdown flag
// Get the current process token handle so we can get shutdown privilege.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
return FALSE;
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
// One privilege to set:
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(token, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot directly test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Display the shutdown dialog box and start the countdown.
result = InitiateSystemShutdown(machine,closemsg,0,FALSE,TRUE);
if (!result)
return FALSE;
// Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(token, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
return TRUE;
}