Script to check whether a file / folder exists
Hi,
I am a new to msi script. I am facing a problem. I need to check whether a file exists or not and accordingly needs to update/increment the registry value while installating a product. Can anyone please share a piece of code(script) to find the list of file and accordingly check whehter files exists or not. If exists then update the registry value. The same thing applies to uninstall. i need to check whether file exists or not and accordingly decrement the registry value. if registry value is '0' then delete the file.
Thanks in advance,
/Sudhi
I am a new to msi script. I am facing a problem. I need to check whether a file exists or not and accordingly needs to update/increment the registry value while installating a product. Can anyone please share a piece of code(script) to find the list of file and accordingly check whehter files exists or not. If exists then update the registry value. The same thing applies to uninstall. i need to check whether file exists or not and accordingly decrement the registry value. if registry value is '0' then delete the file.
Thanks in advance,
/Sudhi
0 Comments
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
supergrid
16 years ago
The following code may be useful to you.
The first time you install an application it creates an entry in the registry.
When you go to reinstall the same application an incremental count is created.
The same code can be used for application uninstalls.
Note: replace MYAPPS with a name more useful to you.
Good Lucj
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
Function Get_ApplicationReg()
On Error Resume Next
Dim tmp
Get_ApplicationInstalled = False
tmp = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\Installed")
If tmp = "True" Then
Get_ApplicationReg = True
End If
End Function
Sub Set_ApplicationReg()
On Error Resume Next
Dim Count
Select Case bApplicationInstalled
Case False
Call oShell.RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\Installed", "True", "REG_SZ")
Case True
Count = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\ReinstallCount")
Count = Count + 1
Call oShell.RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\ReinstallCount", Count, "REG_SZ")
End Select
End Sub
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
The first time you install an application it creates an entry in the registry.
When you go to reinstall the same application an incremental count is created.
The same code can be used for application uninstalls.
Note: replace MYAPPS with a name more useful to you.
Good Lucj
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
Function Get_ApplicationReg()
On Error Resume Next
Dim tmp
Get_ApplicationInstalled = False
tmp = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\Installed")
If tmp = "True" Then
Get_ApplicationReg = True
End If
End Function
Sub Set_ApplicationReg()
On Error Resume Next
Dim Count
Select Case bApplicationInstalled
Case False
Call oShell.RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\Installed", "True", "REG_SZ")
Case True
Count = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\ReinstallCount")
Count = Count + 1
Call oShell.RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\MYAPPS\Installed Applications\" & sfTitle & "\ReinstallCount", Count, "REG_SZ")
End Select
End Sub
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
Posted by:
anonymous_9363
16 years ago
Go to http://www.devguru.com/technologies/vbscript/home.asp. Search for 'FileSystemObject'. In there you'll find 'FileExists' and 'FolderExists' methods and some rather sparse sample code. For more code examples of actually using those methods, try http://www.computerperformance.co.uk/vbscript/index.htm
Posted by:
revizor
16 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.