Jump to content

finding working directory for a program


ahha
 Share

Recommended Posts

Okay a newbie question (arrows expected in the back).

I'm trying to start (run) Acrobat (acrobat.exe) without hardcoding the directory.

I've tried several approaches, searched the web and autoit forums and have come up empty.

Stripped down code in codebox.

Any help appreciated.

CODE
Run("C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe") ; Run Acrobat - this works

;However, I don't want to hardcode the directory

;Run Acrobat.exe under windows (Start->Run->Acrobat.exe) works so windows knows the path

Run("Acrobat.exe", "C:\Program Files\Adobe\Acrobat 6.0\Acrobat\") ; Run Acrobat - this DOES NOT work

Run("Acrobat.exe", "C:\Program Files\Adobe\Acrobat 6.0\Acrobat") ; Run Acrobat - this DOES NOT work

;how do i find the working directory ??

;registry entries look like they require knowing the version of the program already installed - not good

;properties window on acrobat.exe shows the Target: which is the full path/filename.

MsgBox(0+262144, "Status:", "Exiting.")

Link to comment
Share on other sites

try this.

$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2") 
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process") 
For $objItem in $colItems 
    If $objItem.Name = "Acrobat.exe" Then
        MsgBox(0,"",StringLeft($objItem.ExecutablePath,StringInStr($objItem.ExecutablePath,"\",1,-1)-1))
    EndIf
Next
Edited by Joon
Link to comment
Share on other sites

try this.

$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2") 
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process") 
For $objItem in $colItems 
    If $objItem.Name = "Acrobat.exe" Then
        MsgBox(0,"",StringLeft($objItem.ExecutablePath,StringInStr($objItem.ExecutablePath,"\",1,-1)-1))
    EndIf
Next

Joon,

Shows nothing for acrobat.exe, however, tested it with notepad.exe and got c:\WINDOWS\system32,

however then tried it with excel.exe and just like acrobat.exe the program does not show anything.

Hmm ...

Link to comment
Share on other sites

What Operating system are you running?

What version (s) of Acrobat do you need this for?

Docfxit

I'm running XP Pro. The users of the program will be running XP Pro or XP Media.

The version of Acrobat should handle 6, 7, or 8. Ideally whatever version (6 and above) that is installed on their system.

Edited by ahha
Link to comment
Share on other sites

You are not specifying the location of "acrobat.exe". As a result autoit as well as the operating system are unable to find it. Only a few programs have their names embedded in registry so that when you type their names into the windows run prompt you don't need to specify their location.

The working directory doesn't have anything to do with the program's location. A working directory is simply the directory that a program treats as its root when it is run.

You therefore simply need to specify the location of "acrobat.exe" like this:

Run("C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe", "C:\Program Files\Adobe\Acrobat 6.0\Acrobat\")

I hope that helps.

-The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

You are not specifying the location of "acrobat.exe". As a result autoit as well as the operating system are unable to find it. Only a few programs have their names embedded in registry so that when you type their names into the windows run prompt you don't need to specify their location.

The working directory doesn't have anything to do with the program's location. A working directory is simply the directory that a program treats as its root when it is run.

You therefore simply need to specify the location of "acrobat.exe" like this:

Run("C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe", "C:\Program Files\Adobe\Acrobat 6.0\Acrobat\")

I hope that helps.

-The Kandie Man

Thanks for clearing up the working directory issue (working - DUH!!!) versus location. I guess I meant the search path for finding the program. I started out as you suggested hard coding the location of the program. I was hoping since most people install it and Windows knows how to find it when users double click to open/edit PDFs that I could also discover it and code it in rather than hard coding it.
Link to comment
Share on other sites

You don't have to hard code it in there. You can read the location from the registry. I warn you though, i am using Adobe Acrobat 7 and the name of the exe is not "acrobat.exe". The name of adobe acrobat reader for me is "AcroRd32.exe". You can get the location of my AcroRd32.exe from the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\7.0\InstallPath

Though you are using a different version of adobe so it would be different.

Also, if you want to open files with it, you can do it much easier with shellexecute:

ShellExecute("OpenThisPDF.pdf")

That will open the pdf file with whatever program is associated with it, much like double clicking a pdf file.

-The Kandie Man

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Or you could try this:

; Display path to Adobe Acrobat

;  Untested on ver. 6, 8

    $un = "HKEY_CLASSES_ROOT\acrobat\DefaultIcon"
    $display=regread($un,"")

Run($display, "", @SW_MAXIMIZE)

Docfxit

That works quite nicely. I can't believe i overlooked the icon location. :P

Anyway, good job. :D

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

You don't have to hard code it in there. You can read the location from the registry. I warn you though, i am using Adobe Acrobat 7 and the name of the exe is not "acrobat.exe". The name of adobe acrobat reader for me is "AcroRd32.exe". You can get the location of my AcroRd32.exe from the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\7.0\InstallPath

Though you are using a different version of adobe so it would be different.

Also, if you want to open files with it, you can do it much easier with shellexecute:

ShellExecute("OpenThisPDF.pdf")

That will open the pdf file with whatever program is associated with it, much like double clicking a pdf file.

-The Kandie Man

Tried shellexecute however I don't know which include file is needed and my beta version did not run it either. I saw a post that had a #include "shellexecute.au3" however it was a UDF. Another had #include "_ShellExecute.au3". So okay, what include do I need and where can I find it? My help file does not list it. Also any quick way to check which version of Autoit3 and beta is running? Thanks. Edited by ahha
Link to comment
Share on other sites

@ahha: I believe I've got what you were originally hoping to find...

Someone mentioned something about programs registering their location with Windows, so the path doesn't have to be specified in the Run dialog... I can't remember who, and it doesn't seem to be in the topic review while I'm posting here, but that's beside the point. Point is, you might be surprised at how many programs ARE registered with Windows...

Anyway, here's my half-second AutoIt script to report the full executable path of my installed version of Acrobat Reader. Please be aware of the much discussed (so far) issue about the name of the actual EXE file -- acrobat.exe vs. acrord32.exe. Your mileage may vary with this script, but you can't go wrong if you try reading both acrobat.exe and acrord32.exe, then evaluating @error after each RegRead()...

MsgBox(0x0, "Acrobat AppPath", RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe", ""))

The Registry location is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths

Under the above-listed key, you'll find numerous other keys, their names matching those of the main EXE file of many programs installed on any Windows -- maybe just 2K and XP -- computer. Inside the EXE-named keys, you'll find, usually, two values: (Default) and Path. Path sometimes isn't there...

Hope this helps! :P

[right][img]style_emoticons/autoit/robot.gif[/img]One of TenSecondary Adjunct of Unimatrix Z03[/right]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...