Asked by:
Checking whether network connection is established <<VB Script>>

General discussion
-
Hi All,
I have a scenario, I'm running a power point slideshow on group of machines as soon as user login to the machine. The file is placed on a shared drive and can open only when the intranet network connection is established. The target environment doesn't have internet access.
Expectation is: As soon as user login, slideshow must begin without further wait.
Challenge is: I need to run the slideshow only after the intranet connection is established. ( In target environment, it takes 3-5 min to connect to the network)
I have tried the below code. It works fine on machine which is connected to internet with WiFi. But doesn't work on LAN with INTRANET.
Any insights are really helpful below VB Script code.
Option Explicit
Dim MyLoop,strComputer,objPing,objStatus
MyLoop = True
While MyLoop = True
strComputer = "google.com" '##### Here I want to use any intranet site link as there is no internet connection in the target environment.
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery _
("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If objStatus.Statuscode = 0 Then
MyLoop = False
Call MyProgram()
wscript.quit
End If
Next
Wscript.Sleep(5000)
Wend
Sub MyProgram()
'###########################
'I want to write some code here after the network connection is established' Open the powerpoint slide show file.
'###########################
End Sub
- Edited by R V Prasad Monday, April 23, 2018 5:23 AM
- Changed type Bill_Stewart Friday, July 27, 2018 6:10 PM
- Moved by Bill_Stewart Friday, July 27, 2018 6:11 PM This is not "scripts on demand"
Monday, April 23, 2018 4:17 AM
All replies
-
What code do you want to write? We cannot guess at what you want to do.
The code is pointless when no network is available.
We cannot design or write code for you. If you need custom code you will have to contact a consultant.
Please carefully review the following links to set your expectation for posting in technical forums.
This Forum is for Scripting Question Rather than script requests
Script requests
PowerShell DocumentationFrom a Bill Stewart summary of useful forum links:
- Posting guidelines
- Handy tips for posting to this forum
- How to ask questions in a technical forum
- Rubber duck problem solving
- How to write a bad forum post
- Help Vampires: A Spotter's Guide
- This forum is for scripting questions rather than script requests
\_(ツ)_/
Monday, April 23, 2018 4:31 AM -
Dear Jrv, Thank you for your reply.
I just would like to say, I wasn't so blunt and not asking for custom script for my requirement.
I understand and respect the forum guidelines. I was already prepared the code which works in some context but not in another. Hence I posted this after thorough testing to get the views from the forum.
My apologies in case If I was unable to articulate my question as per the guidelines.
Thanks,
RV
- Edited by R V Prasad Monday, April 23, 2018 4:55 AM
Monday, April 23, 2018 4:54 AM -
You posted a script that has nothing to do with your question. Before asking questions you need to learn the basics of scripting. We cannot tell you how to do this. It is up to you to learn the basics.
Start by doing the tutorial. When you have finished that you will be closer to asking a question that makes sense.
You mention a slideshow. What slideshow? Google, Microsoft, other. A photo show? a PowerPoint slideshow? There are many, many types of slideshows. First learn the technology then try to ask a clear question and provide a script example of what you are trying to do.
\_(ツ)_/
Monday, April 23, 2018 5:14 AM -
Dear Jrv,
Thank you. I appreciate your advice.
I would like to say that, I'm not new to the Scripting.
And crux of my question is simple, "Checking whether network connection is established before performing some task". I have also mentioned, code provided is working in some context but not in other context, so i thought someone would help to provide their guidance.
Thanks,
RV
Monday, April 23, 2018 5:39 AM -
Who wrote the code you posted? It does what you ask? What is the issue that you are having?
I will also note that you shouldn't be trying to learn VBScript. It is obsolete and much harder to use than PowerShell which is now the standard scripting language for Windows management.
\_(ツ)_/
Monday, April 23, 2018 5:46 AM -
Dear Jrv,
You are right. VBScript is obsolete and hard to use than PowerShell.But in my environment PS scripts are blocked at this moment due to some security concern.
I have just simplified my question, hope you can give your guidance.
I have created a vbscript to check whether network connection is established on the machine, if network connection is up then do some task ( here I just put message box with a message "Network Connection is established")
To check the network connectivity, I'm checking ping to the google.com or company intranet website. If the ping is responsive then network is up else not.
Below script is working fine in Scenario A but not working in Scenario B (I have changed google.com to company intranet website for Scenario B as there is no internet in scenario B)
Scenario A:
Machine is connected to INTERNET via WiFi.
Scenario B:
Machine is connected to company INTRANET via LAN (No internet)Option Explicit
Dim MyLoop,strComputer,objPing,objStatus
MyLoop = True
While MyLoop = True
strComputer = "google.com" '## or Company intranet website
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery _
("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If objStatus.Statuscode = 0 Then
MyLoop = False
Call MyProgram()
wscript.quit
End If
Next
Wscript.Sleep(5000)
Wend
Sub MyProgram()
MsgBox "Network connection is established"
End Sub
Monday, April 23, 2018 10:50 AM -
PS scripts are blocked at this moment
PS scripts can be executed just fine by setting the execution policy for the session.
Execution policy is not a security feature.
Just open the PowerShell window using the following command:
powershell -ExecutionPolicy RemoteSigned
Once you do that, you can run PowerShell scripts from that PowerShell window.
-- Bill Stewart [Bill_Stewart]
Monday, April 23, 2018 2:33 PM