Delphi create dir under system32

612 views Asked by At

i tried to create dir under system32 folder but no exception shows or errors

note i run it as administrator

//1
  if not TDirectory.Exists('C:\Windows\System32\oobe\info') then
  TDirectory.CreateDirectory('C:\Windows\System32\oobe\info');
//2
  if not DirectoryExists('C:\Windows\System32\oobe\info') then
  CreateDir('C:\Windows\System32\oobe\info');
//3
  try
    ForceDirectories('C:\Windows\System32\oobe\info');
  except
   ShowMessage('cant create it');
  end;
1

There are 1 answers

0
David Heffernan On BEST ANSWER

You have a 32 bit process on 64 bit Windows. Hence you are subject to the file system redirector. This redirects system32 to SysWOW64 which is the 32 system directory. You'll find your directory there.

You have these options:

  1. Use the sysnative alias to access the 64 bit system directory.
  2. Run the code in a 64 bit process.
  3. Disable file system redirection.

The final option here is fraught with danger and is not to be recommended.

The documentation gives the details: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187.aspx

Of course, it's plausible that writing to the 32 bit system directory is exactly what you want to be doing and you have not yet realised that.

And finally, it would be remiss of me not to point out that the system belongs to the system and should not be modified by applications.