FN-GM Posted February 16, 2008 Posted February 16, 2008 (edited) Hi When anyone uses a laptop that is not connected the network it takes ages to get past the “running startup scripts”. Obviously its not loading them because the machine isn’t connected the network. What can I do to stop scripts running when the machine isn’t on the network? Or could I make a timeout on the computer to make it giveup after x number of seconds failing loading the script? Thanks for the advice. Edited February 16, 2008 by FN-Greatermanchester
mattx Posted February 16, 2008 Posted February 16, 2008 Use a conditional statement to check for network settings in the script before it runs: If network connection exsists run script Else Exit Endif You could use the PCs IP address as the condition.....
FN-GM Posted February 16, 2008 Author Posted February 16, 2008 Thanks again for your help. I am not a good scripter, still learning. How would i setup the rule? the laptop may be connected to a home network so it may detect a network connection still.
mattx Posted February 16, 2008 Posted February 16, 2008 (edited) Thanks again for your help. I am not a good scripter, still learning. How would i setup the rule? the laptop may be connected to a home network so it may detect a network connection still. In that case then you need to set some rules or a flag. Get the script to check for an IP address, if it has one, get it to check for something YOU know it would be able to ping or read a file on the school network. If it pings ok or it can read the file , then the script runs, if the ping returns a null value or the file does not exist it does not run. As you know I tend to favour AutoIT in my scripts so I would use the @IPAddress1 macro or FileExists function. As for not being a good scripter, nor am I, never have, never will be - I just keep plugging away at it. Just checking up on the ping function on AutoIT and they provide a very good example: $var = Ping("www.AutoItScript.com",250) If $var Then; also possible: If @error = 0 Then ... Msgbox(0,"Status","Online, roundtrip was:" & $var) Else Msgbox(0,"Status","An error occured with number: " & @error) EndIf Edited February 16, 2008 by mattx
FN-GM Posted February 16, 2008 Author Posted February 16, 2008 $var = Ping("www.AutoItScript.com",250) If $var Then; also possible: If @error = 0 Then ... Msgbox(0,"Status","Online, roundtrip was:" & $var) Else Msgbox(0,"Status","An error occured with number: " & @error) EndIf Right so i would change that web address to an ip address of a server on the network? Then put that directly at the top of my VBS Script? Thanks alot
mattx Posted February 16, 2008 Posted February 16, 2008 I don't script in VBS so you would have to find the relevant function...
FN-GM Posted February 16, 2008 Author Posted February 16, 2008 Im totally lost by this, thanks anyway. z
PiqueABoo Posted February 16, 2008 Posted February 16, 2008 WMI will get you what you want, but it's probably easier to do something like the folllowing which simply looks at what ipconfig says. It's JS coz I don't VBS either, but there will be a very similar VBS equivalent: var s = RunCommand("ipconfig"); if (s.indexOf("10.10.10.254")>0) {//Found work's default gateway - we're at work //do something } function RunCommand(cmdLine) { var so = new ActiveXObject("WScript.Shell"); var outStream = so.Exec(cmdLine); return outStream.StdOut.ReadAll(); }
FN-GM Posted February 16, 2008 Author Posted February 16, 2008 So what do i do with that code please?
K.C.Leblanc Posted February 16, 2008 Posted February 16, 2008 The chances are if you've got no network connection the script isn't even running so adding a line to detect the presence of a network will be pointless. I think there's a setting in group policy to adjust the length of the time out.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now