Web www.arconi.com

 

Logon Script Process - Using a VB Script and GPO

NOTE: You may have noticed several lines that have asterisks in front of them and some info about what the line does. Its always good to note your scripts as much as possible since you probably wont be the last person to manage the system. As well if your like me you may forget what you you were doing and why you made the change.

So now you may want to check the workstations for running programs like Anti-Virus. Or you may want to look for certain registry keys, or whatever else you have interest in knowing about the workstation. I like to make sure Anti-Virus is running. If it's not I send an email to the help desk so they can dispatch an engineer to the users desk.

'********* check for anti-virus and notify IT if missing *********
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'FrameworkService.exe'")
Set objComputer = CreateObject("Shell.LocalMachine")
Set objShell = CreateObject("WScript.Shell")
If colProcesses.Count = 0 Then
subject = "Anti-virus is not running on "& objComputer.MachineName
textbd = "Anti-virus is not running on "& objComputer.MachineName
Call SmtpServer
End If

I like to place some code that's easy to identify that can run outside programs. This way if another engineer comes along to manage the system they can make changes easily without bothering me ;-)

'**********Call scripts or programs outside of this script- change the line after "WshShell.Run" to the program to call *********************

'Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Run "DfltDelSetv3.vbs"

If you want your logon script to send emails with information in them you need to have a method to do it in place. If your users have the SMTP service running on their system (IIS installed) then you can accomplish it with a few lines of code. This is not usually the case so you need to build a little SMTP server in the script to send out email.

'********** email information ***********
'Place any routine above this sub-routine and have it "CALL" SmtpServer
'Then pass the 2 varibles, subject (subject line of the email) and textbd (message text)

Sub SmtpServer
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "LogonScript@yourcompany.com"
objEmail.To = "helpdesk@yourcompany.com"
objEmail.Subject = subject
objEmail.Textbody = textbd
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"yourEmailServer"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub

By the way most of the code in here I borrowed from other sources such as "The Scripting Guys" at Microsoft. I find that 90% of what ever you may want to script has already been done you just need to look around a bit. It will save you tons of time and you'll learn even quicker if you look at what someone else has done to get the results you need.

Next we'll discuss implementing the script with a GPO..

 

About Me | Site Map | Privacy Policy | Contact Me | ©2006 ArconiSoftTools