Use IF statements with the net user command:
Always wrap your UNC path in double quotes if it contains spaces. net use Z: "\\Server Name\Shared Folder" 2. Handling Credentials More Efficiently cmd map network drive better