Jump to content

[Question] How Do I determine if a networked computer is on?


Recommended Posts

Posted (edited)

I have a home network consisting of a server with 3 shared directories and a computer that will map those directories to D,E,Z drives. This machine is dual homed so auto reconnecting is not an option.

I want to create a batch file that will mount the drives if the server is on. I know how to mount the drives from the shell, but I haven't seen a way to determine if the remote machine is on. Does anyone know of a way to do this?

Thanks in advance,

Joe

[edit] Drives should have been D,E,Z not C,D,Z[/edit]

Edited by Joe_Sextus

Posted (edited)

Here is a VBS script I cannot test it but in theroy it should work

Save As MountDrives.Vbs

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Dim MapDrv : MapDrv = Array("C:\\","D:\\","Z:\\")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Volume Where Name = '" & MapDrv & "'")

For Each objItem in colItems
objItem.Mount()
Next

This VBS script detemines what drives are mapped

Use this link to read more about this script

Where I Found This Script

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService. _
ExecQuery("Select * from Win32_MappedLogicalDisk")
For Each objDisk in colDisks
Wscript.Echo "Device ID: " & objDisk.DeviceID
Wscript.Echo "Name: " & objDisk.Name
Wscript.Echo "Free Space: " & objDisk.FreeSpace
Wscript.Echo "Size: " & objDisk.Size
Next

Edited by gunsmokingman
Posted

Going with gunsmokingman's vbscript bonanza, here's a vbscript I wrote for RIS that waits until a network share is available, then maps the drive once the remote share is accessible. The script times out after 20 minutes (and tells you so), but this can be modified as necessary for your needs:

Dim sTestPath
Dim intCount
Dim objnet

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objVolatileEnv = objShell.Environment("VOLATILE")
Set objnet = CreateObject("Wscript.Network")

' An UNC path here that will be available when network connection is in place
sTestPath = "\\server\share
intCount = 1

' test on volatile environment variable to avoid running logon script
' if the user has already run the logon script.
If Not objVolatileEnv("LogonScript") = "Done" Then

Do Until objFSO.FolderExists(sTestPath)
' sleep 5 seconds
WScript.Sleep 5000
intCount = intCount + 1
If intCount = 240 Then
MsgBox "Unable to connect to network share for 20 minutes. Please notify your network administrator."
Exit Do
End If
Loop

' share/folder available on server now, so continue
objnet.MapNetworkDrive "Z:", "\\server\share","True","domain\user","password"

End If

Posted

cluberti that a nice script

Here is the first 2 scripts I posted combined into one script

Now I cannot test this as I am testing Vista and have not added my other computers to Vista.

In therory they should work

strComputer = "."
Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim MapDrv
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService. _
ExecQuery("Select * from Win32_MappedLogicalDisk")
If colDisks.count = 0 Then
Act.Popup "Cannot Not Find A Computer To Map The Drives", 15,"No Computer", 0 + 32
Else
For Each objDisk in colDisks
MapDrv = MapDrv & vbCrLf & objDisk.DeviceID
For Each strMP In MapDrv
Set colItems = objWMIService.ExecQuery("Select * From Win32_Volume Where Name = '" & MapDrv & "\\'")
For Each objItem in colItems
objItem.Mount()
Next
Next
Next
End If

Posted

Thanks! VBScript that runs in XP should run on Vista - all of my current scripts do, including the above, and yours looks like it should be fine.

Posted

The problem is I am having problems connecting from Vista to my XP computers, I have filled a bug.

I have had Vista running for over 2 days and I want to see how long I can keep it going with out rebooting.

This is the first Vista version that has been able to do that with out a blue screen. the earlier ones 4 to 12 hours.

Posted
Going with gunsmokingman's vbscript bonanza, here's a vbscript I wrote for RIS that waits until a network share is available, then maps the drive once the remote share is accessible. The script times out after 20 minutes (and tells you so), but this can be modified as necessary for your needs:

Dim sTestPath
Dim intCount
Dim objnet

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objVolatileEnv = objShell.Environment("VOLATILE")
Set objnet = CreateObject("Wscript.Network")

' An UNC path here that will be available when network connection is in place
sTestPath = "\\server\share
intCount = 1

' test on volatile environment variable to avoid running logon script
' if the user has already run the logon script.
If Not objVolatileEnv("LogonScript") = "Done" Then

Do Until objFSO.FolderExists(sTestPath)
' sleep 5 seconds
WScript.Sleep 5000
intCount = intCount + 1
If intCount = 240 Then
MsgBox "Unable to connect to network share for 20 minutes. Please notify your network administrator."
Exit Do
End If
Loop

' share/folder available on server now, so continue
objnet.MapNetworkDrive "Z:", "\\server\share","True","domain\user","password"

End If

Thanks, this works great.

Joe

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...