I am writing a very basic batch script to run an MD5 hash. I need it to ask the user for an output directory, then ask for an IP address output, then map a drive letter to this output. I can get it to ask, but it doesn't output the file to the chosen directory. It puts it in the local directory the script was run from. It also won't map a drive letter to it.Can anyone help me fix this? The MD5 hash should be sent to the user chosen directory.

REM This section prompts user for output location 

set /p direct="Enter the directory output location: "

dir %1 %direct% > investigation.txt 


set /p direct="Enter the IP output location: "

dir %1 > investigation.txt 

REM Map share 
@echo Map Share
@echo off 
net use z: \\%1

REM This section appends the date and time of the investigation. 
@Echo Date and Time 
@Echo off
date /T >> investigation.txt && time /T >> INVESTIGATION.TXT 

REM This step creates the MD5 hash 

@echo MD5 VALUE
@echo off 
MD5DEEP investigation.txt > Hash.txt


REM This step creates the SHA1 hash
@echo off 
SHA1DEEP investigation.txt >> Hash.txt  

Some explanations

How it Works

set /p Folder=Enter folder's path: 

set /p IP=Enter computer's IP: 

Once you have them set with %Folder% and %IP% values, you can map the remote path to a letter

net use x: "\\%IP%\%Folder%"

Here it maps to the letter x creating a virtual X drive, always double quote because the folder may contain special characters spaces.

Main Issue

dir %1 > investigation.txt

Plain investigation.txt without the path specified like c:\SomeFolder\investigation.txt would create the file in the current directory, that is within the folder the script ran from.

So, you should specify the directory as well, and not just file's name in order to save the output to a file in the directory you want it to be saved in.

Moreover, %1 is first argument, that is the value of the first parameter passed to file, parameter is what you type after its name, that is after calling the file, eg mybatchfile.bat parameter1 parameter2's values would be %1 and %2 respectively inside the batch file.

So I think, the script is wrong, and you should learn to understand what the contents do, and correct some parts of it.


  • IP should be in format, that's four numbers, three dots, in order it to work
  • You can use hostname, that is the name of the computer, instead of its address, that's IP
  • To learn your computer's name: echo %ComputerName%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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