disable windows 7 dialogs

Hello
I am using Delphi 7 and want some code that will
1: Disable the DELETE FILE Confirmation Dialog in WINDOWS 7
and Enable it again.

2: Disable the File Overwrite existing file  Confirmation Dialog in WINDOWS 7
and enable it again.
many thanks Kim
kimlingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
Don't think I can help, but to clarify, are you looking to have this adjustment for handling within your application?
Or on the system I,e. Is using vb, powershell or cmd tools not an option To?
arnoldCommented:
You can make a registry change to disable the confirmation or enable it.
jimyXCommented:
Hi Kim,
1: Disable the DELETE FILE Confirmation Dialog in WINDOWS 7
and Enable it again.


There is a registry key to change, but it won't take immediate effect, you need to, at least, log off first.
Also your application must start with privileged user to be able to set the key.

uses Registry;

/// 0=no msg / 1=show msg
procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
begin
  Reg:= TRegistry.Create;
  try
    Reg.RootKey:= HKEY_CURRENT_USER;
    Reg.Access:= KEY_WRITE;
    Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\', True);
    Reg.WriteInteger('ConfirmFileDelete', 1);   //show msg
  Finally
    Reg.CloseKey();
    Reg.Free;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  Reg: TRegistry;
begin
  Reg:= TRegistry.Create;
  try
    Reg.RootKey:= HKEY_CURRENT_USER;
    Reg.Access:= KEY_WRITE;
    Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\', True);
    Reg.WriteInteger('ConfirmFileDelete', 0);  //no msg
  Finally
    Reg.CloseKey();
    Reg.Free;
  end;
end;

Open in new window


Alternatively, you can use Group Policy to set that, without restart but still you need privileged user to execute.
Just start new application and drop two buttons. Double click each button to generate the OnClick event, then replacy the entire unit with the following code:
unit Unit1;

{Source}
//http://www.swissdelphicenter.ch/en/showcode.php?id=2440

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses ComObj, ActiveX, Registry;

{$R *.dfm}

const
  GPO_OPEN_LOAD_REGISTRY = $00000001;  // Load the registry files
  {$EXTERNALSYM GPO_OPEN_LOAD_REGISTRY}
  GPO_OPEN_READ_ONLY = $00000002;  // Open the GPO as read only

  GPO_SECTION_ROOT = 0;  // Root
  {$EXTERNALSYM GPO_SECTION_ROOT}
  GPO_SECTION_USER = 1;  // User
  {$EXTERNALSYM GPO_SECTION_USER}
  GPO_SECTION_MACHINE = 2;  // Machine

const
  IID_GPO: TGUID = '{EA502722-A23D-11d1-A7D3-0000F87571E3}';

type
  HPROPSHEETPAGE = Pointer;
  {$EXTERNALSYM HPROPSHEETPAGE}
  PHPROPSHEETPAGE = ^HPROPSHEETPAGE;
  LPOLESTR        = POleStr;
  _GROUP_POLICY_OBJECT_TYPE = (GPOTypeLocal,
    // GPO on the local machine
    GPOTypeRemote,                        // GPO on a remote machine
    GPOTypeDS);                           // GPO in the Active Directory
  {$EXTERNALSYM _GROUP_POLICY_OBJECT_TYPE}
  GROUP_POLICY_OBJECT_TYPE = _GROUP_POLICY_OBJECT_TYPE;

  IGroupPolicyObject = interface(IUnknown)
    ['{EA502723-A23D-11d1-A7D3-0000F87571E3}']

    function New(pszDomainName, pszDisplayName: LPOLESTR; dwFlags: DWORD): HRESULT;
      stdcall;
    function OpenDSGPO(pszPath: LPOLESTR; dwFlags: DWORD): HRESULT; stdcall;
    function OpenLocalMachineGPO(dwFlags: DWORD): HRESULT; stdcall;
    function OpenRemoteMachineGPO(pszComputerName: LPOLESTR; dwFlags: DWORD): HRESULT;
      stdcall;
    function Save(bMachine, bAdd: BOOL; const pGuidExtension, pGuid: TGUID): HRESULT;
      stdcall;
    function Delete: HRESULT; stdcall;
    function GetName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
    function GetDisplayName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
    function SetDisplayName(pszName: LPOLESTR): HRESULT; stdcall;
    function GetPath(pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT; stdcall;
    function GetDSPath(dwSection: DWORD; pszPath: LPOLESTR; cchMaxPath: Integer): HRESULT;
      stdcall;
    function GetFileSysPath(dwSection: DWORD; pszPath: LPOLESTR;
      cchMaxPath: Integer): HRESULT; stdcall;

    //
    // Returns a registry key handle for the requested section.  The returned
    // key is the root of the registry, not the Policies subkey.  To set / read
    // a value in the Policies subkey, you will need to call RegOpenKeyEx to
    // open Software\Policies subkey first.
    //
    // The handle has been opened with ALL ACCESS rights.  Call RegCloseKey
    // on the handle when finished.
    //
    // If the GPO was loaded / created without the registry being loaded
    // this method will return E_FAIL.
    //
    // dwSection is either GPO_SECTION_USER or GPO_SECTION_MACHINE
    // hKey contains the registry key on return
    //

    function GetRegistryKey(dwSection: DWORD; var hKey: HKEY): HRESULT; stdcall;
    function GetOptions(var dwOptions: DWORD): HRESULT; stdcall;
    function SetOptions(dwOptions, dwMask: DWORD): HRESULT; stdcall;
    function GetType(var gpoType: GROUP_POLICY_OBJECT_TYPE): HRESULT; stdcall;
    function GetMachineName(pszName: LPOLESTR; cchMaxLength: Integer): HRESULT; stdcall;
    function GetPropertySheetPages(var hPages: PHPROPSHEETPAGE;
      var uPageCount: UINT): HRESULT; stdcall;
  end;

const
  REGISTRY_EXTENSION_GUID: TGUID = (D1: $35378EAC; D2: $683F; D3: $11D2;
    D4: ($A8, $9A, $00, $C0, $4F, $BB, $CF, $A2));
  CLSID_GPESnapIn: TGUID = (D1: $8fc0b734; D2: $a0e1; D3: $11d1;
    D4: ($a7, $d3, $0, $0, $f8, $75, $71, $e3));


/// 0=no msg / 1=show msg

procedure TForm1.Button1Click(Sender: TObject);
var
  GPO: IGroupPolicyObject;
  Key: HKEY;
begin
  GPO := CreateComObject(IID_GPO) as IGroupPolicyObject;
  if GPO.OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY) = S_OK then
  begin
    if GPO.GetRegistryKey(GPO_SECTION_USER, Key) = S_OK then
      with TRegistry.Create do
        try
          RootKey := HKEY_CURRENT_USER;
          if OpenKey('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True) then
          begin
            WriteInteger('ConfirmFileDelete', 1);  // show msg
          end;

          RootKey := Key;
          if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True) then
          begin
            WriteInteger('ConfirmFileDelete', 1);  // show msg
          end;
          RegCloseKey(Key);
          GPO.Save(False, True, REGISTRY_EXTENSION_GUID, CLSID_GPESnapIn);
        finally
          Free;
        end;
    SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, Integer(PChar('Polices')), 0);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  GPO: IGroupPolicyObject;
  Key: HKEY;
begin
  GPO := CreateComObject(IID_GPO) as IGroupPolicyObject;
  if GPO.OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY) = S_OK then
  begin
    if GPO.GetRegistryKey(GPO_SECTION_USER, Key) = S_OK then
      with TRegistry.Create do
        try
          RootKey := HKEY_CURRENT_USER;
          if OpenKey('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True) then
          begin
            WriteInteger('ConfirmFileDelete', 0);  // no msg
          end;

          RootKey := Key;
          if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer', True) then
          begin
            WriteInteger('ConfirmFileDelete', 0);  // no msg
          end;
          RegCloseKey(Key);
          GPO.Save(False, True, REGISTRY_EXTENSION_GUID, CLSID_GPESnapIn);
        finally
          Free;
        end;
    SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, Integer(PChar('Polices')), 0);
  end;
end;

end.

Open in new window


2: Disable the File Overwrite existing file  Confirmation Dialog in WINDOWS 7
and enable it again.


If you copy and paste through the Windows Explorer, not sure if this one is possible. Unless using third-party replacement.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sinisa VukSoftware architectCommented:
If you use dialog component set:
SaveDialog1.Options := SaveDialog1.Options + [ofOverwritePrompt];  //for overwrite prompt

SaveDialog1.Options := SaveDialog1.Options - [ofOverwritePrompt]; //for avoid prompt

Open in new window


look for interesting article from Zarko about avoiding windows shell operation interface:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.