VBScript deleting file after creation

I have the following code that does seem to work but at the end it seems to delete the file.

It copies if needed but then deletes the *.accdb  so that when Access opens the file is missing.  I can see it copying the db but then it deletes it?  either way...even if the file is there it still removes it?

don't know where I am going wrong...

by the way I do plan on changing the links of the deployment version to a network unc path

' ----- ExeScript Options Begin -----
' ScriptType: window,activescript,invoker
' DestDirectory: current
' Icon: default
' deployment.vbs
' ----- ExeScript Options End -----
'declare an object to be a filesystem object
Public fs
'declare an object to be a MS Access application
Public acApp
 'declare a wscript shell
Public WshShell

Main()

'-------------------------------------------------------------------------------------------------------------------------------------------
Sub Main()
dim MyConn
dim MyConn1
Dim LocalSplit
Dim ServerSplit
Dim x
Dim LocalBad



OpenCmdWindow()

Set fs = CreateObject("Scripting.FileSystemObject")

CheckDeployment()

If fs.FileExists("C:\Deployment\DeploymentVersion.txt") then
    Set MyConn= fs.OpenTextFile("C:\Deployment\DeploymentVersion.txt",1, true)
    ServerSplit = Split(MyConn.readall, ".")
    MyConn.Close
Else
    ServerSplit =Split("0.0.0.0", ".")
end if

If fs.FileExists("C:\LocalVersion\Version.txt") then
    Set MyConn1= fs.OpenTextFile("C:\LocalVersion\Version.txt",1, true)
    LocalSplit = Split(MyConn1.readall, ".")
    MyConn1.Close
else
    LocalSplit =Split("0.0.0.0", ".")
end if

set myconn = nothing
set myconn1 = nothing

If UBound(LocalSplit) <> UBound(ServerSplit) Then
        Call CopyUpdate()
        FireDB()
        Exit Sub
End If

For x = 0 To UBound(LocalSplit)
    If cint(ServerSplit(x)) > cint(LocalSplit(x)) Then
        Call CopyUpdate()
        FireDB()
        Exit Sub
    End If
Next

FireDB()

end sub

'------------------------------------------------------------------------------------
private Sub CopyUpdate()
Dim BuiltPath
Dim userpath


userpath= "C:\Deployment\"
BuiltPath = "C:\LocalVersion\"
'DeploymentVersionBackup = "C:\DeploymentVersionBackup\"

TempPath = "c:\prod\temp"

If fs.FolderExists(BuiltPath) = False Then
    fs.CreateFolder BuiltPath

End If
If fs.FolderExists(userpath) = False Then
    fs.CreateFolder userpath

End If

fs.copyfile "C:\Deployment\test.accdb", "C:\LocalVersion\test.accdb", -1
'fs.copyfile "C:\Deployment\deployment.vbs","C:\LocalVersion\LocalVersion.vbs", -1
fs.copyfile "C:\Deployment\DeploymentVersion.txt","C:\LocalVersion\Version.txt",-1

End Sub
'-----------------------------------------------------------------------------------------

Function CheckDeployment() 
Dim BuiltPath
BuiltPath = "C:\LocalVersion\test.accdb"
If fs.FileExists(BuiltPath) = False Then
    Call CopyUpdate()
End If



End Function
'---------------------------------------------------------------------------------------
sub FireDB

CloseCmdWindow()
Dim WshShell, PathToMDE, accessPath
Set WshShell = WScript.CreateObject("WScript.Shell")
PathToMDE = "C:\LocalVersion\test.ACCDB"
accessPath = "C:\Program Files\Microsoft Office 15\root\office15\MSAccess.exe"

WshShell.run chr(34) & accessPath & chr(34) & " " & chr(34) & PathToMDE & chr(34)

If fs.FileExists("C:\LocalVersion\test.accdb") then
    fs.DeleteFile "C:\LocalVersion\test.accdb", True
End If
If fs.FileExists("C:\LocalVersion\test.laccdb") then
    fs.DeleteFile "C:\LocalVersion\test.laccdb", True
End If
end sub

'-------------------------------------------------------------
sub OpenCmdWindow()
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /q",0
WScript.Sleep 10
WshShell.AppActivate "c:\windows\system32\cmd.exe /q"
WScript.Sleep 100
WshShell.Popup "Starting...." & vbcrlf & vbcrlf &  "Checking Version" & vbcrlf & vbcrlf & "Downloading if necessary...." ,5 ,"ALERT! Please Wait! This will close Automatically",0+48
SET WshShell= Nothing
end sub

 '------------------------------------------------------------
sub CloseCmdWindow()
dim oshell
dim oWmg
dim strWndprs
dim objQResult

WScript.Sleep 100

Set oShell = CreateObject("WScript.Shell") 
Set oWmg = GetObject("winmgmts:") 

strWndprs = "select * from Win32_Process where name='cmd.exe'" 
Set objQResult = oWmg.Execquery(strWndprs) 

For Each objProcess In objQResult 
	intReturn = objProcess.Terminate(1) 
Next
End sub

'------------------------------------------------------------

Open in new window

Ernest GroggSecurity Management InfoSecAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Won't this always delete the file, not sure what your intention was?

If fs.FileExists("C:\LocalVersion\test.accdb") then
    fs.DeleteFile "C:\LocalVersion\test.accdb", True
End If

Open in new window


»bp
0
Ernest GroggSecurity Management InfoSecAuthor Commented:
so I will have one deployment version on a network folder (for now I used the local machine) and then I will have the LocalVersion on the local machine.

First I was trying to test if the LocalVersion Folder was there, if not, create the folder.  That then should have then prompted to just copy the items to the LocalVersion folder and then open the db.  Else: if all is there then check the version #'s in each text file....if a version # was different in the .txt file, then remove the files then copy the new files
0
Bill PrewCommented:
I think I would need to better understand what you are trying to do in the script, it's not clear from the code, or what you have described so far.


»bp
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Ernest GroggSecurity Management InfoSecAuthor Commented:
so maybe here:

1. open the cmd window and use the message popup window.
2. set the FileSystemObject
3. run "CheckDeployment"--checks for the "buildpath"  which is the LocalVersion folder and db...if it does not exist then #4 else go to #5
4. run "CopyUpdate"--this creates the folders necessary and the files
5. next we compare the text files...if the local and server are not equal, run "CopyUpdate"--that will copy the files needed, if equal, go to #6
6. run FireDB--this starts the Access program  and the path to the file also closes the cmd window

If I comment out in FireDB, sure it does not delete, but I want to delete, not just overwrite or copy/paste if the text files are different

leaving that there deletes it no matter what.

does this help any?
0
Ernest GroggSecurity Management InfoSecAuthor Commented:
sorry, but have a meeting and will return I a couple of hours
0
Ernest GroggSecurity Management InfoSecAuthor Commented:
Ok.. Back now
0
Fabrice LambertFabrice LambertCommented:
IMO, the FireDB procedure does not do its intended job.

It launch MS Access, check for files existance and delete files.
Why that ?
It should just check for files existances, then if successfull launch MS Access.
So remove those DeleteFile statements, they have no business here.

On the other hand, the CopyUpdate procedure should copy files and overwrite no matter what, to ensure the most up to date files are available.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ernest GroggSecurity Management InfoSecAuthor Commented:
changed to remove the delete in FireDB
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.