sid20vt
asked on
vb script to install app after checking for a file
I am trying to put together a script bundled from different web sources which will checkfor the existance of a file and run an executable if it does NOT exist.
What this is doing is supposed to do is checking for the existance of a driver file in c:\program files and if it is not there running the exe.
I get an error and am not sure what.
' this script will check for the existance of a file and run an app if it is not found.
Option Explicit
Sub Main()
Dim FSO
Dim WSH
Dim LogFile
Dim TxtFile
Dim AppToRun
Dim ts
Dim Running
' These values are just for example and testing... substitute your own real values here.
'
LogFile = "C:\program files\cups driver\cups6.inf"
TxtFile = "C:\program files\cups driver\cups6.ini"
AppToRun = "\\10.10.10.1\Applications \Cups Driver\Cups driver discovery PDF.exe"
Set FSO = CreateObject("Scripting.Fi leSystemOb ject")
Set WSH = CreateObject("Wscript.Shel l")
' If target file doesn't exist, install app.
If Not FSO.FileExists(TxtFile) Then
Wscript.Echo "File does not exist."
Wscript.Quit
End If
' see if we need to create inf file...
If FSO.FileExists(LogFile) Then
Wscript.Echo "Aborting... application is installed."
Wscript.Quit
End If
' If we get this far then we can run the application...
Wscript.Echo "File does exist."
Set Running = WSH.Exec(AppToRun)
'End Sub
The exe in question installs the driver files
What this is doing is supposed to do is checking for the existance of a driver file in c:\program files and if it is not there running the exe.
I get an error and am not sure what.
' this script will check for the existance of a file and run an app if it is not found.
Option Explicit
Sub Main()
Dim FSO
Dim WSH
Dim LogFile
Dim TxtFile
Dim AppToRun
Dim ts
Dim Running
' These values are just for example and testing... substitute your own real values here.
'
LogFile = "C:\program files\cups driver\cups6.inf"
TxtFile = "C:\program files\cups driver\cups6.ini"
AppToRun = "\\10.10.10.1\Applications
Set FSO = CreateObject("Scripting.Fi
Set WSH = CreateObject("Wscript.Shel
' If target file doesn't exist, install app.
If Not FSO.FileExists(TxtFile) Then
Wscript.Echo "File does not exist."
Wscript.Quit
End If
' see if we need to create inf file...
If FSO.FileExists(LogFile) Then
Wscript.Echo "Aborting... application is installed."
Wscript.Quit
End If
' If we get this far then we can run the application...
Wscript.Echo "File does exist."
Set Running = WSH.Exec(AppToRun)
'End Sub
The exe in question installs the driver files
Sub FileExists()
Dim fso
Dim strRunProgram
Dim file As String
file = "C:\Test.xls" ' change to match the file w/Path
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
If Not fso.FileExists(file) Then
MsgBox file & " was not located.", vbInformation, "File Not Found"
strRunProgram = "c:\execute.exe" 'path to executable
WshShell.Run strRunProgram, 1, True
Else
MsgBox file & " has been located.", vbInformation, "File Found"
End If
End Sub
Dim fso
Dim strRunProgram
Dim file As String
file = "C:\Test.xls" ' change to match the file w/Path
Set fso = CreateObject("Scripting.Fi
If Not fso.FileExists(file) Then
MsgBox file & " was not located.", vbInformation, "File Not Found"
strRunProgram = "c:\execute.exe" 'path to executable
WshShell.Run strRunProgram, 1, True
Else
MsgBox file & " has been located.", vbInformation, "File Found"
End If
End Sub
ASKER
I needed to make sure it would not run over and over at every startup/login.
So check for existance of a file and run the application. If its already installed, dont run it again.
In the end I used kix script to get this done. Seemed to be the easiest way to make it work.
Sorry fostejo and cschipper. Did not try the vb solutions you sent in the end.
So check for existance of a file and run the application. If its already installed, dont run it again.
In the end I used kix script to get this done. Seemed to be the easiest way to make it work.
Sorry fostejo and cschipper. Did not try the vb solutions you sent in the end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Probably the simplest script to acheive that would be something like:
'Start of Script
Option Explicit
Dim FSO
Dim WSH
DIM txtFile
Dim AppToRun
TxtFile = "C:\test.xxx"
AppToRun = "Notepad.exe"
Set FSO = CreateObject("Scripting.Fi
Set WSH = CreateObject("Wscript.Shel
' If target file doesn't exist, install app.
IF NOT FSO.FileExists(TxtFile) THEN
Wsh.Run AppToRun
END IF
SET FSO=Nothing ' Clean everything up.
SET WSH=Nothing
SET txtFile=Nothing
SET AppToRun=Nothing
' End of Script
Copy the above and paste into a .VBS file - in this instance if there's no file called 'test.xxx' on the root of drive C, NotePad will be launched.
Hope that helps,