Hack Forums
Batch to save command in same directory - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Computing Lounge (https://hackforums.net/forumdisplay.php?fid=8)
+---- Thread: Batch to save command in same directory (/showthread.php?tid=5206509)



Batch to save command in same directory - FULLAUTO - Mar 17, 2016

Hello Guys, great Forum!

I have a (i guess) easy question which is pretty hard for me to solve.

I want to use the Batch command "TASKLIST" to save the Tasklist to a USB Drive.

the Problem is:

If I use the command -> tasklist>C:\list.txt it will save the Tasklist to C:\list.txt

but i want to use the Batch on a USB drive, and if the guy puts in the USB drive (He is a little dumb) i want the batchfile to be saved automatically to the USB drive, but i dont know which Letter the USB drive get (i.e. E: or F: or D:)

how can i force the Batchfile on the USB to save the list.txt directly on the USB? Is there any possibility?


* - Freebooter - Mar 17, 2016

If the batch script run from USB drive then below command saves the text file to USB drive and folder batch script executed from.



Code
@Echo Off & Cls
Tasklist > list.txt

Below command ask you to enter the USB drive letter and saves the text fie to USB drive

Code
@Echo Off
:Start
Cls
@Echo.
@Echo.
@Echo Please Enter the USB Drive Letter. (X) & Set /p DriveLetter=^>
If "%DriveLetter%"=="" Goto :Start
Tasklist > %DriveLetter:~0,1%:\List.txt



* - FULLAUTO - Mar 18, 2016

(Mar 17, 2016 06:33 PM)Freebooter Wrote:  If the batch script run from USB drive then below command saves the text file to USB drive and folder batch script executed from.



Code
@Echo Off & Cls
Tasklist > list.txt

Below command ask you to enter the USB drive letter and saves the text fie to USB drive

unfortunately it dont save anything, the command seems to need a directory and thats the problem (tested WIN10)


* - Freebooter - Mar 18, 2016

(Mar 18, 2016 01:30 AM)FULLAUTO Wrote:  unfortunately it dont save anything, the command seems to need a directory and thats the problem (tested WIN10)
Copy the batch file to USB drive and execute the batch file from USB drive. Batch script works if you follow my instructions. I also tested on Windows 10 and batch script will run on almost all version of Windows O/S. I'm sorry i should have ask earlier do you know how to create a batch file? One second i just notice one command i should have add to batch script try below commands.

Code
@Echo Off & Cls
Cd %~dp0
Tasklist > List.txt



* - FULLAUTO - Mar 18, 2016

(Mar 18, 2016 02:17 AM)Freebooter Wrote:  Copy the batch file to USB drive and execute the batch file from USB drive. Batch script works if you follow my instructions. I also tested on Windows 10 and batch script will run on almost all version of Windows O/S. I'm sorry i should have ask earlier do you know how to create a batch file? One second i just notice one command i should have add to batch script try below commands.

Code
@Echo Off & Cls
Cd %~dp0
Tasklist > List.txt


I know how to use batches and bitches

your second command works fine and as i want it to work... thanks for your time and the very simple solution 🤝🤝🤝🤝


* - Freebooter - Mar 18, 2016

(Mar 18, 2016 02:38 AM)FULLAUTO Wrote:  I know how to use batches and bitches

your second command works fine and as i want it to work... thanks for your time and the very simple solution 🤝🤝🤝🤝
You are very welcome, happy to help you out.