How to output to a directory and map a share drive

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stubby
Posts: 1
Joined: 24 Oct 2016 18:43

How to output to a directory and map a share drive

#1 Post by stubby » 24 Oct 2016 18:48

I am writing a very basic batch script that needs to accomplish the following:

a. Prompt the user for an output location (IP address and shared folder name) and then map a drive letter to that location.
b. The batch file should write a file with the output of all the commands run to the location specified in step ‘a’ above.
c. The batch file should also write to the file the time and date when the batch file was started and completed.
d. The batch file should also write a separate file to the location in step ‘a’ with the md5 and sha1 hashes for the command output file created above.

While my script prompts the user for a directory and IP, the file that is created just goes to the local directory that the batch file was run from. It also does not map the share. I know just enough to be dangerous and no one elsewhere has been willing to help me. Here is what I currently have:

Code: Select all

@ECHO OFF
pause
REM This section prompts user for output location

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

dir %1 %direct% > investigation.txt
pause

REM

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

dir %1 > investigation.txt
pause

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

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
pause

REM This step creates the MD5 hash


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


pause

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

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: How to output to a directory and map a share drive

#2 Post by Squashman » 25 Oct 2016 06:44

I see you did not use my suggestion from your StackOverFlow question.
http://stackoverflow.com/questions/4022 ... ive-letter

Cornbeetle
Posts: 31
Joined: 23 Nov 2015 09:34

Re: How to output to a directory and map a share drive

#3 Post by Cornbeetle » 25 Oct 2016 08:13

Your main issue here is your use of "%1".

Read up on its usage here: http://ss64.com/nt/syntax-args.html

You need to use the "direct" variable and not "%1" see how I changed it below. Also, you cannot run a DIR command against an IP address.

Code: Select all

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

dir %direct% > investigation.txt


Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: How to output to a directory and map a share drive

#4 Post by Compo » 25 Oct 2016 08:25

Your task is illogical.

If you write to the file, (start date time, directory and ip), then hash it, when you write to the file again, (end date time), the hashes are no longer valid.
Example:

Code: Select all

@ECHO OFF
SET "SDT=%DATE% %TIME%"
CLS
SET/P FLD="Enter the directory output location: "
ECHO=
SET/P IPA="Enter the ip output location: "
NET USE Z: \\%IP%\%FLD%
>Z:\Investigation.txt (ECHO=%SDT%
   ECHO=%FLD%
   ECHO=%IPA%)
>HASH.TXT (START MD5DEEP Z:\INVESTIGATION.TXT
   START SHA1DEEP Z:\INVESTIGATION.TXT)
>>Z:\Investigation.txt ECHO=%DATE% %TIME%

Post Reply