Sign in to follow this  
Followers 0
jinbaba

Include file selection based on @OSVersion

3 posts in this topic

Hello Folks,

I have a script that is to run on both Vista and XP. Some files are only present in XP and some only for Vista.

What I wanted to do was to include certain files only if OS is Vista and vice versa. The code I wrote is

If @OSVersion == 'WIN_VISTA' Then   
    #include<Vista_Library1.au3>
ElseIf @OSVersion == 'WIN_XP' Then  
    #include<XP_Library1.au3>
EndIf

When I execute my script on XP I get "ERROR: can't open include file <Vista_Library1.au3>" and on Vista I get error "ERROR: can't open include file <XP_Library1.au3>".

The question is how I can avoid this error, are there any language keyword for this situation?

Regards,

Jinbaba

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello Folks,

I have a script that is to run on both Vista and XP. Some files are only present in XP and some only for Vista.

What I wanted to do was to include certain files only if OS is Vista and vice versa. The code I wrote is

If @OSVersion == 'WIN_VISTA' Then   
    #include<Vista_Library1.au3>
ElseIf @OSVersion == 'WIN_XP' Then  
    #include<XP_Library1.au3>
EndIf

When I execute my script on XP I get "ERROR: can't open include file <Vista_Library1.au3>" and on Vista I get error "ERROR: can't open include file <XP_Library1.au3>".

The question is how I can avoid this error, are there any language keyword for this situation?

Regards,

Jinbaba

Why not just include both UDFs with your script? Or write the script so that both could be included and supply a compiled version.

Otherwise, you could make another little script which starts your script.

Say your script is called MyScript.au3, then save it as MyScript01.au3 or any other name, but without either of those #include lines.

Write a small scipt called MyScript.au3 like this

If @OSVersion = 'WIN_VISTA' Then    
    $OSinclude = "#include <Vista_Library1.au3>"
ElseIf @OSVersion = 'WIN_XP' Then   
    $OSinclude = "#include <XP_Library1.au3>"
Else
  MsgBox(262144,"ERROR","@OSVersion is not supported by this script!")
 exit
EndIf

$text = $OSinclude & @CR & FileRead("MyScript01.au3")
FileWrite("MyScriptA.au3",$text)
$AutoItexePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir");installDir for production version

Run('"' & $AutoItexePath & '\AutoIt3.exe "' & ' "' & @ScriptDir & '\MyScriptA.au3"' )
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#include <something.au3> just tells compilator to place external source into this position

it isn't dependend on If/Else it places sources always at compilation time.

You should include all (both) include files and call appropriate functions (not includes) based on OS version.

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