Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 #include #include #include #include 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/