Bladey001
asked on
batch script help - uninstalling and installing program(s)
Dear experts,
I'm not much of a script writer and need some help!
I need a script e.g. batch script to run on startup to do the following:
BTW 'Application X' installs to a different path depending on whether the local machine is WinXP or Win 7. So ideally if there's just a way to see if the program is installed at all rather than looking to see whether a file exists in C:\ somewhere.
Hope this makes sense!
I'm not much of a script writer and need some help!
I need a script e.g. batch script to run on startup to do the following:
1.
Uninstall 3 programs, I have the msiexec code numbers so this is pretty straightforward using msiexec /x {number}2.
Trickier bit. Check to see if program "Application X" is installed. If it is go to 'end' If not install from \\server\applicationx.msiBTW 'Application X' installs to a different path depending on whether the local machine is WinXP or Win 7. So ideally if there's just a way to see if the program is installed at all rather than looking to see whether a file exists in C:\ somewhere.
Hope this makes sense!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys i'll test these out but, I need to add a small step in between 1 & 2. Can you include something that will delete some specific files e.g.
DEL "C:\Program Files\file.txt"
DEL "C:\Program Files\file2.txt"
Sorry to be a pain!
Thanks!
DEL "C:\Program Files\file.txt"
DEL "C:\Program Files\file2.txt"
Sorry to be a pain!
Thanks!
You can use vbscript for that as well:
Sub DeleteAFile(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(filespec)
End Sub
So to use tagit's function, add it to the bottom of the code of your choice (VBS that is) and then at the point you want to delete files, add
Although I would also change
To
So that it forces the file deletion.
Rob.
DeleteAFile "C:\Files\MyFile.txt"
Although I would also change
fso.DeleteFile(filespec)
To
fso.DeleteFile filespec, True
So that it forces the file deletion.
Rob.
That's a good point made by Rob - you don't want any confirmation boxes popping up.
Or you could compile the following AutoIT Script (Not Tested) as an executable
#NoTrayIcon
Global $REG_GUIDS[5]
$REG_GUIDS[0] = 3
$REG_GUIDS[1] = '{Guid1}'
$REG_GUIDS[2] = '{Guid2}'
$REG_GUIDS[3] = '{Guid3}'
$REG_GUIDS[4] = '{New Application Guid}'
Global $REG_UNINSTALL = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
;Uninstalls if the programs exist
For $x = 1 To $REG_GUIDS[0]
If RegRead($REG_UNINSTALL & '\' & $REG_GUIDS[$x], 'DisplayName') Then RunWait('MSIExec.exe /x' & $REG_GUIDS[$x] & ' /QN /NORESTART')
Next
If FileExists(@ProgramFilesDir & '\file1.txt') Then FileDelete(@ProgramFilesDir & '\file1.txt')
If FileExists(@ProgramFilesDir & '\file2.txt') Then FileDelete(@ProgramFilesDir & '\file2.txt')
If Not RegRead($REG_UNINSTALL & '\' & $REG_GUIDS[4], 'DisplayName') = 'New Application Name' Then
RunWait('Msiexec.exe /i "' & @ScriptDir & '\MSI Path.msi" /QN /NORESTART')
EndIf
Open in new window
Use WMI and vb script for enumerating installed programs. This will help find what's installed on a computer:
http://technet.microsoft.com/en-us/library/ee156540.aspx
I would try using IdentifyingNumber, SKUNumber before Description or Name due to matching strings is a lot harder than numbers. You would obviously need to know these attributes of each product and instead of outputting to a file as described below, you would test if it matches the description of the products you are wanting to have installed.
Open in new window