Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Creating BATCH file with InstallShield Professiona


8 replies to this topic

cyrus4j

cyrus4j
  • Members
  • 5 posts

Posted 16 January 2004 - 21:12

Hi all,
we are using installshield Professional 6.0 to package our application for distribution and while installing we need to create a batch file that contains certain information about the local 'System'.
I would like to know if this could be done with installshield and an example would be greatly appreciated.

Thanks in advance,
Cyrus

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 17 January 2004 - 01:11

Well you would create a file with a BAT extenstion to get a handle, write lines out to a it, and then close the file handle by using the available commands of CreateFile, WriteLine, and CloseFile respectively..

What kind of local 'System' information are you looking for though, so I can put together an example? Let me know.

Edited by Taco Bell, 17 January 2004 - 01:12.

user posted image

cyrus4j

cyrus4j
  • Members
  • 5 posts

Posted 17 January 2004 - 01:26

I would want to create this batch file after the users install Java 1.4.1 and I would like to get the path where they installed it. I guess the key would be something like "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.4.1\JavaHome" which could contain value like "C:\selected_folder\jdk1.4.1\jre".
My batch file should contain these:
set path="C:\selected_folder\jdk1.4.1";%PATH%
java -jar myjarfile.jar

I sincerely appreciate it.

Cyrus

Perotin

Perotin
  • Full Members
  • 407 posts

Posted 19 January 2004 - 14:15

With java 1.4 you don't need it in the path anymore.
Java installs a java.exe and javaw.exe into the WINSYSDIR, which should be in the path.
So if you run "java -jar myjarfile.jar", WINSYSDIR ^ java.exe is started, asks the registry, if it is the installed version, gets the path to the installed JRE and runs that java.exe (I suppose that is the way it goes ...)
You can add the java directory to the path, but (like you did in the example) make sure, it is before other JREs that may be in the path as well ... but that may disturb third party software, that have their jre 1.1.x in the path!

just my 0.02 € ...
Gruß / regards
Thomas

cyrus4j

cyrus4j
  • Members
  • 5 posts

Posted 20 January 2004 - 17:55

Hi Taco Bell,
did you get a chance to look at my reply.

Thanks,
Cyrus.

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 21 January 2004 - 01:46

Based on Perotin's reply, I was waiting to see if you still wanted the example.

In that case, I'll work on it tomorrow.
user posted image

cyrus4j

cyrus4j
  • Members
  • 5 posts

Posted 21 January 2004 - 01:57

Yes, I still want the example cos, it is exactly for the reason that Perotin said that I want the path information for Java 1.4.1 from the registry. My application needs to be run with JRE 1.4.1 and I need the path to be set in my batch file so that it remains for that session only.
Moreover, Perotin overlooked my concern that the users could have more than one JRE installed.

Thank you,
Cyrus


Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 22 January 2004 - 15:49

Sorry for not getting this to you yesterday as planned, but I left work early that day and got home late.

However, I have it now and I've confirmed it works, so here you go.

CODE
#define JRE_REG_KEY       "SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.4.1"    
#define JRE_REG_VALUE     "JavaHome"
#define JRE_DISPLAY_NAME  "Java Runtime Environment v1.4.1"


STRING szMsg, szBatchFilename, szKey, svValue, szName, szJavaDir;
NUMBER nResult, nResult1, nResult2, nvType, nvSize, nvFileHandle;


program
 // HARD-CODED VALUES FOR THE EXAMPLE
 TARGETDIR = "C:\\Program Files\\TargetFolder";
 szBatchFilename = "javapath.bat";
 
 // LOCATE THE JRE
 RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
 szKey = JRE_REG_KEY;
 szName = JRE_REG_VALUE;
 nvType = REGDB_STRING;
 nResult1 = RegDBGetKeyValueEx(szKey, szName, nvType, svValue, nvSize);
 nResult2 = ExistsDir(svValue);
 
 if (nResult1 = 0 && nResult2 = 0) then
   szJavaDir = svValue;
   
   // CREATE THE BATCH FILE FOR THE JRE
   nResult1 = OpenFileMode(FILE_MODE_APPEND);    
   nResult2 = CreateFile(nvFileHandle, TARGETDIR, szBatchFilename);
   if (nResult1 = 0 && nResult2 = 0) then
     nResult1 = WriteLine(nvFileHandle, "set path=\""+szJavaDir+"\";%PATH%");
     nResult2 = WriteLine(nvFileHandle, "java -jar myjarfile.jar");
 
     if (nResult1 < 0 || nResult2 < 0) then
       MessageBox("WARNING: Unable to write to the file '"+TARGETDIR^szBatchFilename+"'.", WARNING);
     endif;
           
   else
     MessageBox("WARNING: Unable to create the file '"+TARGETDIR^szBatchFilename+"'.", WARNING);
   endif;
 else
   MessageBox("WARNING: Unable to locate the "+JRE_DISPLAY_NAME+".", WARNING);
 endif;  
endprogram

There are few things I should point out though.

The first is a minor thing. That being I replaced the tabs with 2 spaces to preserve the formatting of the post, but an original copy of the code is attached to this reply.

The second thing is that I have this code in an old-school program block to speed up its development & testing, but you can just rip that out and/or throw it in your own function call.

The third & final thing is a limitation of CreateFile and for that I'll simply quote the help:

QUOTE
The CreateFile function's actions are not logged for uninstallation when logging is enabled. If you want a file that's created by CreateFile to be logged for uninstallation, transfer a starter file with the filename you want to the target system using XCopyFile while logging is enabled. You enable and disable logging with the Enable and Disable functions. XCopyFile actions are logged when logging is enabled, so the starter file will be logged for uninstallation. After transferring the logged starter file, you can write to or overwrite the logged starter file using CreateFile and other file-related functions. The filename must remain unchanged or it won't be found during uninstallation.

So pretty easy to workaround. Just add a template batch file to one of your file groups then to cover the uninstall support.

Attached Files


Edited by Taco Bell, 22 January 2004 - 15:49.

user posted image

cyrus4j

cyrus4j
  • Members
  • 5 posts

Posted 12 February 2004 - 23:24

Hi Taco,
thanks so much for that.

We did not get a chance to work on that part of the installation yet. Will let you know how it went then.