Страница 8 из 24 11)--------------------------------------------------------------------------- Q> Как зашутдаунить удаленный компьютер? A> int main(int argc, char **argv) { HANDLE hToken; TOKEN_PRIVILEGES tkp; //------------------- char *name=""; // address of name of computer to shut down char *msg=""; //address of message to display in dialog box DWORD time=0; // time to display dialog box bool force=true; // force applications with unsaved changes flag bool reboot=true; //reboot flag //--------------------------------------------------------------------- OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken); if(!LookupPrivilegeValue(name, SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid)){ printf ("SE_SHUTDOWN_NAME Privilege облом \n"); return 1 ;}; tkp.PrivilegeCount =1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0); if(!LookupPrivilegeValue(name, SE_REMOTE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid)){ printf("SE_REMOTE_SHUTDOWN_NAME Privilege облом \n"); return 2 ;}; tkp.PrivilegeCount =1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0); if (InitiateSystemShutdown(name,msg,time,force,reboot)) printf("%s shutdown Ok\n",name); else printf("Can't shutdown %s \n",name); return 0; } 12)---------------------------------------------------------------------------- Q> Как сделать чтобы окошко не появлялось на таскбаре? A> There is more than one way to stop a window appearing on the taskbar. Rather than WS_EX_APPWINDOW, give your window the WS_EX_TOOLWINDOW extended style. Since toolbars don't appear on the taskbar, this will prevent it appearing there. Unfortunately, this has some rather negative repercussions on the appearance of your window : it gets a thin caption with smaller title, and loses its system menu. This is not acceptable to many people. Windows owned by an invisible window won't appear on the taskbar. "Great", say you, "but my app is dialog based, so what now Mr Smarty ?". Well, you can either recast your dialog app as an SDI with a hidden main window, and have that main window shown at startup, or you can create your own hidden window and set that as your dialogs owner. 13)--------------------------------------------------------------------------- Q> Как запустить(придушить) скринсэйвер A> Starting The method for starting a screen saver is simple, but surprising. You post your own window a message ! Post yourself the WM_SYSCOMMAND message with the SC_SCREE NSAVE parameter : // Uses MFC CWnd::PostMessage PostMessage (WM_SYSCOMMAND, SC_SCREENSAVE); Stopping Stopping a screen saver is somewhat more complex. The Microsoft-documented way of doing this is to look for the special screen-saver desktop, enumerate all windows on that desktop, and close them, as follows: hdesk = OpenDesktop(TEXT("Screen-saver"), 0, FALSE, DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS); if (hdesk) { EnumDesktopWindows (hdesk, (WNDENUMPROC)KillScreenSaverFunc, 0); CloseDesktop (hdesk); } // ---------------------------------------------------------------- BOOL CALLBACK KillScreenSaverFunc (HWND hwnd, LPARAM lParam) { PostMessage(hwnd, WM_CLOSE, 0, 0); return TRUE; } |