Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Installed Path

Posted on 2006-03-26
18
Medium Priority
?
511 Views
Last Modified: 2012-05-05
Hi,

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

Thanks
0
Comment
Question by:shersu
  • 6
  • 5
  • 2
  • +2
16 Comments
 
LVL 9

Expert Comment

by:pradapkumar
ID: 16292685
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
 

Author Comment

by:shersu
ID: 16292732
But my purpose is to get the folder location of AutoCAD 2006 Application using VB Script.

Thanks
0
 
LVL 8

Accepted Solution

by:
Leo Eikelman earned 252 total points
ID: 16294247
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16294707
are you using Visual Basic? or are you using VBScript??
0
 
LVL 6

Expert Comment

by:DeadlyTrev
ID: 16296941
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
 

Author Comment

by:shersu
ID: 16299504
I am using vb script. I will give a try to both the codes that are given here.

Thanks
0
 
LVL 6

Expert Comment

by:DeadlyTrev
ID: 16306844
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
 

Author Comment

by:shersu
ID: 16320079
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
 
LVL 8

Expert Comment

by:Leo Eikelman
ID: 16321571
Have you tried the code I posted?

It should find the installed path.

Leo
0
 
LVL 6

Expert Comment

by:DeadlyTrev
ID: 16328315
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
 

Author Comment

by:shersu
ID: 16348586
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
 
LVL 6

Assisted Solution

by:DeadlyTrev
DeadlyTrev earned 248 total points
ID: 16357067
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
 

Author Comment

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

Thanks
0
 
LVL 6

Expert Comment

by:DeadlyTrev
ID: 16357814
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
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16358420
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
 

Author Comment

by:shersu
ID: 16518765
I think it's the problem #2.

I am using Architectural Desktop 2006.

Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question