I have a file on windows 7 and what I want to do is once someone tries to open this file I want a window to appear asking for the username and password (which is not related to the windows credentials, these credentials would be stored somewhere in another file) and depending on the username and password entered a file will be copied from one location to another. So for example, if userA logged in with passUserA then fileA will be copied to a destination folder, if userB logged in with passUserB then fileB will be the one copied to a destination folder. Any thoughts please how this can be done?

  • can you provide more details as to why you would want or need this behaviour? – Jerome Indefenzo Oct 19 '16 at 22:37
  • @JeromeIndefenzo because depending on the user-credentials I want a file to be copied in a specific location before the application runs. – Tak Oct 19 '16 at 22:39
  • I mean, what are these files you are copying and where are you copying them to? Who will be using the user credentials and what will they be accessing? What's the file that should supposedly trigger the login prompt? – Jerome Indefenzo Oct 19 '16 at 22:42
  • The behaviour you're asking is pretty hacky. There has to be a better way to get the functionality you want without having to go through all sorts of things manually (watching for a file opening, managing user credentials, copying files, etc). – Jerome Indefenzo Oct 19 '16 at 22:44
  • @JeromeIndefenzo so I have a shortcut of a .exe of an application, when this .exe file runs it loads a start-up file saved in a certain location which is loaded in the application. So I have two start-up files and depending on the user credentials one of these start-up files will be copied to the start-up file location so when I double click on the shortcut or the exe itself I want to have this username and password input and depending on them the correct start-up file will be loaded then the application will be opened. – Tak Oct 19 '16 at 23:22

Create a script that does the neccessary setup and call that script using the shortcut instead of the actual executable. The script will start the executable. This will be easy to tamper with so it doesn't really provide any security. You will have to use Set-ExecutionPolicy to allow the execution of PowerShell scripts.

The script itself (saved as a .ps1 file) could look like this:

$credentials = Get-Credential

if ($credentials.Username -eq 'DOMAIN\User') {
    Copy-Item fromhere\startup1 tothere
} elseif {
    Copy-Item fromhere\startup2 tothere


This script would NOT actually verify the credentials, just that the right username was chosen. You could do any number of actions this way and the user would still be able to start the executable directly if she/he wanted to.

| improve this answer | |
  • is it possible to make this script protected so no one can edit it or see the username and password? – Tak Oct 24 '16 at 0:44
  • You can't hide the username as password if you store it in that file. What you could do is use a hash instead. That would make it a bit harder. For protection you could remove the write/change permissions for normal users from the script. – Seth Oct 25 '16 at 5:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.