[Incident]: Some users report they are unable to access the case portal. Please see this community notice for more information.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
MEinstaller
Level 7

Need to read Env. Variable and rename a file accordingly

I need to be able to read in the environment variables in my Windows install and depending on the value of one of the variables, which is a version of the software for that variable. Once I have the value which is either 12 or 15, I need to rename one of my exes to xxxxx15.exe and xxxxx12.exe to just xxxxx.exe according to the value returned. I see in the API that there is a getVariable method however I don't see that it returns the value for the variable. Has anyone else done this before?
Labels (1)
0 Kudos
6 Replies
RobertDickau
Flexera Alumni

You might see if $E(VARIABLE_NAME) works for you; in code, you can wrap that in resolveString...
0 Kudos
MEinstaller
Level 7

Will that return the value of the Env. variable though? The value is what I really need. I also thought about looking at the registry entries but I have not found anything that returns the value in the key either.
Maybe I am misreading the documentation. Any other suggestions?
0 Kudos
RobertDickau
Flexera Alumni

Yes, for example try putting $E(USERNAME) on a dialog box and verifying that the value is returned.

The System Utility Service also provides methods for programmatically reading the values of environment variables, if you prefer to create a custom bean.
0 Kudos
MEinstaller
Level 7

I'm still having some problems with env variables, I'm hoping someone can help me. Does my build system need to have the env. variable that I am searching for in my installer? This doesn't make sense to me but thought I would ask.

I'm pulling in a Sybase variable from the system that the installer is going to be run from.
String ocs = arg0.resolveString( "$E(SYBASE_OCS)" );

ocs returns with the correct value, OCS-15_0 or whatever version it happens to be. From here I am trying to rename a dll accordingly and that is where I am having problems. No file ever gets renamed, all I get is the message that no DLL was renamed.This custom event is the last thing to run in the installer so I don't think that is an issue. Is there something wrong with my code?


String fifteen = "OCS-15_0";
String twelve = "OCS-12_5";
String instLoc = arg0.resolveString( "$P( absoluteInstallLocation )" );
FileService fileCop = ( FileService )arg0.getService( FileService.NAME );
if ( ocs == fifteen ) {
fileCop.copyFile( instLoc + "//bin//lib.dll.sybase15", instLoc + "//libDMdb_nt.dll", true);
JOptionPane.showMessageDialog( null, "Your sybase15 dll was renamed" );
}else if ( ocs == twelve ) {
fileCop.copyFile( instLoc + "//bin//lib.dll.sybase12", instLoc + "//libDMdb_nt.dll", true );
JOptionPane.showMessageDialog( null, "Your sybase12 dll was renamed " );
} else {
JOptionPane.showMessageDialog( null, "No dll was renamed" );
}
0 Kudos
RobertDickau
Flexera Alumni

When comparing two Java String quantities, perhaps try String.equals (or String.equalsIgnoreCase or String.compareTo) instead of ==?
0 Kudos
MEinstaller
Level 7

Thanks Robert, I happened to notice my programming error this morning.
0 Kudos