Joe_Sextus Posted March 3, 2006 Posted March 3, 2006 (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 March 4, 2006 by Joe_Sextus
gunsmokingman Posted March 4, 2006 Posted March 4, 2006 (edited) Here is a VBS script I cannot test it but in theroy it should workSave As MountDrives.VbsstrComputer = "." 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() NextThis VBS script detemines what drives are mappedUse this link to read more about this script Where I Found This ScriptstrComputer = "." 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 March 4, 2006 by gunsmokingman
cluberti Posted March 4, 2006 Posted March 4, 2006 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 sTestPathDim intCountDim objnetSet 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 placesTestPath = "\\server\shareintCount = 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
gunsmokingman Posted March 4, 2006 Posted March 4, 2006 cluberti that a nice scriptHere is the first 2 scripts I posted combined into one scriptNow I cannot test this as I am testing Vista and have not added my other computers to Vista.In therory they should workstrComputer = "." 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
cluberti Posted March 4, 2006 Posted March 4, 2006 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.
gunsmokingman Posted March 4, 2006 Posted March 4, 2006 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.
Joe_Sextus Posted March 4, 2006 Author Posted March 4, 2006 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 sTestPathDim intCountDim objnetSet 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 placesTestPath = "\\server\shareintCount = 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 IfThanks, this works great.Joe
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