I have a simple updater program that copies files from a company server to the user’s machine.
For most people on the internal LAN this is no problem, but some staff access this from LANs where they are not automatically authenticated with the server in question.
Normally an attempt to access this server (e.g. via Explorer) would simply throw up a user credentials dialog asking the user to provide a login that can access the shared directory.
In my Winforms application I simply use operations like File.Copy to move the files.
How can my application cause Windows to prompt for authentication rather than just throwing an exception?
I’m willing to do a fair bit of work myself but what I was really hoping was that Windows provided a way for this to happen.
Otherwise I’m considering just attempting access and showing an error message instructing the user to authenticate themselves using explorer.
Are there any other nice ways to deal with this problem without reinventing the wheel for a 50 line program? 🙂
you could use shell API to make that happen (same API Windows Explorer is based upon) – instead
File.Copyyou would pinvokeSHFileOperation.