thanks
Yes - determine the IP address (e.g. with ipconfig.exe) and loop until you
get a valid value.
Is it a login script or a startup script? Need you to provide more
details on what you are doing. Is the script applied via GPO? If so
then configure to wait for network.
Mark
--
- this is for a home network
- router acting as server
- external HDD attached to router
- users in system want to use HDD as shared data
- desktop maps drive properly, as there is no wait for WLAN discovery and
IP assignment
laptops, however, fail to map drive letter on startup script because device
hasn't been discoverd yet (takes about 20 seconds)
OK, so how about just adding a sleep command to the script before you
map the drive?
Give it a 30 second delay just to be sure:
WScript.Sleep 30000
You might also want to check out the Iomega line, they have an external
drive that has an RJ45 and works very much like a NAS. I just
purchased a 1TB drive yesterday for $175. Larger sizes are available.
I also tried the NetGear SC101T. I would not recommend that. Doesn't
work with x64 systems and Vista support is terrible. Plus it was
taking over 12 hours to format a 500GB drive and mirror it. I had to
take that back and get the Iomega.
Hope that is helpful,
Mark D. MacLachlan
--
A slightly kludgy method would be to ping the default gateway until you
get a reply:
sGateway = "192.168.1.254"
Do
Set oPing = GetObject("winmgmts:").InstancesOf("Win32_PingStatus" _
& " WHERE Address='" & sGateway & "' AND statusCode=0")
WScript.Sleep 1000
Loop Until oPing.Count = 1
'launch with "cscript c:\nasmapper.vbs //nologo" -> /programs/startup
'VBS Script to map NAS over wifi homenets (non GPO script)
'Shadowbq - 2009 BSD License
'Reference Functions: ScriptGuy! (MS), quiet_lurker (neowin), Aaron P
(neowin)
Dim objWMIService, objNet
Dim intSleep, WNICName, knownSSID, retries, maxRetries
Dim mapDrive, mapLocation, mapUsername, mapPassword
knownSSID="URWP80" 'SSID of Hotspot that has mapped location
WNICName="Dell Wireless 1470 Dual Band WLAN Mini-PCI Card" 'Nic name
listed in WMI
maxRetries = 10 'maxRetries * intSleep/1000 ~= total possible
seconds
intSleep = 2000 'wait cycles
mapDrive = "Y:" 'Map to Drive
mapLocation = "\\storage\public" 'Location of Share
mapUsername = "Guest" 'User Account for Share
mapPassword = "" 'User Password for Share
'If your having problems finding the WNICName you can use the
'\\root\wmi call to ("Select * From MSNdis_80211_Configuration") flip
through all wireless devices..
Private Sub GetWMI(WMIArray, WMIQuery, WMIRoot)
'On error resume Next
DIM WMIClass
Set WMIClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\
\.\root\" & WMIRoot)
If not(WMIClass is nothing) Then Set WMIArray = WMIClass.ExecQuery
(WMIQuery)
End Sub
Function SSID()
'On error resume Next
DIM objSSIDSet, objSSID, ID, i
Call GetWMI(objSSIDSet, "Select * from
MSNdis_80211_ServiceSetIdentifier Where active=true", "wmi")
For Each objSSID in objSSIDSet
ID = ""
For i = 0 to objSSID.Ndis80211SsId(0)
ID = ID & chr(objSSID.Ndis80211SsId(i + 4))
Next
SSID = ID
Next
End Function
Function WNICStatus()
Dim colItems, objItem, strStatus
Call GetWMI(colItems, "Select * from Win32_NetworkAdapter where Name
= '" & WNICName & "'", "cimv2")
For Each objItem in colItems
Select Case objItem.NetConnectionStatus
Case 0 strStatus = "Disconnected"
Case 1 strStatus = "Connecting"
Case 2 strStatus = "Connected"
Case 3 strStatus = "Disconnecting"
Case 4 strStatus = "Hardware not present"
Case 5 strStatus = "Hardware disabled"
Case 6 strStatus = "Hardware malfunction"
Case 7 strStatus = "Media disconnected"
Case 8 strStatus = "Authenticating"
Case 9 strStatus = "Authentication succeeded"
Case 10 strStatus = "Authentication failed"
Case 11 strStatus = "Invalid address"
Case 12 strStatus = "Credentials required"
End Select
Next
WNICStatus = strStatus
End Function
Function fnMapNetworkDrive (Drive, Path, Uname, Upass)
Dim i, oDrives
set objNet = Wscript.CreateObject("Wscript.Network")
Set oDrives = objNet.EnumNetworkDrives
For i = 0 to oDrives.Count - 1 Step 2 ' Find out if an existing
network drive exists
If oDrives.Item(i) = Drive Then
WScript.Echo "Removing drive: " & Drive
objNet.RemoveNetworkDrive Drive, true, true
End If
Next
WScript.Echo "Mapping drive: " & Drive & " to path: " & Path
objNet.MapNetworkDrive Drive, Path, false, Uname, Upass
fnMapNetworkDrive = "[completed mapping drive]"
Set i = Nothing
Set oDrives = Nothing
Set Drive = Nothing
Set Path = Nothing
End Function
Dim nicStatus, nicSSID
WScript.Echo "NAS Wifi Mapper"
WScript.Echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
WScript.Echo "[Checking NIC Status]"
nicStatus = WNICStatus()
retries = 0
while (StrComp(nicStatus, "Connected") <> 0)
If (retries < maxRetries) Then
retries = retries + 1
Wscript.Echo "Nic " & nicStatus & ".."
Wscript.Sleep intSleep
nicStatus = WNICStatus()
Else
Wscript.Error "*** Max # of connection attempts reached"
End If
Wend
Wscript.Echo "Connected .. continuing"
WScript.Echo "[Checking SSID Status]"
nicSSID = SSID()
nicSSID = Left(nicSSID, len(nicSSID)-1)
Wscript.Echo "SSID: " & nicSSID
If (StrComp(nicSSID, knownSSID) = 0) Then
Wscript.Echo "[Correct SSID]"
Else
On Error Resume Next
Dim errDescription, errSource
errSource = "NAS Mapper"
errDescription = "Incorrect SSID for network share to be
established"
Wscript.Echo "An Error:'" & errDescription & "' by '" & errSource &
"'."
WScript.Quit 8
End If
WScript.Echo "[Mapping Drive] "
Wscript.Echo fnMapNetworkDrive (mapDrive, mapLocation, mapUsername,
mapPassword)
WScript.Quit