如何实现把一个程序自身复制到指定的目录中,比如c:/windows/system下?(40分)如何实现在windows即将关机和重起的时候自动关掉程序?(程序已

  • 主题发起人 主题发起人 liuyang
  • 开始时间 开始时间
L

liuyang

Unregistered / Unconfirmed
GUEST, unregistred user!
如何实现把一个程序自身复制到指定的目录中,比如c:/windows/system下?(40分)如何实现在windows即将关机和重起的时候自动关掉程序?(程序已经在任务栏)(60分)(100分)<br />如何实现把一个程序自身复制到指定的目录中,比如c:/windows/system下?(40分)<br>如何实现在windows即将关机和重起的时候自动关掉程序?(程序已经在任务栏)(60分)<br>各位大虾帮帮小弟。^-^
 
程序在关机和重起是会自动关闭。<br><br>不能关的接管wm_queryendsession消息,强制保存信息并设置result:=true;
 
关机消息:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br><br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure MyShutDown(var Message:TMessage );Message WM_USERCHANGED; //更改当前用户<br>&nbsp; &nbsp; procedure MyEndsession(var Message:TMessage );Message WM_ENDSESSION;//注消当前用户<br>&nbsp; &nbsp; procedure MyQuseryEnd(var Message:TMessage );Message WM_QUERYENDSESSION;//关机或重新启动<br>&nbsp; &nbsp; procedure ExitApp();//自定义退出函数<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>procedure TForm1.MyEndsession(var Message:TMessage );<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitApp();<br>&nbsp; &nbsp; &nbsp; &nbsp; inherited ; //继承Windows原消息处理机制,不能省,否则此消息会被你的程序堵塞,其他程序无法响应<br>end;<br>procedure TForm1.MyQuseryEnd(var Message:TMessage );<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitApp();<br>&nbsp; &nbsp; &nbsp; &nbsp; inherited ;<br>end;<br>procedure TForm1.MyShutDown(var Message:TMessage );<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitApp();<br>&nbsp; &nbsp; &nbsp; &nbsp; inherited ;<br>end;<br><br>procedure TForm1.ExitApp();<br>begin<br>&nbsp; &nbsp; &nbsp;Application.messagebox('windows close ','information',mb_ok);<br>&nbsp; &nbsp; &nbsp; &nbsp;if Not Form1.Visible Then<br>&nbsp; &nbsp; &nbsp; &nbsp;Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Form1.show;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BringWindowToTop(Application.Handle);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.Restore;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(Application.Handle);<br>&nbsp; &nbsp; &nbsp; &nbsp;End;<br>&nbsp; &nbsp; &nbsp; &nbsp;Form1.Close;<br>end;<br>end.<br>
 
1.如何实现把一个程序自身复制到指定的目录中,比如c:/windows/system下?(40分)<br>&nbsp; &nbsp;copyfile(pchar(application.exename),pchar('c:/windows/system/test.exe'),true);<br>2.windows关闭时会向程序发送关闭消息。
 
多人接受答案了。
 
后退
顶部