Installed Path

Hi,

How do I find the installed path of a particular application using VB Script?

Thanks
shersuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pradapkumarCommented:
u can use
App.Path

to know ur application's installation path

to achieve it correctly paste the above line in startup module.

try this to know in msgbox

MsgBox App.Path
0
shersuAuthor Commented:
But my purpose is to get the folder location of AutoCAD 2006 Application using VB Script.

Thanks
0
Leo EikelmanDirector, IT and Business DevelopmentCommented:
This really isn't a simple question, but here is a script that does sort of what you want.  It will find a certain file no matter where it is located on your PC.  So you can look at this an dI'm sure it will help you with your question.


Option Explicit

Dim Copout As Boolean

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
         (ByVal hWnd As Long, ByVal lpOperation As String, _
         ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory _
         As String, ByVal nShowCmd As Long) As Long

Sub SearchFolder(fso As Scripting.FileSystemObject, _
         Fldr As Scripting.folder, FileName As String)

' Searchs a folder

Dim Fil As Scripting.File
Dim Fol As Scripting.folder
Dim fols As Scripting.Folders
Dim FullPath As String
Dim fnam As String
Dim d As String
Dim ok

' Search files in folder
If InStr(Fldr.Path, "System Volume Information") > 0 Then
    Exit Sub
End If

fnam = Fldr.Path ' make sure the path ends with \

If Right(fnam, 1) <> "\" Then fnam = fnam + "\"

d = Dir(fnam + FileName) ' use vb Dir function
Do While Len(d)
    ok = LaunchOK(fnam + d)
    Copout = True ' remove this for mutiple occurance
    Exit Sub      ' ditto
   
    d = Dir() ' find next
Loop

' look for sub folders
Set fols = Fldr.SubFolders
     
For Each Fol In fols
  SearchFolder fso, Fol, FileName
  If Copout Then Exit Sub
Next

End Sub

Function LaunchOK(FileName As String, Optional Params As String = "", _
            Optional OpenMode As String = "Open")

    ' Launch an app based on file extennsion.
   
    Dim lr As Long
    Dim folder As String
   
    folder = FolderName(FileName)
    If Right(folder, 1) = ":" Then
      folder = folder + "\"
    End If
   
    lr = ShellExecute(0, OpenMode, FileName, Params$, folder$, vbNormalFocus)
    DoEvents
    If (lr < 0) Or (lr > 32) Then
      LaunchOK = True
    Else
      LaunchOK = False
    End If
   
End Function


Function FolderName(FileName As String) As String
    ' get folder name

    Dim folder As String
    Dim lr As Long
    folder = FileName
    lr = Len(folder)
    Do While lr > 1
      If Mid(folder, lr, 1) = "\" Then
          folder = Left(folder, lr - 1)
          Exit Do
      End If
      lr = lr - 1
    Loop
   
    FolderName = folder
   
End Function

Private Sub Command1_Click()

    Dim fso As New Scripting.FileSystemObject
   
    Dim MyDrives As Scripting.Drives
    Dim Drive As Scripting.Drive
    Dim Fldr As Scripting.Folders
    Dim Root As Scripting.folder
   
    Dim FileName As String
   
   
    FileName = InputBox("Enter Search File", "Search")
   
    Dim t As Date
   
   
    Dim StoreMouse As Long
    StoreMouse = Screen.MousePointer ' go practice to save the current mouse
    Screen.MousePointer = vbHourglass
    DoEvents: DoEvents
   
    t = Now ' take time
   
    ' search drives
    For Each Drive In fso.Drives
        If Drive.DriveType = Fixed Then
          Set Root = fso.GetFolder(Drive.DriveLetter + ":\")
          SearchFolder fso, Root, FileName
          If Copout Then Exit For
        End If
    Next
   
    Screen.MousePointer = StoreMouse ' restore mouse
       
    Set Root = Nothing
    Set fso = Nothing
   
    MsgBox "TIME TAKEN: " + Format(DateDiff("s", t, Now), "0.00")

End Sub



Cheers,

Leo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

nffvrxqgrcfqvvcCommented:
are you using Visual Basic? or are you using VBScript??
0
DeadlyTrevCommented:
Below is a function (in VB6, sorry, not VBScript, although should be easy to convert) that will do what you want.  Beware, however!!  It is up to the ACAD installer if it populates the InstallLocation property.  Many installed apps on my system don't have this value (but most of the big ones do...).

In VB6 I accessed the WindowsInstaller object by adding a reference and browsing to MSI.DLL.  With VBScript, replace the Dim installer as WindowsInstaller.installer line with Dim installer as Object.


Private Function GetInstallPath(insProductName As String) As String

    Dim installer As WindowsInstaller.installer
    Dim productcode As String
    Dim productname As String
    Dim i As Integer
    Dim tmp As String

    GetInstallPath = ""
    Set installer = CreateObject("WindowsInstaller.Installer")
    For i = 1 To installer.Products.Count
        productcode = installer.Products.Item(i - 1)
        productname = installer.ProductInfo(productcode, "InstalledProductName")
        If UCase$(CStr(productname)) = UCase$(insProductName) Then
            GetInstallPath = installer.ProductInfo(productcode, "InstallLocation")
            Exit For
        End If
    Next
    Set installer = Nothing

End Function
0
shersuAuthor Commented:
I am using vb script. I will give a try to both the codes that are given here.

Thanks
0
DeadlyTrevCommented:
VBScript version ...
------------------------------------------------------------------------

insProductName = "<your installed appname here>"
GetInstallPath = ""
Set installer = CreateObject("WindowsInstaller.Installer")
For i = 1 To installer.Products.Count
    productcode = installer.Products.Item(i - 1)
    productname = installer.ProductInfo(productcode, "InstalledProductName")
    If UCase(CStr(productname)) = UCase(insProductName) Then
        GetInstallPath = installer.ProductInfo(productcode, "InstallLocation")
        Exit For
    End If
Next
Set installer = Nothing
If GetInstallPath = "" then
    MsgBox("Install path for " & insProductName & " not found")
else
    MsgBox("Install path for " & insProductName & " = " & GetInstallPath)
End If
0
shersuAuthor Commented:
Ok. Let me explain my requirement. I am trying to locate the path of AutoCAD 2006 Application in a system. This is needed since certain PCs are 64 bit in our company. So by default, every application is getting installed in a folder in C drive called Program Files(X86), whereas, there is also a folder called Program Files like any other system. If I run the VB Script from the network, how do I know if the application is installed in Program Files folder or Program Files(X86) folder in the user's PC?
0
Leo EikelmanDirector, IT and Business DevelopmentCommented:
Have you tried the code I posted?

It should find the installed path.

Leo
0
DeadlyTrevCommented:
Shersu,

The script I posted tells you what path an application was installed to.  eg.  If it was installed to C:\Program Files\Discreet\Autocad then that's what would be returned.  If it was installed to C:\Program Files(x86)\Autodesk\ACAD then that's what would be returned. etc. etc.

Note:  This may work for autocad or may not ... you need to try it out.  It depends on how standards-compliant the autocad installer is.   If this (very fast) method does not work then Leikelman's slow-but-sure method will.

Your original post said nothing about working remotely...  !  That is a different kettle of fish.   Leikelman's solution is local too.

However, you can remote execute my vbscript  :-).
Search EE and you'll find a whole bunch of answers on remote-execution of a vbscript.
0
shersuAuthor Commented:
leikelman,

Your code didn't help as I have to specify the Install Location and that is what I am trying to find!

DeadlyTrev,

How do I add a function to a VB Script?

Thanks
0
DeadlyTrevCommented:
Shersu,

You just define it inline with your script.

eg.
---------------------------------------------------------
Private Function GetInstallPath(insProductName)

    GetInstallPath = ""
    Set installer = CreateObject("WindowsInstaller.Installer")
    For i = 1 To installer.Products.Count
        productcode = installer.Products.Item(i - 1)
        productname = installer.ProductInfo(productcode, "InstalledProductName")
        If UCase(CStr(productname)) = UCase(insProductName) Then
            GetInstallPath = installer.ProductInfo(productcode, "InstallLocation")
            Exit For
        End If
    Next
    Set installer = Nothing

End Function


MsgBox(GetInstallPath("TheApplication'sAdd/RemoveName"))
---------------------------------------------------------
0
shersuAuthor Commented:
Yes, I did! But I get a blank message box in return...that is...it is not retrieving the InstallLocation of AutoCAD.

Thanks
0
DeadlyTrevCommented:
There are two possible reasons ...  1. The string you are using doesn't match AutoCad's registry entry.  or  2. AutoCad's installer doesn't set up the InstallLocation property.

If #2 then you're probably stuck with searching the whole hard drive (leikelman method), unless you can find a consistant pointer to the install path (like an .INI file that the installer leaves in the Windows folder).

EXACTLY which version of which AutoCad are you checking for?
0
nffvrxqgrcfqvvcCommented:
If you have visual basic this would be easy, if your only means of going about this is vbscript than it would be easiest to create an activex.dll in VB and then call it by VBscript.
0
shersuAuthor Commented:
I think it's the problem #2.

I am using Architectural Desktop 2006.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.