delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/08/01/03:34:47

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Wed, 1 Aug 2001 09:34:25 +0200
From: Corinna Vinschen <cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Rebooting a windows 2000 box
Message-ID: <20010801093425.C9574@cygbert.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <20010801002530 DOT A13414 AT templar DOT icewall DOT net>
Mime-Version: 1.0
User-Agent: Mutt/1.2.5i
In-Reply-To: <20010801002530.A13414@templar.icewall.net>; from mabehr@alum.mit.edu on Wed, Aug 01, 2001 at 12:25:30AM -0400

> Hello all,
> 
> I need to reboot a win2k box from remote.  I'm using ssh to connect to
> the machine...  is there a command that I can send through cygwin to
> reboot the machine?

I wrote the following tiny code in 1998. If you call it `shutdown.exe'
it will shutdown, call it `reboot.exe' and it will reboot. Otherwise
use the flags.

Hope, that helps,
Corinna

------------------------------ SNIP -------------------------------
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <getopt.h>

#include <windows.h>

int reboot = FALSE;
int force = FALSE;

char *myname;

int usage(void)
{
	fprintf(stderr, "usage: %s [-fr] secs|\"now\"\n", myname);
	return 1;
}

int main(int argc, char **argv)
{
	int c;
	unsigned int secs;
	HANDLE token;
	TOKEN_PRIVILEGES privs;

	if ((myname = strrchr(argv[0], '/')) ||
		(myname = strrchr(argv[0], '\\')))
		++myname;
	else
		myname = argv[0];
	if (strrchr(myname, '.'))
		*strrchr(myname, '.') = '\0';
	if (! strcmp(myname, "reboot"))
		reboot = TRUE;
	while ((c = getopt(argc, argv, "fr")) != EOF)
		switch (c) {
		case 'f':
			force = TRUE;
			break;
		case 'r':
			reboot = TRUE;
			break;
		default:
			return usage();
		}
	if (optind >= argc)
		return usage();
	if (! strcmp(argv[optind], "now"))
		secs = 0;
	else if (! isdigit(argv[optind][0])) {
		usage();
		fprintf(stderr, "%s: secs must be numerical or the word \"now\"\n",
						myname);
		return 2;
	} else
		secs = atoi(argv[optind]);

	privs.PrivilegeCount = 1;
	LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &privs.Privileges[0].Luid);
	privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	if (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token)) {
		int ret = GetLastError();
		fprintf(stderr, "%s: insufficient privileges\n", myname);
		return 3;
	}
	if (! AdjustTokenPrivileges(token, FALSE, &privs, 0, NULL, NULL)) {
		fprintf(stderr, "%s: insufficient privileges\n", myname);
		return 3;
	}


	printf("WARNING!!! System is going down ");
	if (secs)
		printf("in %d seconds\n", secs);
	else
		printf("NOW\n");
	while (secs)
		secs = sleep(secs);
	if (! InitiateSystemShutdown(NULL, NULL, 0, force, reboot)) {
		fprintf(stderr, "%s: insufficient privileges\n", myname);
		return 3;
	}
	return 0;
}

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin AT cygwin DOT com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019