Reputation: 11
I am trying to make a copy of this directory from my program and when I try it tells me that, "the path does not exist".
Upvotes: 0
Views: 968
Reputation: 18320
If your application is a 32-bit app on a 64-bit system then you're experiencing what's called File system redirection.
Because 32-bit apps cannot load 64-bit dlls, and 64-bit apps cannot load 32-bit dlls, a 64-bit system has two system folders:
System32
- the 64-bit version with 64-bit dlls, and:
SysWOW64
- the 32-bit version with 32-bit dlls.
The File System Redirector automatically redirects %SystemRoot%\System32
to %SystemRoot%\SysWOW64
for all 32-bit apps trying to access the System32
folder, so the reason you cannot copy the directory is because it doesn't exist in the SysWOW64
folder.
There are three ways you can overcome this. I've listed them in the order where the first is the most recommended, and the last is the least recommended:
Use the SysNative
folder instead.
Instead of C:\Windows\System32
you can use C:\Windows\SysNative
which will take 32-bit apps to the original System32
folder.
If Environment.Is64BitOperatingSystem = True AndAlso Environment.Is64Process = False Then 'Is this a 32-bit app in a 64-bit system?
My.Computer.FileSystem.CopyDirectory("C:\Windows\SysNative\spp\store", "your destination path here")
Else 'This is either a 64-bit app in a 64-bit system, or a 32-bit app in a 32-bit system.
My.Computer.FileSystem.CopyDirectory("C:\Windows\System32\spp\store", "your destination path here")
End If
Compile your app in 64-bit mode or AnyCPU
.
Disable File System Redirection by P/Invoking the Wow64DisableWow64FsRedirection()
function. (I really do not recommend this as things might break if your app tries to load dlls from the system directory).
Upvotes: 2
Reputation: 84
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Computer.FileSystem.CopyDirectory("C:\Windows\System32\spp\store", "D:\store", True)
End Sub
Upvotes: -1