Use "NET USE" Windows command in batch script without a clear text password

Last Modified: Fri, 24 Apr 2009 17:23:26 +0000 ; Created: Fri, 24 Apr 2009 17:23:26 +0000

I had some batch scripts that needed to access remote shares. In order to not have to leave the clear text password in the batch files you must do the following:
  1. Run batch script under user with same username and password as a user on the remote system
    • Ex: Machine A user "MachineA\sameUsername" and Machine B user "MachineB\sameUsername"
    • Ex: Machine A user "MY-DOMAIN\sameUsername" and "DIFF-DOMAIN_BUT_SAME_NAME_PASSWORD\sameUsername
  2. Execute the NET USE command without the password specified
    • Ex: NET USE \\ /USER:DIFF-DOMAIN\sameUsername

This works because even though you have different domains or machine names Windows will still try the same password if both machines have users with the same usernames. I used this to map resources on a separate domain that didn't have a domain trust to the first domain.