Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
The help visible when you type wscript /? (or more properly wscript //?) at the prompt shows 2 slashes for the switches available, although one will work in a simple case where the script itself is not supplied with any slashed parameters, as you have noticed. The scripting host programs cscript.exe and wscript.exe are written to interpret doubly slashed command line switches as intended for themselves. The official advice from Microsoft is to use two slashes // for options specific to the scripting hosts cscript.exe and wscript.exe so that the hosts can distinguish between switches meant for them and those which may be meant for the scripts which they are running.You may not have realised that, because the vbs file extension is associated (by Windows) with wscript.exe, the following have identical effect both at the command line and in a batch:Code: [Select]wscript anyscript.vbsanyscript.vbsAnd so do theseCode: [Select]wscript //nologo anyscript.vbsanyscript.vbs //nologoSo if anyscript had a parameter /goose either of these following could be used. Without the double slash convention the second invocation format would be ambiguous: (as to which parameter was for cscript.exe and which one was for anyscript.vbs)Code: [Select]wscript //nologo anyscript.vbs /gooseanyscript.vbs //nologo /goose
wscript anyscript.vbsanyscript.vbs
wscript //nologo anyscript.vbsanyscript.vbs //nologo
wscript //nologo anyscript.vbs /gooseanyscript.vbs //nologo /goose
hi, I need to create a batch file that sends an email automatically when a windows service stops. I could have the batch file run every 10 minutes to see if the service is active, but I have no idea how to give an if condition and then send an email. First of all is this possible? any suggestions would be great to know. Thanks.
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colMonitoredProcesses = objWMIService. _ ExecNotificationQuery("Select * From __InstanceModificationEvent " _ & " Within 1 where TargetInstance ISA 'Win32_Service'")Do While True Set objLatestProcess = colMonitoredProcesses.NextEvent If LCase(objLatestProcess.TargetInstance.Name) = "" Then 'Name of service quoted; do not use display name If objLatestProcess.TargetInstance.State = "Stop pending" Then Call SendMail End if If objLatestProcess.TargetInstance.State = "Stopped" Then Call SendMail End if End ifLoopSub SendMail() Set cdo = CreateObject("CDO.Message") With cdo .Subject = "Service Down" 'email subject line quoted .From = "" 'your email address quoted .To = "" 'recipient email address quoted .TextBody = "" 'email body text quoted .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 'your ISP SMTP server address .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Configuration.Fields.Update .Send End With Set cdo = Nothing End Sub
Sidewinder, once the script discovers the service is in the stopped state, will it keep sending emails every 10 minutes?
@ sidewinderwon't it require password for sending the mailsI mean if i add in the field From="somone@mydomain.com"then will it send the email without the password here ??
strComputer = "."Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")For Each objService in colRunningServices If objService.DisplayName = "Licensing Service" And objService.State = "Stopped" Then WScript.Echo "Licensing Service is Stopped" Call SendMail End IfNextSub SendMail() Set CDO = CreateObject("CDO.Message") With cdo .From = "name@name.com" .To = "name2@name.com" .Subject = "Service Down" .Textbody = "Test" .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp mail server" .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "userid"' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Configuration.Fields.Update .Send End With End Sub