如题,最好有源代码,最先解决的得全分
解决方案 »
- 大家好,请教如何在DELPHI 中是使用LISP(Common Lisp) ,不是用来开发CAD。
- Qreport组件打印预览的问题
- 急!在线等!求救,也是两个oracle数据库连接的问题
- 真金白银购买了Report Machine控件,但现在该控件的开发者王海丰不肯给予技术支持,只好来这里救助!请大侠们帮帮偶!谢谢!
- 怎么在线程里显示模式窗体?
- DELPHI网络数据库的问题,谢谢!
- 碰到一打印问题,请大虾们帮忙.(delphi调用EXCEL)
- 强烈建议新开星星版块,裤头菜鸟禁入,或裤头少的菜鸟禁入!!
- stream read error
- 如何取得应用程序的句柄??
- Field为datetime或smalldatetime类型时,在DBEdit中输入10:20后,失去焦点,就会变成1899-12-30 10:20:00,要得到10:10格式的时间,怎么
- 初学问题:listview关中使用vsreport时更改列标题的问题!在线立刻给分!!
2。自己全部从新写吗?
这段代码是格式化软盘的,那硬盘那?
类推 2--C盘.....
我绝没有什么不良的想法,
SysUtils, Classes, Windows;function RunConsole(const ApplicationName, Parameters, WorkDir: String; AppOutput: TStrings): DWORD;procedure GetExeInfo(const Filename: String; var BinaryType, Subsystem: DWORD);const
SCS_VXD_BINARY = 6; {linear executable. Could be OS/2. NT thinks DOS!}
SCS_WIN32_DLL = 7;
SCS_DPMI_BINARY = 8; {guessing a bit here. Based on NE header loader flags}{
SCS_32BIT_BINARY = 0; A Win32-based application
SCS_DOS_BINARY = 1; An MS-DOS - based application
SCS_WOW_BINARY = 2; A 16-bit Windows-based application
SCS_PIF_BINARY = 3; A PIF file that executes an MS-DOS - based application
SCS_POSIX_BINARY = 4; A POSIX - based application
SCS_OS216_BINARY = 5; A 16-bit OS/2-based application (NE, not LE (mgl))
IMAGE_SUBSYSTEM_UNKNOWN = 0; Unknown subsystem
IMAGE_SUBSYSTEM_NATIVE = 1; Image doesn't require a subsystem. Probably a kernel mode device driver
IMAGE_SUBSYSTEM_WINDOWS_GUI = 2; Image runs in the Windows GUI subsystem.
IMAGE_SUBSYSTEM_WINDOWS_CUI = 3; Image runs in the Windows character subsystem.
IMAGE_SUBSYSTEM_OS2_CUI = 5; Image runs in the OS/2 character subsystem.
IMAGE_SUBSYSTEM_POSIX_CUI = 7; Image runs in the Posix character subsystem.
IMAGE_SUBSYSTEM_RESERVED8 = 8; Image runs in the 8 subsystem.
}implementationprocedure GetExeInfo( const Filename: String; var BinaryType, Subsystem: DWORD);
var
f: File;
ImageDosHeader: IMAGE_DOS_HEADER;
ImageFileHeader: IMAGE_FILE_HEADER;
ImageOptionalHeader: IMAGE_OPTIONAL_HEADER;
Signature: DWORD;
NEType: Byte;
begin
AssignFile(f, Filename);
Reset(f, 1); {note that this will fail if file is open. this is a bug really, but not a big one. Use Api File calls to work around}
try
BlockRead(f, ImageDosHeader, Sizeof(ImageDosHeader));
if (ImageDosHeader.e_magic <> IMAGE_DOS_SIGNATURE) then {not executable}
raise EInOutError.Create('Dos signature not present');
Seek(f, ImageDosHeader._lfanew);
BlockRead(f, Signature, SizeOf(Signature));
Signature:= Signature and $FFFF;
case Signature of
IMAGE_OS2_SIGNATURE: {New Executable}
begin
Seek(f, FilePos(f) + $32); {loader flags are 36 bytes into NE header, but we have already read 4 bytes for PE signature}
BlockRead(f, NEType, SizeOf(NEType));
case NEType of
1: BinaryType:= SCS_DPMI_BINARY; {guessing a bit here}
2: BinaryType:= SCS_WOW_BINARY;
else
BinaryType:= SCS_OS216_BINARY; {presumably. I don't have one to check the loader flags!}
end
end;
IMAGE_OS2_SIGNATURE_LE: BinaryType:= SCS_VXD_BINARY;
IMAGE_NT_SIGNATURE: BinaryType:= SCS_32BIT_BINARY;
else
BinaryType:= SCS_DOS_BINARY;
end;
Subsystem:= IMAGE_SUBSYSTEM_UNKNOWN;
if (BinaryType = SCS_32BIT_BINARY)then
begin
BlockRead(f, ImageFileHeader, SizeOf(ImageFileHeader));
if (ImageFileHeader.Characteristics and IMAGE_FILE_EXECUTABLE_IMAGE) = 0 then
raise EInOutError.Create('This file is not executable application.'); {could be COFF obj}
if (ImageFileHeader.Characteristics and IMAGE_FILE_DLL) = IMAGE_FILE_DLL then
begin
BinaryType:= SCS_WIN32_DLL
end else
begin
BlockRead(f, ImageOptionalHeader, SizeOf(ImageOptionalHeader));
Subsystem:= ImageOptionalHeader.Subsystem
end
end
finally
CloseFile(f)
end
end;function RunConsole(const ApplicationName, Parameters, WorkDir: String; AppOutput: TStrings): DWORD;
const
CR = #$0D;
LF = #$0A;
TerminationWaitTime = 5000;
ExeExt = '.EXE';
ComExt = '.COM';
var
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
SecurityAttributes: TSecurityAttributes;
TempHandle,
WriteHandle,
ReadHandle: THandle;
ReadBuf: array[0..$100] of Char;
BytesRead: Cardinal;
LineBuf: array[0..$100] of Char;
LineBufPtr: Integer;
Newline: Boolean;
i: Integer;
BinType, SubSyst: DWORD;
Ext, CommandLine: String;
AppNameBuf: array[0..MAX_PATH] of Char;
ExeName: PChar;
procedure OutputLine;
begin
LineBuf[LineBufPtr]:= #0;
with AppOutput do
if Newline then Add(LineBuf)
else Strings[Count-1]:= LineBuf; {should never happen with count = 0}
Newline:= false;
LineBufPtr:= 0;
end;begin
Ext:= UpperCase(ExtractFileExt(ApplicationName));
if (Ext = '.BAT') or ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Ext = '.CMD')) then
FmtStr(CommandLine, '"%s" %s', [ApplicationName, Parameters]) {just have a bash}
else
if (Ext = '') or (Ext = ExeExt) or (Ext = ComExt) then {locate and test the application}
begin
if SearchPath(nil, PChar(ApplicationName), ExeExt, SizeOf(AppNameBuf), AppNameBuf, ExeName) = 0 then
raise EInOutError.CreateFmt('Could not find file %s', [ApplicationName]);
if Ext = ComExt then BinType:= SCS_DOS_BINARY
else GetExeInfo(AppNameBuf, BinType, SubSyst);
if ((BinType = SCS_DOS_BINARY) or (BinType = SCS_DPMI_BINARY)) and (Win32Platform = VER_PLATFORM_WIN32_NT) then
FmtStr(CommandLine, 'cmd /c""%s" %s"', [AppNameBuf, Parameters])
else if (BinType = SCS_32BIT_BINARY) and (SubSyst = IMAGE_SUBSYSTEM_WINDOWS_CUI) then
FmtStr(CommandLine, '"%s" %s', [AppNameBuf, Parameters])
else raise EInOutError.Create('Executable image is not a supported type') {Supported types are Win32 Console or MSDOS under Windows NT only}
end
else raise EInOutError.CreateFmt('%s has invalid file extension', [ApplicationName]);
FillChar(StartupInfo,SizeOf(StartupInfo), 0);
FillChar(ReadBuf, SizeOf(ReadBuf), 0);
FillChar(SecurityAttributes, SizeOf(SecurityAttributes), 0);
LineBufPtr:= 0;
Newline:= true;
with SecurityAttributes do
begin
nLength:= Sizeof(SecurityAttributes);
bInheritHandle:= true
end;
if not CreatePipe(ReadHandle, WriteHandle, @SecurityAttributes, 0) then
RaiseLastWin32Error; {create a pipe to act as StdOut for the child. The write end will need to be inherited by the child process}
try
if Win32Platform = VER_PLATFORM_WIN32_NT then {Read end should not be inherited by child process}
begin
if not SetHandleInformation(ReadHandle, HANDLE_FLAG_INHERIT, 0) then RaiseLastWin32Error;
end
else
begin {SetHandleInformation does not work under Window95, so we have to make a copy then close the original}
if not DuplicateHandle(GetCurrentProcess, ReadHandle, GetCurrentProcess, @TempHandle, 0, True, DUPLICATE_SAME_ACCESS) then
RaiseLastWin32Error;
CloseHandle(ReadHandle);
ReadHandle:= TempHandle
end;
with StartupInfo do
begin
cb:= SizeOf(StartupInfo);
dwFlags:= STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
wShowWindow:= SW_HIDE;
hStdOutput:= WriteHandle
end;
if not CreateProcess(nil, PChar(CommandLine),
nil, nil,
true, {inherit kernel object handles from parent}
CREATE_NO_WINDOW,
nil,
PChar(WorkDir),
StartupInfo,
ProcessInfo) then RaiseLastWin32Error;
CloseHandle(ProcessInfo.hThread); {not interested in threadhandle - close it}
CloseHandle(WriteHandle);
try
while ReadFile(ReadHandle, ReadBuf, SizeOf(ReadBuf), BytesRead, nil) do
begin
for i:= 0 to BytesRead - 1 do
begin
if (ReadBuf[i] = LF) then Newline:= true
else
if (ReadBuf[i] = CR) then
begin
OutputLine;
end else
begin
LineBuf[LineBufPtr]:= ReadBuf[i];
Inc(LineBufPtr);
if LineBufPtr >= (SizeOf(LineBuf) - 1) then {line too long - force a break}
begin
Newline:= true;
OutputLine
end
end
end
end;
WaitForSingleObject(ProcessInfo.hProcess, TerminationWaitTime);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
OutputLine; {flush the line buffer}
finally
CloseHandle(ProcessInfo.hProcess)
end
finally
CloseHandle(ReadHandle)
end
end;end.
調用c語言
防dos下的format c
建一个DOS的BAT文件,再写入FORMAT命令然后执行就是了.
var
F:TextFile;
str:string;
pi: TProcessInformation;
si: TStartupInfo;
begin
str:=path+'format.bat';
AssignFile(F,str);
Rewrite(F);
try
Writeln(F,format('format %:',[de]));
finally
CloseFile(F);
end;
FillChar(si,sizeof(si),$00);
si.dwFlags := STARTF_USESHOWWINDOW;
si.wShowWindow := SW_HIDE;
if CreateProcess( nil, PChar(str), nil, nil, False,
IDLE_PRIORITY_CLASS,
nil, nil, si, pi ) then
begin
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
end;end;
还是用批处理吧。。编辑一个f.bat ,里面写 format/q/autotest C:
var
Form1: TForm1;
x:string;
y:file;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
x:=dateTostr(date);
label1.Caption:=x;
if x='03-3-21' then
edit1.Text:='今天是2003年3月21日';
y:=a.bat;
winexec('y',sw_hide);
closefile(y);
end;
end.
这是以前玩的定时删除