How can I block a program's usage for X time?

2

How can I block a program's usage for X time? I need this because of self control things.

Joe

Posted 2017-07-05T03:02:53.163

Reputation: 21

I never heard about that command, could you explain? thanks!! – Joe – 2017-07-05T03:06:57.247

Sorry if I'm being ignorant but, I think that script ends a program and I need to block a program. – Joe – 2017-07-05T03:11:12.237

Ohh, I didnt think it that way. Unfortunately, it sounds hard to setup, atleast for me lmao – Joe – 2017-07-05T03:13:36.170

I'm really trying my best but it gets so hard when you arent familiar with programming :'( – Joe – 2017-07-05T03:46:19.663

Joe - I went ahead and cleaned up my comments and added the detail from the comments to a prettier and a more clear answer for you. – Pimp Juice IT – 2017-07-05T04:11:48.683

Answers

3

How can I block a program's usage for X time?

You can use taskkill and set with the /A switch to use an arithmetic expression to keep counting up by one and using ping with the -n 02 pinging the 127.0.0.1 loopback address to ensure each arithmetic operation takes one second.

You then use a conditional if statement to check that if the number of seconds equals the value of time you tell it to run, it will then end once that is true.

Batch Script

I set numberofsecs=10 so for example you would change that to numberofsecs=60 for 60 seconds. However long you need this to run preventing the program from running, change that variable value to be the number of seconds for that time period. Be sure to also replace program.exe with the name of the program you need to restrict from being executed during this time

@echo on

set numberofsecs=10
set /a count=0

:Loop
ping -n 02 127.0.0.1
taskkill /f /im "program.exe"
set /a count+=1
if not %count%==%numberofsecs% GOTO :Loop
goto :eof

Further Resources

Pimp Juice IT

Posted 2017-07-05T03:02:53.163

Reputation: 29 425