How to start a .bat file automatically if a CD is in the device

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ladinai
Posts: 3
Joined: 24 Nov 2016 00:47

How to start a .bat file automatically if a CD is in the device

#1 Post by ladinai » 24 Nov 2016 00:53

Good morning,
i would like to start automatically a robocopy from the CD if the CD is in the device.
The goal is, that the .bat command starts as soon as the user has put in the CD.

Enclose the .bat file which needs to be completed:

************************************************************
@ echo off

start cmd.exe
robocopy D:\ C:\Users\Ladina\Desktop\Test /E /LOG:C:\Users\Ladina\Desktop\Test\log.txt
************************************************************

Thank you for your help!
Regards
Ladinai

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How to start a .bat file automatically if a CD is in the device

#2 Post by npocmaka_ » 24 Nov 2016 04:29

if you don't have access to the machine you are aiming you should check this - https://msdn.microsoft.com/en-us/librar ... 02(v=vs.85).aspx
if it is your own machine you can create a schedule task triggered by event .You have to check the event log for the event written when cd is put. here's shctasks help - http://ss64.com/nt/schtasks.html

ladinai
Posts: 3
Joined: 24 Nov 2016 00:47

Re: How to start a .bat file automatically if a CD is in the device

#3 Post by ladinai » 24 Nov 2016 05:04

Hello,

thank you. This seems to be a bit too complicated. Yes it is my own device so I do have full admin acces.
Is there no simple if-clause like if CD is in device D: than run .bat file..?

Thank you and best regards
Ladina

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

Re: How to start a .bat file automatically if a CD is in the device

#4 Post by Squashman » 24 Nov 2016 08:38

ladinai wrote:Hello,

thank you. This seems to be a bit too complicated. Yes it is my own device so I do have full admin acces.
Is there no simple if-clause like if CD is in device D: than run .bat file..?

Thank you and best regards
Ladina


Well we can check if there is something in the D: drive but the batch file would constantly have to run and keep checking for the existence. Batch files are not really event driven by themselves.

ladinai
Posts: 3
Joined: 24 Nov 2016 00:47

Re: How to start a .bat file automatically if a CD is in the device

#5 Post by ladinai » 24 Nov 2016 08:52

Hey,

alright I see. So there it's might be better to do this point through the windows services...
However I do have another question als well.

I would like to enhance my code:
*******************************************************************************
@ echo off

start cmd.exe
robocopy D:\ C:\Users\Ladina\Desktop\Test /E /LOG:C:\Users\Ladina\Desktop\Test\log.txt /V
*******************************************************************************

The goald is that I will be asked at first to create a new share. I would like to be asked: please enter a new folder name.
Than I will enter for example "TEST1" and this folder will automatically build under the path specified: (for example) D:\ C:\Users\Ladina\Desktop

Than, secondly after I have created this new folder, the code should start with this part:
robocopy D:\ C:\Users\Ladina\Desktop\Test1 /E /LOG:C:\Users\Ladina\Desktop\Test1\log.txt /V

Important will be, that it already takes into concern the new entered folder name where the dates will be stored in.

Can you help me with that? I think for me it is at the moment far too complicated. However it would be a very useful thing since there is a lot of storage work to do.

Post Reply