Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project for work that has me redirect the Documents and Desktop folders of my users to a share on a SAN that is attached to our network. I am accomplishing this through GPM in Windows Server 2008r2. I am also tasked with creating a home drive (H:\) with a script that transfers all the user data over in those respective locations. Once the script executes initially and everything is transferred successfully, i would like the file transfer(robocopy) portion to delete itself but the H:\ to remain mapped. A big concern for me are my users that are on the road and connect through VPN. The VPN connects after logon. I took a script from RaisKazi, 9 May 2013 to establish an IF/THEN statement for my vbscript. VBScript to check - Am I connected to VPN?[^]the rest of the code looks like this. Please advise me how I can improve on this
VB
Function IsVPNConnected()
   
   IsVPNConnected = False
   sComputer = "." 

   Set oWMIService = GetObject("winmgmts:\\" _
    & sComputer & "\root\CIMV2") 

    
   Set colItems = oWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapterConfiguration",,48) 

    
   For Each objItem in colItems 

'Please check description of your VPN Connection by running command "ipconfig /all" on command-line.

    If(InStr(LCase(objItem.Description),"vpn")) Then
     IsVPNConnected = objItem.IPEnabled     
    End If

   Next
   

   If(IsVPNConnected) Then
    IsVPNConnected =  "I am Connected to VPN."
   Else
    IsVPNConnected = "I am Not Connected to VPN."
   End If

End Function

Sub MapNetworkDrive


Dim objNetwork, strUserName, strDriveLetter, strRemotePath, strUserName, strSourceOne, strSourceTwo, strTarget, WshShell, strHomeDrive, WshNetwork
Set objNetwork = CreateObject(Wscript.Network)
Set objExec = objShell.Exec("ping -n 6 -w 4000 " & strTarget
Set WshNetwork = Wscript.CreateObject("Wscript.Network")
WshNetwork.MapNetworkDrive "H:", \\10.100.1.218\HomeFolder\Users$\username*\
On Error Resume Next

strDriveLetter = "H:"
strRemotePath = "\\10.100.1.218\HomeFolder\Users$\username*\"
strUserName = objNetwork.Username
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, & "\" & strUserName, True
homeDriveSet objShell.namespace(strDriveLetter).Self.Name(Shell.Application) 
strNewName = strUserName & "'s Home Folder"
objShell.NameSpace(strDriveLetter).Self.Name = strNewName <user> Home Drive


Set oShell = Wscript.CreateObject(Wscript.shell)
Set objFSO = Wscript.CreateObject(Scripting.FileSystemObject)
strSourceOne = Chr(34) & "C:\User\username*\Documents" & Chr(34)
strTarget = Chr(34) & "\\10.100.1.218\HomeFolder$\Users$\username*\" & Chr(34)
strParms = " /mir /sec /copy:datsou /if *.pdf *.doc *.docx *.xls *.txt *.xlsx *.pptx /R:4 /W:2 /NP /log+:" & "\\10.100.1.218\HomeFolder$\Logs\RoboCOPLog.dco" 

Set oshell = CreateObject("Wscript.Shell")
strCommand = Robocopy.exe
WshShell.Run ("robocopy " & strSourceOne & " " & strTarget & strParms)

Set oShell = Wscript.CreateObject(Wscript.shell)
Set objFSO = Wscript.CreateObject(Scripting.FileSystemObject)
strSourceTwo = Chr(34) & "C:\User\username*\Desktop" & Chr(34)
strTarget = Chr(34) & "\\10.100.1.218\HomeFolder$\Users$\username*\" & Chr(34)
strParms = " /mir /sec /copy:datsou /if *.pdf *.doc *.docx *.xls *.txt *.xlsx /R:4 /W:2 /NP /log+:" & "\\10.100.1.218\HomeFolder\Logs\RoboCOPLog.doc" 

Set oshell = CreateObject("Wscript.Shell")
strCommand = Robocopy.exe
WshShell.Run ("robocopy" & strSourceTwo & " " & strTarget & strParms)
Posted
Updated 12-Jun-14 17:09pm
v3
Comments
Sergey Alexandrovich Kryukov 12-Jun-14 22:32pm    
You could have notified Rais on your question. Actually I have just done it for you by commenting on his latest comment.
If you are referring some article, you could add a question in comments to that article. That way, Rais can be notified of your concern and get a chance to answer.

It's always a good idea to give us a link to the piece of code you are referring. It's not too late to do it, by clicking on Improve question.

—SA
Marc785 12-Jun-14 22:42pm    
I have done so Sergey. Thank you for helping me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900