Script Center > Scripting Forums > The Official Scripting Guys Forum! > VBS - Script Fails after User Input on Logoff
Ask a questionAsk a question
 

QuestionVBS - Script Fails after User Input on Logoff

  • Tuesday, November 03, 2009 9:54 AMkarl_009 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    I have a script which am running at logon and logoff using the group policy.

    The logon is fine however the logoff seems to fail, I belive this is because the VBS runs but it then trys to run a DOS Shell for the robocopy.

    I was thinking is there away to keep the VBS running after YES is pressed and allow the DOS Shell to stay open and run but when the DOS Shell closes close the VBS?

    Here is the code;

    Option Explicit
    
    
    '*  
    '*  Declare Variables  
    '*  
    
    Dim intFIL, intResult, intFOL, tFol, intSIZ,cFol, tFolSize
    Dim strGFO, strMSG
    
    'Local Store
    cFol = "C:\UserData " & createobject("Wscript.Network").Username
    
    'Server Store
    tFol = "\\swuk0ns105\LaptopBackup$\" & createobject("Wscript.Network").Username
    
    
    '*  
    '*  Declare Objects  
    '*  
     
    Dim objFSO, objGFO, objTFO, objShell, WshShell
    set objShell = CreateObject("Wscript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")  
    Set WshShell = WScript.CreateObject("WScript.Shell")
    
    
    '*  
    '*  Error Checking
    '*  
    
    'Checks for the User Folder on the Local C:\ Drive
    If not objFSO.FolderExists(cFol) then
      msgbox "Unable to find Local Data Store, " & cFol & vbCrLf & "Contact the IT Department!", vbOKOnly + vbError, "Error"
      wsh.quit 1
    End If
    
    'Checks for the User Folder on the Server
    If not objFSO.FolderExists(tFol) then
      msgbox "Unable to find Server Data Store, " & tFol & vbCrLf & "Contact the IT Department!", vbOKOnly + vbError, "Error"
      wsh.quit 2
    End If
    
    'Checks for the RoboCopy Application
    If not objFSO.FileExists("c:\windows\system32\robocopy.exe") then
      msgbox "Unable to find robocopy.exe" & vbCrLf & "Contact the IT Department!", vbOKOnly + vbError, "Error"
      wsh.quit 3
    End If
    
    
    '*  
    '*  GetSubFolders()  
    '*  
    
    Set objTFO = objFSO.GetFolder(tFol)
    
    'If you want it in Kilobytes use 1024 instead of 1048576
    tFolSize = int(objTFO.Size/1048576)
    
    Call GetSubFolders(cFOL)  
    
    'Display title and location of local store
    strMSG = "Local Data Backup Solution " & vbCr & "Location of Data '" & cFOL & "':" & vbCrLf
    
    'Display the local store size
    strMSG = strMSG & vbCrLf & "Local Store" & vbTAB & FormatNumber(intSIZ/1048576,0) & " Mb ("  & FormatNumber(intFIL,0) & " Files, " & FormatNumber(intFOL,0) & " Folders)"  
    
    'Display the server store size
    strMSG = strMSG & vbCrLf & "Server Store" & vbTAB & tFolSize & "Mb"
    
    'Display the difference in size
    strMSG = strMSG & vbCrLf & "Difference is " & vbTAB & int(intSiz/1048576 - tFolSize) & " Mb" 
    
    'Displays yes&no popup box for 10 secords
    intResult = WshShell.Popup(strMsg,10,"Backup Files?",4 + 32)
    
    'If answer is yes then files are copied to the server using robocopy
    if intResult = 6 Then 
    	objShell.Run("c:\windows\system32\robocopy.exe ""C:\UserData %UserName%"" ""\\swuk0ns105\LaptopBackup$\%UserName%"" /MIR /W:1 /R:1")
    End If
    
    
    Set objFSO = Nothing  
    
    
    'Count the Files and Folders
    Sub GetSubFolders(FolderSpec)  
    	Set objGFO = objFSO.GetFolder(FolderSpec)  
    		If intSIZ = 0 Then  
    		intSIZ = intSIZ + objGFO.Size  
    		End If  
    		  
    	intFOL = intFOL + objGFO.SubFolders.Count  
    	intFIL = intFIL + objGFO.Files.Count  
    	  
    	For Each strGFO in objGFO.Subfolders  
    		Call GetSubFolders(strGFO.Path)  
    	Next  
    
    End Sub
    
    
    
    Thanks for any help...

All Replies

  • Tuesday, November 03, 2009 1:25 PMTom Lavedas Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Get the WSH documents and read about the RUN function:
    WSH 5.6 documentation download (URL all one line)
    http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

    There you will find that there are two more switches, one of which causes Run to act in the way you want.  For example,

    sCmd = "%WINDIR%\system32\robocopy.exe ""C:\UserData %UserName%"" " _
             & """\\swuk0ns105\LaptopBackup$\%UserName%"" /MIR /W:1 /R:1"
    objShell.Run sCmd, 0, True

    Note, when used this way the parentheses must NOT be included.

    Tom Lavedas
  • Wednesday, November 04, 2009 8:34 AMkarl_009 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Thanks for your reply...

    I will have a look into this today...

    Thank You.