Jump to content

Recommended Posts

Posted

Howdy.

Just got asked the question so I thought I'd ask you fine folk.

Is there a way through Group Policy etc to do the following.

Users login to a laptop without network connectivity. Cache Mode allows them to work.

The Network connection comes live. We'd like to have their network drives come live without them needing to login / re-enter passwords.

Does anyone have any suggestions?

Steve.


Posted

Have the same issue in my network. What I've done in the past, although not automated, is build a bat file that when double clicked will map all needed drives. I don't know of a way for GP to repush policies after already authenticating to the DC. You could maybe try a gpupdate /force but I doubt it will bring drives back without a logoff/logon.

Posted
Have the same issue in my network. What I've done in the past, although not automated, is build a bat file that when double clicked will map all needed drives. I don't know of a way for GP to repush policies after already authenticating to the DC. You could maybe try a gpupdate /force but I doubt it will bring drives back without a logoff/logon.

Thanks Mang.

I'm thinking that I need to find the event that occurs when the NIC starts communiticating with the DC, like when the FQDN is located or some such. Then have something set against that trigger to activate a gpupdate / force or some kind of login script .vbs .kix .bat something.

Posted

You could simply have a vbs that runs constantly from logon that checks for share availability and sleeps, and when one comes active (hence machine has network connectivity and is on the local LAN), run gpupdate and map network drives...

Posted (edited)

Work in progress:

Script currently not finished, or working.

Going down this path

Option Explicit
On Error Resume Next


Dim strDriveLetter, strRemotePath
Dim CheckDrive, AlreadyConnected, intDrive

' Define vars
Dim OWS, intReturn, objIE, strIETitle, objShell, k, objNetwork, intButton, blnConnected, sDialUpCmd, sResult

' define objects


Set OWS = CreateObject("Wscript.Shell")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

intButton = OWS.Popup("Connect account to GovNet, are you sure?",5,"Connect to Dep of Gov ?",65)


If intButton = 2 or intButton = -1 Then
WScript.Quit
End if

' Run VPN link
OWS.Run "rasphone.exe -d GovWire"



Do
Wscript.sleep 10000
'Msgbox "just checking for srv002..."
sDialUpCmd = "rasdial"
blnConnected = 0

' Execute sDialUpCmd and get the output of sDialUpCmd into a text string

sResult = CMDResults(sDialUpCmd)
'WScript.exit
Msgbox sResult
If InStr(1, Lcase(sResult), "no connections", vbTextCompare) > 0 Then
'WScript.Echo "Not connected!"
blnConnected = 0
Else
'WScript.Echo sResult
blnConnected = 1
End If
'Msgbox "blnConnected ..."' & blnConnected
Loop Until (blnConnected = 1)

'Loop Until IsAlive("srv002")
wScript.exits

' IF statement based on timer
IF (strTimer) = "10000" THEN
wScript.quit
END IF



'\\Msgbox "found GovNet..."

OWS.Run "\\ser005\SYSVOL\Gov.Gov.Gov.au\scripts\Gov_logon.bat"
WScript.Quit


Function CMDResults(cmdline)
' simple wrapper for command line you want
' to use while capturing output
Dim oShell, oExCmd, oExCmdStdOut

Set oShell = CreateObject("WScript.Shell")
Set oExCmd = oShell.Exec(cmdline)
Set oExCmdStdOut = oExCmd.StdOut
Do: WScript.Sleep 10
Do Until oExCmdStdOut.AtEndOfStream
CmdResults = CmdResults & oExCmdStdOut.ReadAll
Loop
Loop Until oExCmd.Status <> 0 and oExCmdStdOut.AtEndOfStream

End Function


'========================SubRoutines==========================================
Function IsConnect(strHost)
' Testing Connection to GovNet - looking for Wireless Connection.

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim objShell, objFSO, TempRASCon, fFile
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName
objShell.Run "rasdial "..." & strHost & ">" TempRASCon, 0 , True
Set fFile = objFSO.OpenTextFile(TempRASCon, ForReading, FailIfNotExist, OpenAsASCII)
Select Case InStr(fFile.ReadAll, "Connected")
Case 0
IsCon = False
Case Else
IsCon = True
End Select
fFile.Close
objFSO.DeleteFile(TempRASCon)
Set objFSO = Nothing
Set objShell = Nothing

End Function

Edited by Fixie
Posted

OK, OK. Here it is, the finished product.

Wasn't allowed to use Connection Manager or Network Manager. Reason unknown. Don't know if I'll ever need to do something like this again. But just incase you need to have a .vbs that does just this, enjoy.

'VBScript to Connect to VPN'
'For use by authorised Government personel only'
'Written by a Government Employee'

'Option Explicit
On Error Resume Next

'Setting up a 5 minute timeout
intMaxTime = 300
intStartTime = Timer



Dim strDriveLetter, strRemotePath
Dim CheckDrive, AlreadyConnected, intDrive

' Define vars
Dim OWS, intReturn, objIE, strIETitle, objShell, strHost, objNetwork, intButton, blnConnected, sDialUpCmd, sResult

' define objects

'get current user
set objNetwork = createobject("WSCRIPT.Network")
dim strCurrentUser
strCurrentUser = objNetwork.UserName


Set OWS = CreateObject("Wscript.Shell")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

'This bit looks for Local machines RAS connection
If IsRasConnected = True then
Msgbox Ucase(strCurrentUser) & " - you're already connected to GovNetWireless. Exiting...."
WScript.Quit
End if

intButton = OWS.Popup("Connect account to GovNet, are you sure?",30,"Connect to Department of Government ?",65)
CheckWhetherTerminateScript

If intButton = 2 or intButton = -1 Then
WScript.Quit
End if

' Run VPN link
OWS.Run "rasphone.exe -d GovNetWireless"

'get RAS connected...............
Do
Wscript.sleep 5000
blnConnected = 0
CheckWhetherTerminateScript
If IsRasConnected = True then
'WScript.Echo "RAS connected!"
blnConnected = 1
Else
'WScript.Echo "RAS not connected!"
blnConnected = 0
End If

Loop Until (blnConnected = 1)
'end get RAS connected...............

Wscript.sleep 5000

' Connect Users Global Network Drive - in this case U:
objNetwork.RemoveNetworkDrive "U:"

OWS.Run "\\GovernentServer002\SYSVOL\gov.gov.gov.au\scripts\Gov_logon.bat"

'check u: connected...............

Do
Wscript.sleep 5000
blnConnected = 0

If IsDriveConnected("U:") = True then
'WScript.Echo "U: connected!"
blnConnected = 1
Else
'WScript.Echo "u: not connected!"
blnConnected = 0
End If

Loop Until (blnConnected = 1)
'end check u: connected..............

' Connect Users Global Network Drive - in this case N:

MapDrive "N:", "\\GovernementServer\users\" & strCurrentUser

WScript.Quit


'*************************************************
Function IsRASConnected
'*************************************************
Const SYSTEM_FOLDER = 1, TEMP_FOLDER = 2 ' FileSystemObject constants

Set objFSO = CreateObject("Scripting.FileSystemObject")

With objFSO
' Construct a temporary filename.
Do
strTempFile = .BuildPath(.GetSpecialFolder(TEMP_FOLDER), .GetTempName)
Loop While .FileExists(strTempFile)

strCmdLine = .BuildPath(.GetSpecialFolder(SYSTEM_FOLDER), "cmd.exe") _
& " /c " & .BuildPath(.GetSpecialFolder(SYSTEM_FOLDER), "rasdial.exe") _
& " > " & strTempFile
End With

CreateObject("Wscript.Shell").Run strCmdLine, 0, True

' Open the temporary file.
Set objTS = objFSO.OpenTextFile(strTempFile, 1)

sStdOut = lcase(objTS.ReadLine)

If Not objTS.AtEndOfStream Then
Select Case sStdOut
Case "connected to": IsRASConnected = True
Case "no connections": IsRASConnected = False
Case Else: IsRASConnected = False
End Select
End If

' Close and delete the temporary file.
objTS.Close
objFSO.DeleteFile strTempFile

Set objTS = Nothing
Set objFSO = Nothing

End Function


'*********************************************


Sub MapDrive(strDrive, strPath)
' The section sets the variables.
strDriveLetter = strDrive

strRemotePath = strPath

' This sections creates two objects:
' objShell and objNetwork and counts the drives
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()

' This section deals with a For ... Next loop
' See how it compares the enumerated drive letters
' with strDriveLetter
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter Then AlreadyConnected =True
Next

' This section uses the If = then, else logic
' This tests to see if the Drive is already mapped.
' If yes then disconnects

If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
Else
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
End if
End Sub

Function IsDriveConnected(strDrive)
' The section sets the variables.
strDriveLetter = strDrive


Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()

' This section deals with a For ... Next loop
' See how it compares the enumerated drive letters
' with strDriveLetter
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) = strDriveLetter Then IsDriveConnected = True
Next

End Function

Sub CheckWhetherTerminateScript
intCount = Timer - intStartTime

If intCount >= intMaxTime then
OWS.Popup "Timeout is about to happen...",5,"",vbExclamation
WScript.Quit
End if




End Sub

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

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