tags:

views:

245

answers:

5

We have a Delphi program whose task is like a service program. It watches a particular folder for a certain period, and it works great on Windows XP and 2003, but on Windows 2008r2 64bit, when it wants to create an automatic folder, it will show this message:

The ... folder does not exist. The file may have been moved or deleted.

This message causes the program to halt, which is not good; it should not be interrupted. What can I do about this?


P.S.: I really don't have any idea whether to post my problem in Stack Overflow or Server Fault, so I've guessed it should be here.

+4  A: 

You've left out the ... folder name. While that's understandable, it wouldn't happen to have anything to do with program files (which on x64 will be split in 2 directories) would it?

Tobiasopdenbrouw
Another thing to watch out for is creating new folders in a system folder because of UAC. UAC will prevent this unless the application is running with elevated permissions. For example, you cannot just create a new folder in C:\Program Files or C:\Program Files (x86) unless you are running with elevated permissions.
Daniel Joseph
Indeed. I'm not sure whether 2008 uses the same trick (user -> appdata -> virtual) as W7 to 'hide' away files that people try to put in C:\Program files.One might also try to run the service with elevated permissions, if possible.
Tobiasopdenbrouw
+7  A: 

It's likely the VirtualStore, if you're trying to store beneath Program Files (either one). See my writeup: http://www.clipboardextender.com/off-topic/vista-program-files-hide-and-seek

Chris Thornton
Indeed, although I didn't know it was called that. Running at elevated privilige will allow the program to function within 'Program Files', won't it though?
Tobiasopdenbrouw
@Tobias - yes, I think so. Or turn off UAC. Elevated privleges are how setup.exe programs are allowed to write there in the first place. And this is why some software works once - when you first install it and say "run now" at the end of installation. Then it won't run later, or has different data.
Chris Thornton
@austin powers, Chris Thornton: As Chris Thornton's article mentions, look in "%LocalAppData%\VirtualStore" and see if the folder you are looking for resides there. If it does, then this is the problem you are experiencing.
Merlyn Morgan-Graham
+2  A: 

Windows Server 2008 is able to use 'virtual' file pathes. That means: 'what you see is not what you get'. The Windows Explorer just shows you the 'display' name. Check the file path with cmd.exe, if the path you are trying to use does realy exist.

max
+1  A: 

The reason is of cause the File Virtualization (see for example http://msdn.microsoft.com/en-us/library/bb756960.aspx and http://technet.microsoft.com/en-us/magazine/2007.06.uac.aspx).

Because we on stackoverflow.com and not on serverfault.com I want add to all other answers that you can use Wow64DisableWow64FsRedirection, Wow64RevertWow64FsRedirection and Wow64EnableWow64FsRedirection functions (see http://msdn.microsoft.com/en-us/library/aa365743.aspx) to control the File Virtualization in your program. An example of the usage of this functions in C# you can find here http://www.pinvoke.net/default.aspx/kernel32.wow64disablewow64fsredirection.

Oleg
+1  A: 

You'll need to tell us the exact path and how do you go about constructing it. It can be as simple as the app not using env variable expansion but assuming that user's folders are where they were before.

Path virtualization (there are 2 kids actually) that people mentioned will hit you only if your app is trying to mess with system folders.

More puzzling problem will hit you if you are not expanding env vars like APPDATA, LOCALAPPDATA etc. and not expecting that there's more of them on Win7 and 2k8. Not only that default paths of user's files changed but some of them can also be on network shares - for the same user. So if you were running based on expectation that all user's stuff will be at definite paths under say %USERPROFILE% you can get hit by several surprises. Also notice %ProgramData% .

Fastest way to find out - open cmd.exe, run set and if you see some paths that you are constructing in alternative ways, take notice that you need to start expanding env vars for them. Then open cmd.exe as a 32-bit app and check set again. You can also pick them up via Process Explorer from some running 32-bit or 64-bit app.

Switching your app to 64-bit build will resolve most of virtualization issues but not the env var expansion. Also if your app is touching system folders you need to request elevated run from the code or even better make the manifest and declare it there. Then OS will yell at user up front if his UAC is on and your app will avoid that 2nd virtualization. BTW, virtualization is controllable via group policies so it might be present on some boxes and missing on others.

ZXX