A few days ago, I posted a question in this forum about how to use batch processing to send the IP to the email, and got the pointers from the friends in the forum. I have benefited a lot, but I am really weak in this aspect of knowledge, and there is still a problem that cannot be solved. I have to post this post again to ask the experts for guidance.
Original batch processing code:
@echo off
for /f "tokens=2 delims=:" %%i in ('"ipconfig|findstr /I /c:"ip address""') do set a=%%i
echo NameSpace="http://schemas.microsoft.com/cdo/configuration/" >1.vbs
echo Set Email=CreateObject("CDO.Message") >>1.vbs
echo Email.From="your sending email address" >>1.vbs
echo Email.To="your receiving email address" >>1.vbs
echo Email.Subject="TEST" >>1.vbs
echo Email.Textbody="%a%" >>1.vbs
echo With Email.Configuration.Fields >>1.vbs
echo ^.Item(NameSpace^&"sendusing")=2 >>1.vbs
echo ^.Item(NameSpace^&"smtpserver")="SMTP address" >>1.vbs
echo ^.Item(NameSpace^&"smtpserverport")=25 >>1.vbs
echo ^.Item(NameSpace^&"smtpauthenticate")=1 >>1.vbs
echo ^.Item(NameSpace^&"sendusername")="username" >>1.vbs
echo ^.Item(NameSpace^&"sendpassword")="password" >>1.vbs
echo ^.Update >>1.vbs
echo End With >>1.vbs
echo Email.Send >>1.vbs
cscript c:\1.vbs
del c:\1.vbs
Problem: When connected to the Internet, the batch processing runs and can successfully send the IP to the email, but if not connected to the Internet, it will be wrong. How to modify the command so that the batch processing runs only when the system is connected to the Internet, and does not run or does not display errors when not connected to the Internet?
Original batch processing code:
@echo off
for /f "tokens=2 delims=:" %%i in ('"ipconfig|findstr /I /c:"ip address""') do set a=%%i
echo NameSpace="http://schemas.microsoft.com/cdo/configuration/" >1.vbs
echo Set Email=CreateObject("CDO.Message") >>1.vbs
echo Email.From="your sending email address" >>1.vbs
echo Email.To="your receiving email address" >>1.vbs
echo Email.Subject="TEST" >>1.vbs
echo Email.Textbody="%a%" >>1.vbs
echo With Email.Configuration.Fields >>1.vbs
echo ^.Item(NameSpace^&"sendusing")=2 >>1.vbs
echo ^.Item(NameSpace^&"smtpserver")="SMTP address" >>1.vbs
echo ^.Item(NameSpace^&"smtpserverport")=25 >>1.vbs
echo ^.Item(NameSpace^&"smtpauthenticate")=1 >>1.vbs
echo ^.Item(NameSpace^&"sendusername")="username" >>1.vbs
echo ^.Item(NameSpace^&"sendpassword")="password" >>1.vbs
echo ^.Update >>1.vbs
echo End With >>1.vbs
echo Email.Send >>1.vbs
cscript c:\1.vbs
del c:\1.vbs
Problem: When connected to the Internet, the batch processing runs and can successfully send the IP to the email, but if not connected to the Internet, it will be wrong. How to modify the command so that the batch processing runs only when the system is connected to the Internet, and does not run or does not display errors when not connected to the Internet?
