![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | script that checks whether a pc is connecting to LAN Hi, is there a sample script that can check whether a pc is connecting to LAN? The script needs to be run when the user logs on. thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: script that checks whether a pc is connecting to LAN tree leafs wrote: Quote: > is there a sample script that can check whether a pc is connecting to LAN? > The script needs to be run when the user logs on. > thanks logs on. Otherwise the user has logged on locally. There are several ways to check for a domain (check if the computer has authenticated to a domain), but all methods I'm aware of involve error trapping and a timeout (maybe 10 seconds) if there is no connection. === Method 1 ==== On Error Resume Next Set objRootDSE = GetObject(LDAP://RootDSE) If (Err.Number = 0) Then On Error GoTo 0 Wscript.Echo "Authenticated to domain " & objRootDSE.Get("defaultNamingContext") Else On Error GoTo 0 Wscript.Echo "Not authenticated to domain" End If === Method 2 ==== On Error Resume Next Set objSysInfo = CreateObject("ADSystemInfo") If (Err.Number = 0) Then On Error GoTo 0 Wscript.Echo "Authenticated to domain " & objSysInfo.DomainDNSName Else On Error GoTo 0 Wscript.Echo "Not authenticated to domain" End If -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: script that checks whether a pc is connecting to LAN Thanks very much. "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:Ov1YgQUKJHA.4324@xxxxxx Quote: > tree leafs wrote: > Quote: >> is there a sample script that can check whether a pc is connecting to >> LAN? >> The script needs to be run when the user logs on. >> thanks > The computer will be authenticated (connected) to the domain before the > user logs on. Otherwise the user has logged on locally. There are several > ways to check for a domain (check if the computer has authenticated to a > domain), but all methods I'm aware of involve error trapping and a timeout > (maybe 10 seconds) if there is no connection. > === Method 1 ==== > On Error Resume Next > Set objRootDSE = GetObject(LDAP://RootDSE) > If (Err.Number = 0) Then > On Error GoTo 0 > Wscript.Echo "Authenticated to domain " & > objRootDSE.Get("defaultNamingContext") > Else > On Error GoTo 0 > Wscript.Echo "Not authenticated to domain" > End If > > === Method 2 ==== > On Error Resume Next > Set objSysInfo = CreateObject("ADSystemInfo") > If (Err.Number = 0) Then > On Error GoTo 0 > Wscript.Echo "Authenticated to domain " & objSysInfo.DomainDNSName > Else > On Error GoTo 0 > Wscript.Echo "Not authenticated to domain" > End If > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: script that checks whether a pc is connecting to LAN I had an intermittent problem where (on a dialup connection while at the cottage) I would lose connections to the DNS. I wrote a little GUI which would execute ipconfig and extract the IP addresses of the internet connection (my computer, default gateway, DNS) every five seconds, log the results and display them in the GUI. It uses kixforms (free download) for the GUI. You can strip out the code and do away with the GUI. Code follows... ' ' ' Name: ' ' ' ' ip.vbs ' ' ' ' Description: ' ' ' ' This script monitors an internet connection. It provides a GUI which displays the IP ' ' address and status for ' ' ' ' o the computer on which the script is running ' ' o the server assigned as the gateway ' ' o the server assigned as the primary domain name server ' ' o the server assigned as the alternate domain name server ' ' ' ' The connections are tested every 5 seconds. Also displayed ' ' ' ' o the number of times each connection has failed ' ' o the time of the last connection failure ' ' ' ' Results are logged to the file identified in LogFile. ' ' ' ' Notes: ' ' ' ' GUI provided by kixForms version 2.46 ' ' ' ' Audit: ' ' ' ' 2008-09-28 jdeg original code ' ' ' 'create an instance of the kixForms system object Dim System: Set System = CreateObject("KiXtart.System") 'define the form Dim frmMain: Set frmMain = System.Form() frmMain.Size = System.Size(409, 214) frmMain.Text = "Internet Connection Monitor" frmMain.FormBorderStyle = 2 Dim lblAddress: Set lblAddress = frmMain.Controls.Label lblAddress.AutoSize = True lblAddress.Size = System.Size(58, 13) lblAddress.Text = "IP Address" lblAddress.Location = System.Point(155, 12) Dim lblFailed: Set lblFailed = frmMain.Controls.Label lblFailed.AutoSize = True lblFailed.Size = System.Size(35, 13) lblFailed.Text = "Failed" lblFailed.Location = System.Point(250, 12) Dim lblLastFailed: Set lblLastFailed = frmMain.Controls.Label lblLastFailed.AutoSize = True lblLastFailed.Size = System.Size(58, 13) lblLastFailed.Text = "Last Failed" lblLastFailed.Location = System.Point(315, 12) 'My Computer Stats Dim staMe: Set staMe = frmMain.Controls.Label staMe.BackColor = System.Color.FromName("Lime") staMe.Size = System.Size(20, 20) staMe.BorderStyle = 1 staMe.Location = System.Point(11, 38) Dim lblMe: Set lblMe = frmMain.Controls.TextBox lblMe.Size = System.Size(90, 20) lblMe.Text = "My Computer" lblMe.Location = System.Point(37, 38) Dim adrMe: Set adrMe = frmMain.Controls.TextBox adrMe.Size = System.Size(100, 20) adrMe.Location = System.Point(133, 38) Dim totMe: Set totMe = frmMain.Controls.TextBox totMe.Size = System.Size(61, 20) totMe.Location = System.Point(239, 38) totMe.Alignment = 1 Dim lstMe: Set lstMe = frmMain.Controls.TextBox lstMe.Size = System.Size(72, 20) lstMe.Location = System.Point(306, 38) 'Gateway Computer Stats Dim staGateway: Set staGateway = frmMain.Controls.Label staGateway.BackColor = System.Color.FromName("Lime") staGateway.Size = System.Size(20, 20) staGateway.BorderStyle = 1 staGateway.Location = System.Point(11, 68) Dim lblGateway: Set lblGateway = frmMain.Controls.TextBox lblGateway.Size = System.Size(90, 20) lblGateway.Text = "Gateway" lblGateway.Location = System.Point(37, 68) Dim adrGateway: Set adrGateway = frmMain.Controls.TextBox adrGateway.Size = System.Size(100, 20) adrGateway.Location = System.Point(133, 68) Dim totGateway: Set totGateway = frmMain.Controls.TextBox totGateway.Size = System.Size(61, 20) totGateway.Location = System.Point(239, 68) totGateway.Alignment = 1 Dim lstGateway: Set lstGateway = frmMain.Controls.TextBox lstGateway.Size = System.Size(72, 20) lstGateway.Location = System.Point(306, 68) 'Primary DNS Stats Dim staPrimary: Set staPrimary = frmMain.Controls.Label staPrimary.BackColor = System.Color.FromName("Lime") staPrimary.Size = System.Size(20, 20) staPrimary.BorderStyle = 1 staPrimary.Location = System.Point(11, 98) Dim lblPrimary: Set lblPrimary = frmMain.Controls.TextBox lblPrimary.Size = System.Size(90, 20) lblPrimary.Text = "Primary DNS" lblPrimary.Location = System.Point(37, 98) Dim adrPrimary: Set adrPrimary = frmMain.Controls.TextBox adrPrimary.Size = System.Size(100, 20) adrPrimary.Location = System.Point(133, 98) Dim totPrimary: Set totPrimary = frmMain.Controls.TextBox totPrimary.Size = System.Size(61, 20) totPrimary.Location = System.Point(239, 98) totPrimary.Alignment = 1 Dim lstPrimary: Set lstPrimary = frmMain.Controls.TextBox lstPrimary.Size = System.Size(72, 20) lstPrimary.Location = System.Point(306, 98) 'Alternate DNS Stats Dim staAlternate: Set staAlternate = frmMain.Controls.Label staAlternate.BackColor = System.Color.FromName("Lime") staAlternate.Size = System.Size(20, 20) staAlternate.BorderStyle = 1 staAlternate.Location = System.Point(11, 128) Dim lblAlternate: Set lblAlternate = frmMain.Controls.TextBox lblAlternate.Size = System.Size(90, 20) lblAlternate.Text = "Alternate DNS" lblAlternate.Location = System.Point(37, 128) Dim adrAlternate: Set adrAlternate = frmMain.Controls.TextBox adrAlternate.Size = System.Size(100, 20) adrAlternate.Location = System.Point(133, 128) Dim totAlternate: Set totAlternate = frmMain.Controls.TextBox totAlternate.Size = System.Size(61, 20) totAlternate.Location = System.Point(239, 128) totAlternate.Alignment = 1 Dim lstAlternate: Set lstAlternate = frmMain.Controls.TextBox lstAlternate.Size = System.Size(72, 20) lstAlternate.Location = System.Point(306, 128) 'Status Bar Dim StatusBar: Set StatusBar = frmMain.Controls.StatusBar StatusBar.Size = System.Size(399, 22) StatusBar.Text = "" StatusBar.Location = System.Point(0, 156) StatusBar.Dock = 2 'Timer Dim Timer1: Set Timer1 = System.Timer() Timer1.Enabled = True Timer1.Interval = 5000 Timer1.OnTick = "Timer1_OnTick()" Dim wso 'windows script shell helper object ' Dim fso 'file system helper object ' Dim HostName 'the name of the computer on which this script is running ' Dim LogFile 'the file to log the results to ' Dim LogOut 'text stream object for log file output ' 'create the helper objects Set wso = CreateObject("Wscript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") 'get the name of the host computer from the environment variable HostName = wso.ExpandEnvironmentStrings("%COMPUTERNAME%") 'initialize counters and status displays MeFail = 0 MeLast = "" GatewayFail = 0 GatewayLast = "" PrimaryFail = 0 PrimaryLast = "" AlternateFail = 0 AlternateLast = "" 'open the log file LogFile = "c:\ip.log" set LogOut = fso.OpenTextFile(LogFile,8,true) 'initialize the display and start the timer Timer1_OnTick Timer1.Enabled = True 'periodically update the display until the user closes the form frmMain.Visible = "True" on error resume next Do 'While frmMain.Visible Execute(frmMain.DoEvents) if err.Number <> 0 then wscript.Quit Loop FormClose Function FormClose() msgbox "closing" End Function 'this function handles the timer event Function Timer1_OnTick () 'refresh the addresses of all connections GetAddresses if adrMe.Text = "n/a" then exit function 'ping the addresses in turn and update the display If Ping(adrMe.Text) Then staMe.BackColor = "Lime" staMe.Tag = True Else staMe.BackColor = "Red" staMe.Tag = False MeFail = MeFail + 1 MeLast = Time End If totMe.Text = MeFail lstMe.Text = MeLast LogIt "Me" If Ping(adrGateway.Text) Then staGateway.BackColor = "Lime" staGateway.Tag = True Else staGateway.BackColor = "Red" staGateway.Tag = False GatewayFail = GatewayFail + 1 GatewayLast = Time End If totGateway.Text = GatewayFail lstGateway.Text = GatewayLast Logit "Gateway" If Ping(adrPrimary.Text) Then staPrimary.BackColor = "Lime" staPrimary.Tag = True Else staPrimary.BackColor = "Red" staPrimary.Tag = False PrimaryFail = PrimaryFail + 1 PrimaryLast = Time End If totPrimary.Text = PrimaryFail lstPrimary.Text = PrimaryLast LogIt "Primary" If Ping(adrAlternate.Text) Then staAlternate.BackColor = "Lime" staAlternate.Tag = True Else staAlternate.BackColor = "Red" staAlternate.Tag = False AlternateFail = AlternateFail + 1 AlternateLast = Time End If totAlternate.Text = AlternateFail lstAlternate.Text = Alternatelast LogIt "Alternate" StatusBar.Text = "Last Update at " & Now() End Function 'endregion Function LogIt ( node ) Dim status Dim address Execute "status = sta" & node & ".Tag" Execute "address = adr" & node & ".Text" LogOut.Write Now & " " LogOut.Write Left(node&Space(10),10) LogOut.WriteLine iif(status,"responding","not responding") End Function Function iif ( condition , tval , fval ) if condition then iif = tval else iif = fval End Function Function GetAddresses () Dim exe Dim result Dim active Dim i Set exe = wso.Exec("ipconfig /all") Do While exe.Status = 0 WScript.Sleep 100 Loop result = exe.Stdout.ReadAll result = Replace(result,vbCr,"") result = Split(result,vbLf) active = False For i = 0 To UBound(result) line = result(i) If InStr(line,"IP Address") > 0 Then active = True If active Then Select Case True Case InStr(line,"IP Address") > 0 adrMe.Text = Trim(Split(line,":")(1)) Case InStr(line,"Default Gateway") > 0 adrGateway.text = Trim(Split(line,":")(1)) Case InStr(line,"DNS Servers") > 0 adrPrimary.Text = Trim(Split(line,":")(1)) adrAlternate.Text = Trim(result(i+1)) End Select End If Next if not active then adrMe.Text = "n/a" adrGateway.Text = "n/a" adrPrimary.Text = "n/a" adrAlternate.Text = "n/a" end if End Function Function Ping ( ipaddress ) Dim PingResults 'collection of instances of Win32_PingStatus class ' Dim PingResult 'single instance of Win32_PingStatus class ' Set PingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" _ & HostName & "/root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus " _ & "WHERE Address = '" + ipaddress + "'") Ping = False For Each PingResult In PingResults If PingResult.StatusCode = 0 Then Ping = True End If Next End Function "tree leafs" <treeleafs@xxxxxx> wrote in message news:eBRG8ifKJHA.740@xxxxxx Quote: > Thanks very much. > > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in > message news:Ov1YgQUKJHA.4324@xxxxxx Quote: >> tree leafs wrote: >> Quote: >>> is there a sample script that can check whether a pc is connecting to >>> LAN? >>> The script needs to be run when the user logs on. >>> thanks >> The computer will be authenticated (connected) to the domain before the >> user logs on. Otherwise the user has logged on locally. There are several >> ways to check for a domain (check if the computer has authenticated to a >> domain), but all methods I'm aware of involve error trapping and a >> timeout >> (maybe 10 seconds) if there is no connection. >> === Method 1 ==== >> On Error Resume Next >> Set objRootDSE = GetObject(LDAP://RootDSE) >> If (Err.Number = 0) Then >> On Error GoTo 0 >> Wscript.Echo "Authenticated to domain " & >> objRootDSE.Get("defaultNamingContext") >> Else >> On Error GoTo 0 >> Wscript.Echo "Not authenticated to domain" >> End If >> >> === Method 2 ==== >> On Error Resume Next >> Set objSysInfo = CreateObject("ADSystemInfo") >> If (Err.Number = 0) Then >> On Error GoTo 0 >> Wscript.Echo "Authenticated to domain " & objSysInfo.DomainDNSName >> Else >> On Error GoTo 0 >> Wscript.Echo "Not authenticated to domain" >> End If >> >> -- >> Richard Mueller >> MVP Directory Services >> Hilltop Lab - http://www.rlmueller.net >> -- >> >> > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Quicken does not print checks in Vista 64 | Software | |||
| checks for messages but nbox not checked. | Live Mail | |||
| Can one start a script after connecting to a specific wireless network? | Vista installation & setup | |||
| WLM checks mail whenever network is connected | Live Mail | |||
| Newsgroup checks for new newsgroups and then loses new news | Live Mail | |||