How to copy a file from local hard drive to a mapped drive with password using cmd?

1.9k Views Asked by At

I am aware of the fact that this could be done more easily with copy and paste, but the point here is to use VBA to automate the process so some other people can just click a button and the file will be copied automatically. I have tried to use copy command under cmd but failed, as this does not invoke the password prompt windows so no way to access the hard drive. Is there any other way to tackle this issue? It does not matter if the user name and password cannot be embedded as part of the command. If the command can manage to pop up the window for user name and password entries that is also acceptable. Any suggestions? Thanks.

1

There are 1 best solutions below

1
On

you can use vba to prompt for username and password, or store them in the file (whichever is applicable to your needs)

the command to map a drive that has a username and password is

NET USE G: \\server\path password /user:username

and

NET USE G: /delete

when you are finished with a mapped drive, you can use object.Copy destination[, overwrite] to copy the file, or SaveAs if you want a copy of the current file