Re: Script initiate a drive connection?
- From: kfrost <kris@xxxxxxxxx(donotspam)>
- Date: Tue, 21 Mar 2006 17:12:27 -0800
Thank you Marty,
I hardly ever mess with scripts and didn't want to have to compile something
to try and do this. Thank you for your help!
--
kris@xxxxxxxxx<Remove This Before Emailing>
Network & Software Integration
www.n-sv.com
"Helping put the pieces of your IT puzzle together"
"Marty List" wrote:
.
I just threw this together quickly, so do your own testing/tweaking/optimizing.
'========================================================================='
Option Explicit
Const ComputerName = "yourservername"
Const ShareName = "yoursharename"
Const DriveLetter = "X:"
Const SleepInterval = 10000 ' milliseconds
Dim objWMI, objPing, colPings, ServerOnline, Result
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
ServerOnline = False
Do
Set colPings = objWMI.ExecQuery _
("Select * From Win32_PingStatus Where Address = '" & _
ComputerName & "'")
For Each objPing in colPings
If IsNull(objPing.StatusCode) Or objPing.StatusCode <> 0 Then
ServerOnline = False
WScript.Echo ComputerName & " failed to respond, sleeping for " & _
SleepInterval \ 1000 & " seconds."
WScript.Sleep SleepInterval
Else
ServerOnline = True
WScript.Echo ComputerName & " responded at address " & _
objPing.ProtocolAddress
End If
Next
Loop While ServerOnline = False
Result = MapDrive(DriveLetter, "\\" & ComputerName & "\" & ShareName)
WScript.Quit(Result)
'========================================================================='
Function MapDrive(ByVal strDrive, ByVal strShare)
'========================================================================='
On Error Resume Next
' If the drive letter is mapped elsewhere, it is overwritten.
' If the drive letter is already mapped to the correct share, no changes.
' This check uses objNetwork.EnumNetworkDrives but could also use
' FileSystemObject.GetDrive.ShareName
Const SYSTEM_ERRBASE = 2147024896 'Abs(vbObjectError + 196608)
Dim objNetwork, colDrives
Dim i, intIgnoredError, Result
Set objNetwork = WScript.CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
If colDrives.Count > 0 Then
For i = 0 To colDrives.Count - 1 Step 2
'WScript.Echo "DEBUG: [" & colDrives(i) & " = " & colDrives(i+1) & "]"
If UCase(colDrives(i)) = UCase(strDrive) Then
If UCase(colDrives(i+1)) = UCase(strShare) Then
intIgnoredError = 85
' Ignoring MapNetworkDrive() error 85, drive is mapped correctly.
Else
Err.Clear
Call objNetwork.RemoveNetworkDrive(strDrive, False, True)
'WScript.Echo "DEBUG: RemoveNetworkDrive() returned: Err.Number
WScript.Sleep 1000
End If
End If
Next
End If
Err.Clear ' WSH 5.1's MapNetworkDrive does not clear Err on success.
objNetwork.MapNetworkDrive UCase(strDrive), strShare
MapDrive = Err.Number
Result = Err.Description
If MapDrive < 0 Then MapDrive = MapDrive + SYSTEM_ERRBASE
If MapDrive = intIgnoredError Then
MapDrive = 0
End If
If MapDrive = 0 Then
WScript.Echo "Drive " & strDrive & " mapped successfully."
Else
WScript.Echo "Mapping failed, error " & CStr(MapDrive) & " occurred."
WScript.Echo vbNewLine & vbNewLine & Result
End If
End Function
'========================================================================='
"kfrost" <kris@xxxxxxxxx(donotspam)> wrote in message
news:275635B4-94FF-4901-BCE0-E0AC9E3F5722@xxxxxxxxxxxxxxxx
Could probably get by that way but do you have an example of how to do that
utilizing the credentials stored with XP?
Thanks.
--
kris@xxxxxxxxx<Remove This Before Emailing>
Network & Software Integration
www.n-sv.com
"Helping put the pieces of your IT puzzle together"
"Marty List" wrote:
Sorry , I didn't read your post carefully enough. I don't know how to
simulate
in a script the double click on a disconnected drive.
The default behavior of XP is to automatically connect network drivers at
logon
(but not bootup), but if one fails then its mapped but in some sort of
"disconnected" state.
Maybe you could change your approach a little, instead of mapping the drive
ahead of time, just store the credentials in the account manager. Then the
script would ping, loop, ping, loop until the VPN is up and then disconnect
the
drive if it exists, then map the drive.
"kfrost" <kris@xxxxxxxxx(donotspam)> wrote in message
news:C8FFF1DB-5543-4EF9-A038-7C9D0F8C498F@xxxxxxxxxxxxxxxx
Hello Marty,
Guess it doesn't really matter what the script is. vbscript is fine. Not
sure you would need to manage the password because it is already being
managed by XP.
The drive is already mapped by right clicking on My Network Places and
clicking Map Network Drive. You then select the drive and the share and
click "Connect using a different user name" You supply the credentials
here.
However, when the machine reboots, the drive doesn't connect until you go
into My Computer and double click the drive mapping. Then everything works
fine.
So therefore, I'm looking for a way to do a ping for the remote server that
will be succesful after the Cisco VPN client connects during boot up. Then
once I receive a successful ping, do something that's equivalent of a user
double clicking on the mapped drive that causes the connection.
(Thinking about it I think there may be a setting somewhere that tells XP
to
automatically connect map drives on boot up.) But I'm still curious as to
how to do this via a script.
Thanks.
kris
--
kris@xxxxxxxxx<Remove This Before Emailing>
Network & Software Integration
www.n-sv.com
"Helping put the pieces of your IT puzzle together"
"Marty List" wrote:
Which scripting language?
Where do you want to store the password? If it's stored in the script (in
plain
text) that's easy. If you want it encrypted that's harder.
Before you script this, look into letting Windows XP manage the password:
Control Panel -> User Accounts -> Advanced -> Manage Passwords
Or a command line shortcut:
Start %WINDIR%\System32\RunDll32.exe
%WINDIR%\System32\KeyMgr.dll,KRShowKeyMgr
"kfrost" <kris@xxxxxxxxx(donotspam)> wrote in message
news:E6271CA3-6D38-4C33-BCF5-1D8CA82661D8@xxxxxxxxxxxxxxxx
Hello,
Have a user who has an XP machine. When it's rebooted, from the Startup
folder, a Cisco VPN client is used to connect this machine to the main
office. This XP machine is not a member of the domain and they use a
connect
as to map a drive to a server share at the main office which is part of
a
domain.
Right now if somebody reboots the machine, they have to remember to go
into
My Computer and double click on the mapped drive so it will initiate the
connection before the drive can be used.
My thoughts are to create a script that when kicked off with ping the
remote
server, if not available, pause and loop back through several times
waiting
for the VPN connection. Once successful, do something in script that
will
emulate the actions of somebody double clicking the mapped drive in My
Computer. (Having said that I don't necessary need to script exactly
the
same steps that are performed by double clicking the drive mapping, just
something that will initiate the authentication and connection.
Thanks.
kris
- References:
- Re: Script initiate a drive connection?
- From: Marty List
- Re: Script initiate a drive connection?
- From: kfrost
- Re: Script initiate a drive connection?
- From: Marty List
- Re: Script initiate a drive connection?
- From: kfrost
- Re: Script initiate a drive connection?
- From: Marty List
- Re: Script initiate a drive connection?
- Prev by Date: Re: Script initiate a drive connection?
- Next by Date: Re: Script initiate a drive connection?
- Previous by thread: Re: Script initiate a drive connection?
- Next by thread: Re: Script initiate a drive connection?
- Index(es):
Relevant Pages
|
Loading