www.rodneybeede.com "I would love to change the world, but they won't give me the source code" - unknown

Use "NET USE" Windows command in batch script without a clear text password - Last Modified 2009-04-24 17:23 UTC - Created 2009-04-24 17:23 UTC

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.