I wanted to setup a computer so that it would automatically run a ‘Quick Scan’ every day when the user logs into it.
I started out trying to create a Scheduled Task. Sadly, for whatever the reason (decided to stop fighting with it after having wasted 2hrs trying to get it to work) I kept getting permission errors. Furthermore, it becomes very difficult to perform a definition update and then a scan, and delay things a little to not impact login… So Scheduled Tasks were not the answer.
I fiddled with Batch files, and they do work, but I decided, to turn to vbScript because I was more familiar and it allowed, in my opinion, more power and easier coding.
Here is what I came up with:
'*******************************************************************************
'Author: Daniel Pineault / CARDA Consultants Inc.
'Copyright: All rights reserved, 2013
'Purpose: Update MSE and then perform a Quick Scan of the system
' Place in the AllUser startup folder so it run everytime someone
' logs into the computer.
'Revision: 2013-10-04 Initial Release
'*******************************************************************************
Dim sMSEInstlRegKey
Dim sMSEPath
Dim sMSECmdLineExe
Dim sMSEUpdate
Dim sMSEQuickScan
Dim oShell
Dim lDelay
'Locate the MSE installation folder so we can use the cmd line
sMSEInstlRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Antimalware\InstallLocation"
sMSEPath = ReadFromRegistry(sMSEInstlRegKey,"")
sMSECmdLineExe = "MpCmdRun.exe"
'Build our 2 commands
'Build the Update Definition command
sMSEUpdate = chr(34) & sMSEPath & sMSECmdLineExe & chr(34) & " -SignatureUpdate"
'Build the Quick Scan command
sMSEQuickScan = chr(34) & sMSEPath & sMSECmdLineExe & chr(34) & " -Scan -1" '1-Quick Scan 2-Full Scan
'Define the delay, so the scan run slightly after actual logon, so as to not slow down the
'login process - try to make it a little less painful to the end-user.
lDelay=1000 * 60 * 1
'Actual run the commands
Set oShell = CreateObject("WScript.Shell")
WScript.Sleep lDelay 'Delay the script per the delay defined above
oShell.Run sMSEUpdate, 0, True 'Update the virus definition(s)
oShell.Run sMSEQuickScan, 0, True 'Scan the Computer
Set oShell = Nothing
Function ReadFromRegistry (strRegistryKey, strDefault)
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead( strRegistryKey )
if err.number <> 0 then
readFromRegistry= strDefault
else
readFromRegistry=value
end if
set WSHShell = Nothing
End Function
All you have to do is save the above code into a simple text file and name it as you wish, but give it a vbs file extension. In my case, I simply named it ‘MSE.vbs’. Then, to make it run for every user when they login, simply place the file in the AllUser StartUp folder.
You could easily modify this script to say run a Quick Scan Tuesday through Friday, but on Monday’s run a Full Scan… The possibilities are endless!
Also remember that Microsoft Security Essentials also has a basic scheduler built-in, so don’t go looking to complicate things for no reason should you only require a straight forward scheduling.