user3347448
user3347448

Reputation: 1

VB Script for creating and deleting text file if certain software is installed?

I am trying to create a .vbs to create a text document that is only created if Chrome is installed. This will then run as a .bat on start up on every pc so I can see if this software is installed. This seems to work but need some help making it work correctly

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") Then

   outFile="C:\Script\test3.txt"

   Set objFile = objFSO.CreateTextFile(outFile,True)

   objFile.Write "Chrome Installed" & vbCrLf

   objFile.Close

Else
    Wscript.Quit
End If

So what I want it to do is:

  1. Create the test3.txt file as PC NAME + Chrome (Eg: Comp123-Chrome.txt) Something like (Set objFile = FSO.CreateTextFile("C:\Script\" & SysName & "-Chrome.txt", True) but not quite sure how that would fit in to the script above.

  2. At the "ELSE" part (So if Chrome.exe is not there and FALSE). It will delete the txt file created by point 1. (This is so I know that chrome has been removed the next time the script has run rather than keep the .txt file there forever)

Upvotes: 0

Views: 516

Answers (1)

Bond
Bond

Reputation: 16311

You can get the computer name like so:

Name = CreateObject("WScript.Network").ComputerName

So now outfile becomes:

outFile = "C:\Script\" & Name & "-Chrome.txt"

To delete a file, simply use the DeleteFile() method of your FSO:

objFSO.DeleteFile outFile

You'll want to create your outFile path before your If statement, though, so it's available for both your If and your Else.

Upvotes: 0

Related Questions