[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

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.FileSystemObject")
   Set WSH = CreateObject("Wscript.Shell")

   ' 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
0
sid20vt
Asked:
sid20vt
1 Solution
 
fostejoCommented:
sid20vt,

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.FileSystemObject")
Set WSH = CreateObject("Wscript.Shell")

' 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,
0
 
cschipperCommented:
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.FileSystemObject")
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
0
 
sid20vtAuthor Commented:
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.
0
 
CetusMODCommented:
PAQed with points refunded (260)

CetusMOD
Community Support Moderator
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now