Fixie Posted December 5, 2007 Posted December 5, 2007 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.
ringfinger Posted December 7, 2007 Posted December 7, 2007 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.
Fixie Posted December 10, 2007 Author Posted December 10, 2007 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.
cluberti Posted December 10, 2007 Posted December 10, 2007 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...
Fixie Posted December 12, 2007 Author Posted December 12, 2007 (edited) Work in progress:Script currently not finished, or working. Going down this pathOption ExplicitOn Error Resume NextDim strDriveLetter, strRemotePathDim CheckDrive, AlreadyConnected, intDrive ' Define varsDim OWS, intReturn, objIE, strIETitle, objShell, k, objNetwork, intButton, blnConnected, sDialUpCmd, sResult ' define objectsSet 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.QuitEnd 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 timerIF (strTimer) = "10000" THENwScript.quitEND IF'\\Msgbox "found GovNet..."OWS.Run "\\ser005\SYSVOL\Gov.Gov.Gov.au\scripts\Gov_logon.bat"WScript.QuitFunction 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.AtEndOfStreamEnd 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 = NothingEnd Function Edited December 12, 2007 by Fixie
Fixie Posted December 12, 2007 Author Posted December 12, 2007 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 ExplicitOn Error Resume Next'Setting up a 5 minute timeoutintMaxTime = 300 intStartTime = TimerDim strDriveLetter, strRemotePathDim CheckDrive, AlreadyConnected, intDrive ' Define varsDim OWS, intReturn, objIE, strIETitle, objShell, strHost, objNetwork, intButton, blnConnected, sDialUpCmd, sResult ' define objects'get current userset objNetwork = createobject("WSCRIPT.Network")dim strCurrentUserstrCurrentUser = objNetwork.UserNameSet OWS = CreateObject("Wscript.Shell")Set objShell = CreateObject("WScript.Shell")Set objNetwork = CreateObject("WScript.Network")'This bit looks for Local machines RAS connectionIf IsRasConnected = True then Msgbox Ucase(strCurrentUser) & " - you're already connected to GovNetWireless. Exiting...." WScript.QuitEnd ifintButton = OWS.Popup("Connect account to GovNet, are you sure?",30,"Connect to Department of Government ?",65) CheckWhetherTerminateScriptIf intButton = 2 or intButton = -1 Then WScript.QuitEnd if' Run VPN linkOWS.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 IfLoop 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 IfLoop Until (blnConnected = 1)'end check u: connected..............' Connect Users Global Network Drive - in this case N:MapDrive "N:", "\\GovernementServer\users\" & strCurrentUserWScript.Quit'*************************************************Function IsRASConnected'*************************************************Const SYSTEM_FOLDER = 1, TEMP_FOLDER = 2 ' FileSystemObject constantsSet objFSO = CreateObject("Scripting.FileSystemObject")With objFSO' Construct a temporary filename.DostrTempFile = .BuildPath(.GetSpecialFolder(TEMP_FOLDER), .GetTempName)Loop While .FileExists(strTempFile)strCmdLine = .BuildPath(.GetSpecialFolder(SYSTEM_FOLDER), "cmd.exe") _& " /c " & .BuildPath(.GetSpecialFolder(SYSTEM_FOLDER), "rasdial.exe") _& " > " & strTempFileEnd WithCreateObject("Wscript.Shell").Run strCmdLine, 0, True' Open the temporary file.Set objTS = objFSO.OpenTextFile(strTempFile, 1)sStdOut = lcase(objTS.ReadLine)If Not objTS.AtEndOfStream ThenSelect Case sStdOutCase "connected to": IsRASConnected = TrueCase "no connections": IsRASConnected = FalseCase Else: IsRASConnected = FalseEnd SelectEnd If ' Close and delete the temporary file.objTS.CloseobjFSO.DeleteFile strTempFileSet objTS = NothingSet objFSO = NothingEnd 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 drivesSet 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 strDriveLetterOn Error Resume NextAlreadyConnected = False For intDrive = 0 To CheckDrive.Count - 1 Step 2 If CheckDrive.Item(intDrive) =strDriveLetter Then AlreadyConnected =TrueNext ' This section uses the If = then, else logic' This tests to see if the Drive is already mapped.' If yes then disconnectsIf AlreadyConnected = True then objNetwork.RemoveNetworkDrive strDriveLetter objNetwork.MapNetworkDrive strDriveLetter, strRemotePath Else objNetwork.MapNetworkDrive strDriveLetter, strRemotePath End if End SubFunction 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 strDriveLetterOn Error Resume NextAlreadyConnected = False For intDrive = 0 To CheckDrive.Count - 1 Step 2 If CheckDrive.Item(intDrive) = strDriveLetter Then IsDriveConnected = TrueNext End FunctionSub CheckWhetherTerminateScriptintCount = Timer - intStartTime If intCount >= intMaxTime then OWS.Popup "Timeout is about to happen...",5,"",vbExclamation WScript.QuitEnd ifEnd Sub
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now