We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Installed Path

shersu
shersu asked
on
Medium Priority
546 Views
Last Modified: 2012-05-05
Hi,

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

Thanks
Comment
Watch Question

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

Author

Commented:
But my purpose is to get the folder location of AutoCAD 2006 Application using VB Script.

Thanks
Director, IT and Business Development
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2010

Commented:
are you using Visual Basic? or are you using VBScript??
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

Author

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

Thanks
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

Author

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?
Leo EikelmanDirector, IT and Business Development

Commented:
Have you tried the code I posted?

It should find the installed path.

Leo
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.

Author

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
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"))
---------------------------------------------------------

Author

Commented:
Yes, I did! But I get a blank message box in return...that is...it is not retrieving the InstallLocation of AutoCAD.

Thanks
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?
Top Expert 2010

Commented:
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.

Author

Commented:
I think it's the problem #2.

I am using Architectural Desktop 2006.

Thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.