UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Vbscript To Copy Folder From Network Drive To User Desktop    
 
   
ciapul12
post Feb 3 2016, 06:58 AM
Post#1



Posts: 226
Joined: 7-June 14



Hi There
I'm using below script to simply provide my users with the latest access database.
The double click this script and it copies new files into specified directory.
However as you can see below my script requires me to specify the computer name in "DestinationFile" which is rather painful because I in my case I have 30 users and each one of them has exactly the same script with only difference that it refers to their pc name...
I would like to have this script written so that it could be generic to any users is this possible?
I have tried using the "Environment.GetFolderPath(Environment.SpecialFolder.Desktop)" but failed every time.
Hopefully someone here can help :-)

Regards
Dan

CODE
Dim oFSO, oFile, SourceFile, DestinationFile, FolderSource, FolderDestination
Dim objShell, RegPath, RegValue, RegName, RegVar, BinaryReturn, ArrayValue

'Create FileSystem Object
Set oFSO = CreateObject("Scripting.FileSystemObject")

SourceFile = "W:\General Access\NCN SYSTEM\NCN Project"
DestinationFile = "C:\Users\AndrewB\Desktop\NCN SYSTEM\NCN Project"

If oFSO.FileExists(DestinationFile) Then oFSO.DeleteFile DestinationFile

oFSO.CopyFile SourceFile, DestinationFile

msgbox "Database updated"

'close out file(s) from memory
On Error Resume Next
oFile.close
Set oFSO = Nothing
Set oFile = Nothing
WScript.Quit
Go to the top of the page
 
dashiellx2000
post Feb 3 2016, 07:21 AM
Post#2


UtterAccess VIP
Posts: 9,762
Joined: 11-March 05
From: Maryland


I would not attempt to install in the User directory for this very reason, rather I always install on the C drive. The VBScript I use copies the updated version of the database and then automatically opens it.

CODE
Dim fso
Dim wshShell
Dim SourceFile
Dim DestinationFile  
Dim strDirectory
Dim strCheckFile

SourceFile = "\\nw100\shared\Shares\Patacctg\PFSARReportingSystem\PFSARReportingSystem.accdb"
DestinationFile = "C:\PFSARReportingSystem\PFSARReportingSystem.accdb"
strDirectory = "C:\PFSARReportingSystem"
strCheckFile = "C:\PFSARReportingSystem\PFSARReportingSystem.laccdb"

Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(strCheckFile) Then
    On Error Resume Next
    FSO.DeleteFile(strCheckFile)
    If Err.Number <>0 Then
        MsgBox "You already have the PFS AR Reporting System Open",vbExclamation,"Error - PFS AR Reporting System Open"
        Set objPFSSupport = GetObject(DestinationFile).Application
        On Error Goto 0
        dim shell
        set shell = CreateObject("wscript.shell")
        shell.AppActivate "PFSSupportSystem"
    Else
        If FSO.FolderExists(strDirectory) Then
        Else
            set objFolder=FSO.CreateFolder(strDirectory)
        End if

        If FSO.FileExists(SourceFile) Then
               FSO.CopyFile SourceFile, DestinationFile
        End if    
        Set wshShell = WScript.CreateObject ("WSCript.shell")
            wshshell.run "MSACCESS.EXE """ & DestinationFile & """", 3, False
        set wshshell = nothing
    End if
Else
    If FSO.FolderExists(strDirectory) Then
    Else
      set objFolder=FSO.CreateFolder(strDirectory)
    End if

    If FSO.FileExists(SourceFile) Then
       FSO.CopyFile SourceFile, DestinationFile
    End if    
        Set wshShell = WScript.CreateObject ("WSCript.shell")
        wshshell.run "MSACCESS.EXE """ & DestinationFile & """", 3, False
    set wshshell = nothing
End if

Set FSO = Nothing


This works for me, but I'm sure it can be improved upon.

HTH

William.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    14th December 2017 - 11:58 AM