[ale] Don't flame me -- More Info
James Kinney
jkinney at localnetsolutions.com
Tue Jun 12 14:57:55 EDT 2001
Now, imbed that in some avi files on a web site.
fun!!
On Tue, 12 Jun 2001, Chris Fowler wrote:
> Majorally Off topic but here is the windows shutdown/reboot code. I pulled
> it out of my code.
>
> void
> command(int cmd)
> {
> char byte[1];
>
> switch(cmd)
> {
> case 's':
> write(fd,"\nSHUTDOWN: Sure? (Y/N):", 23);
> read(fd, byte, 1);
> if((byte[0] == 'y') || (byte[0] == 'Y'))
> shutdown(EWX_SHUTDOWN);
> break;
> case 'r':
> write(fd,"\nREBOOT: Sure? (Y/N):", 21);
> read(fd, byte, 1);
> if((byte[0] == 'y') || (byte[0] == 'Y'))
> shutdown(EWX_REBOOT);
> break;
> case 'k':
> kill(cPid, SIGKILL);
> break;
> default:
> write(fd, "\n------------------------\n", 26);
> write(fd, "Commands:\n", 10);
> write(fd, "s: Shutdown\n", 17);
> write(fd, "r: Reboot", 14);
> write(fd, "k: kill Command\n", 21);
> write(fd, "\n------------------------\n", 26);
> break;
> }
> write(fd,'\n', 1);
>
> CMD=0;
> }
>
> /* int shutdown(int option)
> *
> * Function will shutdown and/or reboot system
> *
> * Arguments:
> * int option: EWX_REBOOT or EWX_SHUTDOWN
> *
> * Returns:
> * Nothing
> *
> */
> int
> shutdown(int option)
> {
>
> // Get a token for this proces
> HANDLE hToken; TOKEN_PRIVILEGES tkp;
>
> // Get the LUID for the shutdown privilege.
> if (!OpenProcessToken(GetCurrentProcess(),
> TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
> perror("OpenProcessToken");
>
> LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
> &tkp.Privileges[0].Luid);
>
> tkp.PrivilegeCount = 1; // one privilege to set
> tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
>
> // Get the shutdown privilege for this process.
> AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
> (PTOKEN_PRIVILEGES)NULL, 0);
>
> // Cannot test the return value of AdjustTokenPrivileges.
> if (GetLastError() != ERROR_SUCCESS)
> perror("AdjustTokenPrivileges");
>
> // Shut down the system and force all applications to close.
> if (!ExitWindowsEx(option | EWX_FORCE, 0))
> perror("ExitWindowsEx");
>
> }
>
> -----Original Message-----
> From: Eric Z. Ayers [mailto:eric.ayers at mindspring.com]
> Sent: Tuesday, June 12, 2001 4:53 AM
> To: Chris Fowler
> Cc: 'ale at ale.org'
> Subject: Re: [ale] Don't flame me -- More Info
>
>
> Chris Fowler wrote:
>
> > I've tried this and it does not work!
> >
> > I like the cygwin environment. In fact, I don't think I'll port to
> > win32 at all!
> >
> > How can I issue a shutdown in W2K in cygwin? I want to do it in code.
> >
>
> > You'll want to ask this on the cygwin mailing list. Go to redhat's
> > web site to find it. And check the mailling list archives first.
> > Some of the most knowledgeable folks are, unfortunately, not too nice
> > when someone asks a FAQ.
>
>
> >
> > -----Original Message-----
> > From: Vernard Martin [mailto:vernard at cc.gatech.edu]
> > Sent: Monday, June 11, 2001 10:13 AM
> > To: Cade Thacker
> > Cc: Eric Z. Ayers; 'ale at ale.org'
> > Subject: Re: [ale] Don't flame me -- More Info
> >
> >
> > > How do I compile this file, so that my prof can run it on her computer
> > > that does not have the cywin dll?
> >
> > Hrm. I don't think that is possible under windows. What you
> > effectively want is
> > a "static" executable that includes the code itself and all the
> > libraries that
> > it needs to run. you can do that under unix usually with some compiler
> > option
> > such as "-static" or somesuch. I would check to see if the compiler
> > you are
> > using with cygwin (mostly likely gcc) has this option and what it does
> > under
> > the windows platform.
> >
> > hope this helps
> > V
> > --
> > Vernard Martin (vernard at cc.gatech.edu)
> > http://www.cc.gatech.edu/~vernard/
> > "Anything worth fighting over is worth fighting dirty over"
> > --
> > To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in
> > message body.
> >
>
>
> --
> To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message
> body.
>
--
James P. Kinney III \Changing the mobile computing world/
President and COO \ one Linux user /
Local Net Solutions,LLC \ at a time. /
770-493-8244 \.___________________________./
--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
More information about the Ale
mailing list