WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Batch file not recognizing the environment variable
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
sandeepsirsgi
Junior Member

Registered: May 2006
From: INDIA

Unhappy Batch file not recognizing the environment variable

Hi,

I am able to set the environment variable by using following following NSIS script.

Push JAVA_HOME
Push "d:\JDK1.5"
Call WriteEnvStr

After that i am running a batchfile using NSIS which is refering the JAVA_HOME to execute the batch.
But the .bat file is not recognizing the environment variable JAVA_HOME.
If i run that .bat file through command prompt then it's working.

Can any one help me on that.

Regards
sandy

Quick Link | Report this post to a moderator | IP: Logged

sandeepsirsgi is offline Old Post 12-16-2006 05:40 AM
Click Here to See the Profile for sandeepsirsgi Click here to Send sandeepsirsgi a Private Message Click Here to Email sandeepsirsgi Find more posts by sandeepsirsgi Add sandeepsirsgi to your buddy list Edit/Delete Message Reply w/Quote
kichik
M.I.A.
[NSIS Dev, Mod]

Registered: Oct 2001
From: Jerusalem, Israel

Setting environment variables this way doesn't affect running processes. Use SetEnvironmentVariable
for that.

__________________
NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius

Quick Link | Report this post to a moderator | IP: Logged

kichik is offline Old Post 12-16-2006 10:25 AM
Click Here to See the Profile for kichik Click here to Send kichik a Private Message Visit kichik's homepage! Find more posts by kichik Add kichik to your buddy list Edit/Delete Message Reply w/Quote
sandeepsirsgi
Junior Member

Registered: May 2006
From: INDIA

I am running a batch file which is refering to JAVA_HOME and
taking APP_HOME as classpath. I am able to set environment variable by using following NSIS script.

Push JAVA_HOME
Push "d:\JDK1.5"
Call WriteEnvStr
Push APP_HOME
Push "d:\application"
Call WriteEnvStr

ReadEnvStr $R0 "PATH"
StrCpy $R0 "$R0;$TEMP2;$TEMP1"
SetEnv::SetEnvVar "PATH" "$R0"
Exec batchfile.bat

Here $TEMP1 and $TEMP2 contains path to java_home
and batch file respectively. When batch file is executed
it's not able to recognize

Still not able to execute batch file.

Quick Link | Report this post to a moderator | IP: Logged

sandeepsirsgi is offline Old Post 12-18-2006 06:00 AM
Click Here to See the Profile for sandeepsirsgi Click here to Send sandeepsirsgi a Private Message Click Here to Email sandeepsirsgi Find more posts by sandeepsirsgi Add sandeepsirsgi to your buddy list Edit/Delete Message Reply w/Quote
Red Wine
Forum King

Registered: Mar 2006
From: Ath. GR

Case 1.
If you want to set an environment variable only for the installer process and its sub-processes use:

code:
!define JAVA_HOME "d:\JDK1.5" !define APP_HOME "d:\application" Section "Add Env Var" ReadEnvStr $R0 "PATH" messagebox mb_ok '$R0' StrCpy $R0 "$R0;${JAVA_HOME};${APP_HOME}" System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r2' ReadEnvStr $R0 "PATH" messagebox mb_ok '$R0' exec 'batchfile.bat' SectionEnd


Case 2.
If you want to set an environment variable that will stick for every other process and after reboots too...
code:
!define JAVA_HOME "d:\JDK1.5" !define APP_HOME "d:\application" !include WriteEnvStr.nsh Section "Add Env Var" !ifdef ALL_USERS !define ReadEnvStr_RegKey \ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' !else !define ReadEnvStr_RegKey 'HKCU "Environment"' !endif Push JAVA_HOME Push '${JAVA_HOME}' Call WriteEnvStr Push APP_HOME Push '${APP_HOME}' Call WriteEnvStr ReadEnvStr $R0 "PATH" messagebox mb_ok '$R0' ;ensure that is written valid for NT only ReadRegStr $0 ${ReadEnvStr_RegKey} 'JAVA_HOME' ReadRegStr $1 ${ReadEnvStr_RegKey} 'APP_HOME' StrCpy $R0 "$R0;$0;$1" ;or just this ;StrCpy $R0 "$R0;${JAVA_HOME};${APP_HOME}" System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r2' ReadEnvStr $R0 "PATH" messagebox mb_ok '$R0' writeuninstaller '$EXEDIR\uninst.exe' exec 'batchfile.bat' SectionEnd # ... Section uninstall # remove the variable Push JAVA_HOME Call un.DeleteEnvStr Push APP_HOME Call un.DeleteEnvStr SectionEnd

__________________
Quick AVI Creator - Quick and easy convert from DVD/MPEG/AVI/MKV to AVI/MP4/MKV
Quick AVI Creator entirely edited with NSIS and entirely upgraded to Unicode NSIS

Last edited by Red Wine on 12-18-2006 at 12:25 PM

Quick Link | Report this post to a moderator | IP: Logged

Red Wine is offline Old Post 12-18-2006 12:10 PM
Click Here to See the Profile for Red Wine Click here to Send Red Wine a Private Message Find more posts by Red Wine Add Red Wine to your buddy list Edit/Delete Message Reply w/Quote
sandeepsirsgi
Junior Member

Registered: May 2006
From: INDIA

Sorry for late reply.
It worked for me.


Regards
Sandeep

Quick Link | Report this post to a moderator | IP: Logged

sandeepsirsgi is offline Old Post 01-08-2007 04:38 AM
Click Here to See the Profile for sandeepsirsgi Click here to Send sandeepsirsgi a Private Message Click Here to Email sandeepsirsgi Find more posts by sandeepsirsgi Add sandeepsirsgi to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 09:33 AM. Post New Thread    Post A Reply
  Last Thread   Next Thread
WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Batch file not recognizing the environment variable
Show Printable Version
 | 
Email this Page
 | 
Subscribe to this Thread

Forum Jump:
 

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is off
vB code is ON
Smilies are ON
[IMG] code is ON