Sign in to follow this  
Followers 0
ne0trace

Directory Check before running script...

9 posts in this topic

Hello,

I am currently writing a script for installing Adobe After Effects. What I wanted to include before the installer is running "blind" is a script which checks if the program directory (c:\program files\adobe\adobe after effects 7.0) already exists. As we are having a mixed environment of x86/x64 Windows XP Systems it has to first check if the OS is 64bit (the use \program files(x86)\adobe\...) or else, use the usual directory.

I've already found the following variable:

@ProgramFilesDir

As I am a complete newbie to Autoit (using it since friday), I don't know much about using the "if function". Could someone please help me?

Felix

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

First, I'm not familiar with the 64 bit environment, so I'm making some assumptions that might be off.

The macro @ProgramFilesDir should evaluate to wherever the correct directory based on the OS, so it should evaluate to "C:\Program Files" under XP 32 bit, and "C:\Program Files(x86)" under XP 64 bit.

So, you should just need one statement

If FileExists ( @ProgramFilesDir & '\adobe\adobe after effects 7.0' ) Then
     ; your code here
EndIf
for either OS to determine if the directory exists. Edited by JerryD

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank you for your fast response...

I just want to be sure that I understood you correctly. Your code checks whether the directory X:\Program Files\... exists and if positive, continues/stops the script?

What makes the situation so complicated (imho) is that AE7 (After Effects 7) is beeing installed to "C:\Program Files" on x86 OS and to "C:\Program Files (x86)" on x64 OS's. But windows variable is different on each OS Version.

I pasted the variables directly from Windows:

ProgramFiles=C:\Program Files

ProgramFiles(x86)=C:\Program Files (x86)

Or am I overcomplicating things here?

thank you

Felix

Edited by ne0trace

Share this post


Link to post
Share on other sites

found this topic here

http://www.autoitscript.com/forum/index.ph...6294&hl=x64

SmOke_N wrote a function to dtermine what os is running

maybe something like this might help

Dim $ProgramFilesDir

If _OSBit2() = 64 Then
    $ProgramFilesDir = @HomeDrive & "\Program Files (x86)"
Else
    $ProgramFilesDir = @HomeDrive & "\Program Files"
EndIf

If FileExists($ProgramFilesDir & "\adobe\adobe after effects 7.0") Then
    ;Code
EndIf

Func _OSBit2()
    Local $tOS = DllStructCreate("char[256]")
    Local $aGSWD = DllCall("Kernel32.dll", "int", "GetSystemWow64Directory", "ptr", DllStructGetPtr($tOS), "int", 256)
    If IsArray($aGSWD) And DllStructGetData($tOS, 1) Then Return 64
    Return 32
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I rewrote the function to make a quick check if it is working as proposed. The directory i try to check is "C:\Programme\Adobe\Adobe After Effects 7.0" and the OS is 32bit. I thought that output of the script should have been "Directory Exists". Instead it reports that the directory isn't existing.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


Dim $ProgramFilesDir

If _OSBit2() = 64 Then
    $ProgramFilesDir = @HomeDrive & "\Program Files (x86)"
Else
    $ProgramFilesDir = @HomeDrive & "\Program Files"
EndIf

If FileExists($ProgramFilesDir & "\Adobe\Adobe After Effects 7.0\") Then

    MsgBox(64,  "After Effects 7.0 Install", "IT EXISTS")
Else
    MsgBox(64,  "Test", "IT DOESN'T EXIST")
EndIf

Func _OSBit2()
    Local $tOS = DllStructCreate("char[256]")
    Local $aGSWD = DllCall("Kernel32.dll", "int", "GetSystemWow64Directory", "ptr", DllStructGetPtr($tOS), "int", 256)
    If IsArray($aGSWD) And DllStructGetData($tOS, 1) Then Return 64
    Return 32
EndFunc

Any idea what I did wrong?

Felix

Edited by ne0trace

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

What happens if you just do this without any other code:

If FileExists ( @ProgramFilesDir & "\Adobe\Adobe After Effects 7.0\") Then
    MsgBox ( 64, "After Effects 7.0 Install", "IT EXISTS" )
Else
    MsgBox ( 64, "Test", "IT DOESN'T EXIST" )
EndIf
Note that's @ProgramFilesDir - the MACRO - NOT a Vairable.

As I originally said, @ProgramFilesDir should automatically evaluate correctly. Does it?

Edited by JerryD

Share this post


Link to post
Share on other sites

What happens if you just do this without any other code:

If FileExists ( @ProgramFilesDir & "\Adobe\Adobe After Effects 7.0\") Then
    MsgBox ( 64, "After Effects 7.0 Install", "IT EXISTS" )
Else
    MsgBox ( 64, "Test", "IT DOESN'T EXIST" )
EndIf
Note that's @ProgramFilesDir - the MACRO - NOT a Vairable.

As I originally said, @ProgramFilesDir should automatically evaluate correctly. Does it?

It recognizes the directory correctly: "IT EXISTS".

So the OS_bit function isn't working in this case?

Felix

Share this post


Link to post
Share on other sites

I've found a way that works (though not elegant at all)...

If FileExists ( "C:\Program Files\Adobe\Adobe After Effects 7.0\") Or FileExists ( "C:\Program Files(x86)\Adobe\Adobe After Effects 7.0\") OR FileExists ( "C:\Programme\Adobe\Adobe After Effects 7.0\") Then
    MsgBox ( 64, "After Effects 7.0 Install", "IT EXISTS" )
Else
    MsgBox ( 64, "Test", "IT DOESN'T EXIST" )
EndIf

Felix

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Never mind...

Edited by JerryD

Share this post


Link to post
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
Sign in to follow this  
Followers 0