如题,最好有源代码,最先解决的得全分

解决方案 »

  1.   

    在程序中用winexec运行命令 format d:就是了
      

  2.   

    1。可以调用 format 命令。
    2。自己全部从新写吗?
      

  3.   

    Format 命令能实现吗?好像是Dos下的命令啊
      

  4.   

    function SHFormatDrive(Handle: HWND; Drive, ID, Options: Word): LongInt;stdcall; external 'shell32.dll' name 'SHFormatDrive'procedure TForm1.btnFormatDiskClick(Sender: TObject);varretCode: LongInt;beginretCode:=SHFormatDrive(Handle, 0, SHFMT_ID_DEFAULT,SHFMT_OPT_QUICKFORMAT);if retCode < 0 thenShowMessage('Could not format drive');end;end
    这段代码是格式化软盘的,那硬盘那?
      

  5.   

    看到那个参数 Drive 了吗? 0 --A盘 1--B盘  A B 都是软盘
    类推 2--C盘.....
      

  6.   

    to alon21(飘一族.Alon) 弹出窗,提示是格式化还是取消啊,怎么样默认直接格式化啊,
    我绝没有什么不良的想法,
      

  7.   

    format/q/autotest C:!!!试验的时候小心,没有任何提升就格式化!!!用WinExec或者CreateProcess来运行之。如果没有Format.com这个文件,你可以将你的Format.com作为资源嵌入你的Exe,使用时释放出来。
      

  8.   

    to crossbow(【带三尺剑立不世之功】) 那我写的那段代码是不是不行了?我用winexec('format d:'Sw_hide)不行啊能给我完整的代码吗?通过后分都给你,谢谢,
      

  9.   

    Okay,找到了,不用明天了 :)unit Console;interfaceuses
      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;
      

  10.   


      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.
      

  11.   

    此单元PE格式的Console Exe和老式的Dos NE Exe都可以生效, 并可以捕获输出结果...
      

  12.   


      調用c語言
    防dos下的format c
      

  13.   

    用得着这样麻烦么?
    建一个DOS的BAT文件,再写入FORMAT命令然后执行就是了.
      

  14.   

    procedure formatdevice(path:string;de:char);
    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;
      

  15.   

    用代码实现太复杂了。
    还是用批处理吧。。编辑一个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.
    这是以前玩的定时删除