NZTechworks
Programmer
I run a small network with Win XP and Win7 workstations and mappings area a pain as they dont always get invoked and you have to open an explorer window and click on the mapped drive with the red X before ite will "refresh".
Yes I know where must be a "network" fix for this, but I gave up on that years ago!
So my solution is to run a script at startup to:
1) disconnect all mappings
2) reconnect mappings
3) open a windows explorer window for each mapping
4) close each explorer window
I have got steps 1-3 working, but cant find any way to close one or more windows explorer windows.
Here is my script:
------------------------------------------
On Error Resume Next
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
Set objShell = CreateObject("Wscript.Shell")
set shell = WScript.CreateObject("WScript.Shell")
'strPath = Wscript.Arguments(0)
intMapping = _
Msgbox("Refresh Work Mappings?", _
vbYesNo, "Mapping Refresh Script")
If intMapping = vbYes Then
objNetwork.RemoveNetworkDrive "P:"
objNetwork.MapNetworkDrive "P:", "\\TW05\_Install"
objNetwork.RemoveNetworkDrive "S:"
objNetwork.MapNetworkDrive "S:", "\\TW05\_SharedData"
objNetwork.RemoveNetworkDrive "W:"
objNetwork.MapNetworkDrive "W:", "\\TW05\_Backup_Data"
objNetwork.RemoveNetworkDrive "Y:"
objNetwork.MapNetworkDrive "Y:", "\\TW05\_Archive"
objNetwork.RemoveNetworkDrive "J:"
objNetwork.MapNetworkDrive "j:", "\\Tw06\_SharedData"
objNetwork.RemoveNetworkDrive "K:"
objNetwork.MapNetworkDrive "K:", "\\TW05\_SD_Tools"
'now open mapped drives
objShell.Run "explorer.exe /e, P:\"
objShell.Run "explorer.exe /e, S:\"
objShell.Run "explorer.exe /e, W:\"
objShell.Run "explorer.exe /e, Y:\"
objShell.Run "explorer.exe /e, J:\"
objShell.Run "explorer.exe /e, K:\"
End If
intClose = _
Msgbox("Close explorer sessions?", _
vbYesNo, "Close Explorer Sessions")
If intClose = vbYes Then
'Shell.Run "cmd /c Taskkill /F /IM explorer.exe"
'Nope .. this kills taskbar as wel!!!!!!
'objShell.quit "explorer.exe"
'nope dosent work
' successP = shell.appactivate("P:\")
' if successP then shell.sendkeys "%{F4}"
' successS = shell.appactivate("S:\")
' if successS then shell.sendkeys "%{F4}"
' successW = shell.appactivate("W:\")
' if successW then
' shell.sendkeys "%{F4}"
' end if
' successY = shell.appactivate("Y:\")
' if successY then
' shell.sendkeys "%{F4}"
' end if
' successJ = shell.appactivate("J:\")
' if successJ then
' shell.sendkeys "%{F4}"
' end if
' successK = shell.appactivate("K:\")
' if successK then
' shell.sendkeys "%{F4}"
' end if
'NOPE, only clsoes last window
'close = CloseExplorerWindow("\\tw05\_Backup_Data")
'NOPE just returns "False" and doent close anything
'msgbox(close)
end if
Function CloseExplorerWindow(sFolderPath)
Dim bTest
bTest = false
with createobject("shell.application")
for each wndw in .windows
if typename(wndw.document) = "IShellFolderViewDual2" then
if lcase(wndw.document.folder.self.path) = lcase(sFolderPath) then
on error resume next
wndw.quit
bTest = err.number = 0
on error goto 0
end if
end if
next
end with ' shell.application
CloseExplorerWindow = Cstr(bTest)
end function
------------------------------------
you will see I have remmed out a few ways I've tried that havnt worked
I suspect the mapping issue is related to a delay in the workstations poling each other when they start up, and also that one of them is usually hybernated rather than turned off when disconnected.
Any suggestions much appreciated
Cheers
Grant
Yes I know where must be a "network" fix for this, but I gave up on that years ago!
So my solution is to run a script at startup to:
1) disconnect all mappings
2) reconnect mappings
3) open a windows explorer window for each mapping
4) close each explorer window
I have got steps 1-3 working, but cant find any way to close one or more windows explorer windows.
Here is my script:
------------------------------------------
On Error Resume Next
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
Set objShell = CreateObject("Wscript.Shell")
set shell = WScript.CreateObject("WScript.Shell")
'strPath = Wscript.Arguments(0)
intMapping = _
Msgbox("Refresh Work Mappings?", _
vbYesNo, "Mapping Refresh Script")
If intMapping = vbYes Then
objNetwork.RemoveNetworkDrive "P:"
objNetwork.MapNetworkDrive "P:", "\\TW05\_Install"
objNetwork.RemoveNetworkDrive "S:"
objNetwork.MapNetworkDrive "S:", "\\TW05\_SharedData"
objNetwork.RemoveNetworkDrive "W:"
objNetwork.MapNetworkDrive "W:", "\\TW05\_Backup_Data"
objNetwork.RemoveNetworkDrive "Y:"
objNetwork.MapNetworkDrive "Y:", "\\TW05\_Archive"
objNetwork.RemoveNetworkDrive "J:"
objNetwork.MapNetworkDrive "j:", "\\Tw06\_SharedData"
objNetwork.RemoveNetworkDrive "K:"
objNetwork.MapNetworkDrive "K:", "\\TW05\_SD_Tools"
'now open mapped drives
objShell.Run "explorer.exe /e, P:\"
objShell.Run "explorer.exe /e, S:\"
objShell.Run "explorer.exe /e, W:\"
objShell.Run "explorer.exe /e, Y:\"
objShell.Run "explorer.exe /e, J:\"
objShell.Run "explorer.exe /e, K:\"
End If
intClose = _
Msgbox("Close explorer sessions?", _
vbYesNo, "Close Explorer Sessions")
If intClose = vbYes Then
'Shell.Run "cmd /c Taskkill /F /IM explorer.exe"
'Nope .. this kills taskbar as wel!!!!!!
'objShell.quit "explorer.exe"
'nope dosent work
' successP = shell.appactivate("P:\")
' if successP then shell.sendkeys "%{F4}"
' successS = shell.appactivate("S:\")
' if successS then shell.sendkeys "%{F4}"
' successW = shell.appactivate("W:\")
' if successW then
' shell.sendkeys "%{F4}"
' end if
' successY = shell.appactivate("Y:\")
' if successY then
' shell.sendkeys "%{F4}"
' end if
' successJ = shell.appactivate("J:\")
' if successJ then
' shell.sendkeys "%{F4}"
' end if
' successK = shell.appactivate("K:\")
' if successK then
' shell.sendkeys "%{F4}"
' end if
'NOPE, only clsoes last window
'close = CloseExplorerWindow("\\tw05\_Backup_Data")
'NOPE just returns "False" and doent close anything
'msgbox(close)
end if
Function CloseExplorerWindow(sFolderPath)
Dim bTest
bTest = false
with createobject("shell.application")
for each wndw in .windows
if typename(wndw.document) = "IShellFolderViewDual2" then
if lcase(wndw.document.folder.self.path) = lcase(sFolderPath) then
on error resume next
wndw.quit
bTest = err.number = 0
on error goto 0
end if
end if
next
end with ' shell.application
CloseExplorerWindow = Cstr(bTest)
end function
------------------------------------
you will see I have remmed out a few ways I've tried that havnt worked
I suspect the mapping issue is related to a delay in the workstations poling each other when they start up, and also that one of them is usually hybernated rather than turned off when disconnected.
Any suggestions much appreciated
Cheers
Grant