I have not been doing as good of a job as I should have with making sure my computer is up to date with virus definitions and scans. I usually use Microsoft Security Essentials for real time, but then I round it off with Malwarebytes Anti-Malware on the side. There are a few problems though.
1. MSE is set to run once a week at 2:00 am. The computer is not on at this time and I don't want to leave it on all night long. This means it usually gets run while I am using it.
2. Even if I do have the computer wake up for this, how do I get it to go back to sleep?
3. What about Malwarebytes? What about definition updates?
I decided that I would set up a scheduled time early in the morning where everything will run. I will first have to turn on the computer, then run MSE, then check for definition updates for Malwarebytes, then run Malwarebytes, and then put the computer back to sleep. Lots to do.
Recently I discovered two pieces of technology that may help with this. One is Task Scheduler, and the other are windows batch files (.bat extension). I used the command line briefly before, but had never used it much until a few months ago.
This is the solution that I came up with.
1. I noticed that there already was a scheduled task labeled "Microsoft Antimalware Scheduled Scan" This was set to run once a week, but since the computer was put to sleep it was not running.
There are some settings though that can fix that. I discovered a setting called "Wake the computer to run this task"
ping -n 30 127.0.0.1
taskkill /F /IM "mbam.exe"
start mbam.exe /scan -quick -terminate
1. MSE is set to run once a week at 2:00 am. The computer is not on at this time and I don't want to leave it on all night long. This means it usually gets run while I am using it.
2. Even if I do have the computer wake up for this, how do I get it to go back to sleep?
3. What about Malwarebytes? What about definition updates?
I decided that I would set up a scheduled time early in the morning where everything will run. I will first have to turn on the computer, then run MSE, then check for definition updates for Malwarebytes, then run Malwarebytes, and then put the computer back to sleep. Lots to do.
Recently I discovered two pieces of technology that may help with this. One is Task Scheduler, and the other are windows batch files (.bat extension). I used the command line briefly before, but had never used it much until a few months ago.
This is the solution that I came up with.
1. I noticed that there already was a scheduled task labeled "Microsoft Antimalware Scheduled Scan" This was set to run once a week, but since the computer was put to sleep it was not running.
There are some settings though that can fix that. I discovered a setting called "Wake the computer to run this task"
Once that was checked it successfully woke up my computer and started running MSE.
2. Next up is Malwarebytes. Malwarebytes does support a schedule, however that is only in the Pro version. No since I don't really want to pay for it, and I like learning things I set out to find a way to do it all from a command line.
I created a new .bat file that will start this process. After looking around I discovered two things. One is that you can update and run Malwarebytes from the command line, but only the paid Pro version supports silent mode. That will make it slightly more difficult but still doable.
The first line of the file will then be:
start mbam.exe /update
I discovered an issue where after it updates its definitions, a window pops up asking that you press ok. The batch file will not proceed forward until the user clicks ok. Now since I am asleep at that time that is not going to work. So by saying "start mbam.exe /update" instead of just "mbam.exe /update" it will cause the rest of the script to go on and not wait for it to finish.
This means that we need to have it wait for it to finish though. There is no easy way that I could think of, especially since the window just opens up after the update is finished, so I decided to just hard code in a set time. I haven't found a good way to cause it to wait so I just used:
ping -n 30 127.0.0.1
This will force it to ping itself 30 times before going on to the next step. (around 30 seconds or so) This should give it enough time to update itself.
Now we still have that issue where the window popped up saying that it had updated successfully. I cannot start the scan until this is killed. So I use the useful taskkill function.
taskkill /F /IM "mbam.exe"
/IM tells it to look for mbam.exe and /F means it will forcefully kill it.
Then our final step:
start mbam.exe /scan -quick -terminate
This will do a quick scan. The -terminate parameter tells it to close the program when finished if nothing is detected. If something is it will just remain open until I get to it the next day.
The final result is:
cd "\Program Files (x86)\Malwarebytes' Anti-Malware"
start mbam.exe /updateping -n 30 127.0.0.1
taskkill /F /IM "mbam.exe"
start mbam.exe /scan -quick -terminate
3. Now I need to schedule everything. MSE usually takes less than 10 minutes to do a scan, so I will give it a 20 minute window. That means that Malwarebytes needs to start running 20 minutes MSE starts.
So I created a scheduled task that calls the .bat file that I just created. I had to check the box for "Run with highest privileges" so that it will run the .bat file as Administrator.
4. Last is to put the computer back to sleep. Not sure of an easy way so created another scheduled task. I am having this one run about 20 minutes after Malwarebytes starts.
For this one you want it to call rundll32.exe with "Powrprof.dll,SetSuspendState Sleep" as the arguments.
And that is that! I think this will work pretty well, but give it a week or two and I will be able to see if I missed anything. If anyone knows any hints or ideas to make it a little cleaner please let me know
UPDATE:
See my next post for an update on getting this to work.
No comments:
Post a Comment