Old 6th February 2003, 10:18   #1
kikolo
Junior Member
 
kikolo's Avatar
 
Join Date: Jan 2003
Location: SnSn - Spain
Posts: 10
Unhappy Environment Variables:: Write/Change Them?

I have read some posts about how to write Environment Variables Permantently, but i need to write/set them on install running to test the DB Connection.
The program that connects with DataBase reads Settings from Environment Variables like DBDATE, DBTEMP, DBSERVER and others that the installer sets into installoptions 'forms'/'pages', but i need them on the environment to test the connection on the next page, but i only read about reading env. vars. and write them on the registry or the autoexec, but this option needs to reboot.
Resume: How Can I write/change Env. Vars. on installer execution?
Thanks
kikolo is offline   Reply With Quote
Old 6th February 2003, 11:23   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
http://nsis.sourceforge.net/archive/....php?pageid=91

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 6th February 2003, 11:25   #3
Mark_Ive
Junior Member
 
Join Date: Nov 2000
Posts: 29
Hi there, this is how i would write an environment variable

WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Env Name" "Env Value"
Mark_Ive is offline   Reply With Quote
Old 6th February 2003, 11:26   #4
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
That only works on Windows NT. The functions I have posted above work with Windows 9x too.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 6th February 2003, 13:42   #5
kikolo
Junior Member
 
kikolo's Avatar
 
Join Date: Jan 2003
Location: SnSn - Spain
Posts: 10
Unhappy

RePlay: sorry about my english, but maybe i said something different that i thonk (thonk? thinked? what is the past of to think?)
Example:
One Install Script
PAge 1 Welcome
Page 2 License
Page 3 Components
Page 4 Custom Page With Input Text Boxes
Page 5 Custom Page With DB connection test
Page 6 Custon Page that shows information about connection
Page 7 Install Rest of Components
Page 8 Bye Bye

In The Page 6 i read a file written by Program on Page 5
In The Page 5 i call an executable that read the Environment Variables to Test an DataBase Connection.
In the Page 4 i do an input of the variables that i need in the Page 5.
In The solutions that you give me, i need to install,reboot and test de connection,
if the connection dont work the user must repeat the install!?!?!

Resume: How Can I Change/SetUp/Write Variables to Environment Directly during execution, not to registry, not to autoexec.bat?
kikolo is offline   Reply With Quote
Old 6th February 2003, 13:53   #6
Sunjammer
Major Dude
 
Join Date: Jun 2002
Location: Swindon, UK
Posts: 559
past of think is thought
Sunjammer is offline   Reply With Quote
Old 6th February 2003, 17:10   #7
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
I am sorry. I haven't read your question to the end.

Here is how you do it without the need to create a plug-in:
PHP Code:
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("name", "value").r0'
StrCmp $0 0 error
    Exec 
"other proggie.exe" 
Replace "name" with the name of the environment variable and "value" with it's value. Repeat this line (System::Call...) for every variable you need to set.

If you don't want to include System.dll in your installer (9KB) then you'll have to write a nice little plug-in that calls SetEnvironmentVariable.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 7th February 2003, 08:59   #8
kikolo
Junior Member
 
kikolo's Avatar
 
Join Date: Jan 2003
Location: SnSn - Spain
Posts: 10
Smile

thank you!
it works fine,
at the moment i will use the system.dll, in future... maybe a new little dll.
kikolo is offline   Reply With Quote
Old 21st February 2003, 16:04   #9
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
Does this work with nsExec as well?
Or just for the Exec functions?
---
Thanks
iceman_k is offline   Reply With Quote
Old 21st February 2003, 16:05   #10
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Yes, it works for nsExec as well as both use CreateProcess.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 10th March 2003, 09:02   #11
kikolo
Junior Member
 
kikolo's Avatar
 
Join Date: Jan 2003
Location: SnSn - Spain
Posts: 10
Unhappy

--- La Función - The Function ---
code:
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("name", "value").r0'

--- La Función - The Function ---

--- Post in Spanish ---
Hola
La función System::Call funcionó bien, hasta que empecé a realizar debug y control de errores, fue entonces cuando descubri que cada vez que se utiliza la función, el flag de error se activa, y pierdo el control de los errores, y se me escapa por algun lado.
¿tengo alguna otra manera de hacer lo mismo con otro dll ya existente?
Muchas Gracias y Saludos Totales :P
KiKoLo
--- Post in Spanish ---
--- Post in ... Spanglish? ---
Hi
The Function System::Call worked fine, but when i started to do debug and error hadler control, i discover that when i use the function, the error flag activates, and i miss the control of the error handles and it scapes anywhere.
¿Can i do the same with an existent dll?
Lots of Thanks and SALUDOS TOTALES :P
KiKoLo
--- Post in ... Spanglish? ---

--- Ejemplo - Example ---
PHP Code:
Name "Tester"
OutFile "..\bin\testing.exe"
   
Section "Testing"
      
Push $R0
      StrCpy $R0 
"I"
      
DetailPrint "DEBUG_TRACE[$0]: (REG) INFODB = [$R0]"
      
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("INFODB", "$R0").r0'
      
DetailPrint "DEBUG_TRACE[$0]: (ENV) INFODB = [$R0]"
      
Pop $R0
   SectionEnd 
--- Ejemplo - Example ---

Thank you for all darkboy
kikolo is offline   Reply With Quote
Old 10th March 2003, 20:23   #12
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,917
!define Spanish_Post

KiKoLo: Tu mensaje en el foro está bien redactado, les explicas que
tienes un error al usar el plugin System al usar Debug, y que este
error no lo puedes controlar.
Ayuda el hecho de que hayas puesto parte de tu código.


!define English_Post

KiKoLo: you post in english is ok. When you use the System plugin with
the debug and error handlers, you starting to recived error that you
can't handle...
It helps that you put part of your code.


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with MATE.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with MATE.
Joel is offline   Reply With Quote
Old 11th March 2003, 08:02   #13
kikolo
Junior Member
 
kikolo's Avatar
 
Join Date: Jan 2003
Location: SnSn - Spain
Posts: 10
Talking

I made a plugin dll (SetEnv.dll) to do this.
And Works when the other way doesnot
explanation...
PHP Code:
Name "Tester"
OutFile "..\bin\testing.exe"

   
Section "Testing"
      
Push $R0
      Push $R1
      StrCpy $R0 
"PATH"

      
ReadEnvStr $R1 "$R0"
      
MessageBox MB_OK "Before Modify Var: PATH = $R1"

      
StrCpy $R1 "C:\MYAPP;$R1"
      
MessageBox MB_OK "Before Set Env Var: PATH = $R1"

      
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("$R0", "$R1").r0'

      
ReadEnvStr $R1 "$R0"
      
MessageBox MB_OK "After Set and Get: PATH = $R1"

      
Pop $R1
      Pop $R0
   SectionEnd 
code:
Messages:
Before Modify Var: PATH = C:\Archivos de Programa\TextPad 4;P:\Bin_Unstable;D:\UTILES\MKSNT;C:\WINNT\System32;C:\WINNT;C:\WINNT\System32\WBem;"C:\Archivos de Programa\Norton\Ghost\";"C:\Archivos de programa\NullSoft\NSIS";D:\UTILES\COMP
---
Before Set Env Var: PATH = C:\MYAPP;C:\Archivos de Programa\TextPad 4;P:\Bin_Unstable;D:\UTILES\MKSNT;C:\WINNT\System32;C:\WINNT;C:\WINNT\System32\WBem;"C:\Archivos de Programa\Norton\Ghost\";"C:\Archivos de programa\NullSoft\NSIS";D:\UTILES\COMP
---
After Set and Get : PATH =



If I replace the system call with
PHP Code:
SetEnv:SetEnvVar "$R0" "$R1
It Works and the last message shows like
code:
After Set and Get : PATH = C:\MYAPP;C:\Archivos de Programa\TextPad 4;P:\Bin_Unstable;D:\UTILES\MKSNT;C:\WINNT\System32;C:\WINNT;C:\WINNT\System32\WBem;"C:\Archivos de Programa\Norton\Ghost\";"C:\Archivos de programa\NullSoft\NSIS";D:\UTILES\COMP



The file is the SetEnv Plugin, anybody knows how can i upload it to downloads section in the official page?
Thanks for everybody and...
¡¡¡Saludos Totales!!!!
yeah!

KiKoLo
NOTAS
NOTA 1: No tengo ni puta idea de C, pero con los ejemplos que tenian, y el msdn, no fue dificil hacerlo.
NOTA 2: Mi inglés es pésimo, está oxidado asi que si alguien no lo entiende, lo siento, es hasta donde puedo llegar
NOTA 3: Descomprimir quedando SenEnv como un directorio mas del Contrib debajo del NSIS (NSIS\Contrib\SetEnv) porque coge el ..\exdll\exdll.h y despues mover el setenv.dll a NSIS\Plugins

NOTES
NOTE 1: I have no idea about C, but with the examples anda with the MSDN it does not be dificult to do.
NOTE 2: Sorry about my english
NOTE 3: Extract It on a Dir behind Contrib 'cause it take the ..\exdll\exdll.h and then move the setenv.dll to NSIS\Plugins
Attached Files
File Type: rar setenv.rar (2.7 KB, 2486 views)
kikolo is offline   Reply With Quote
Old 11th March 2003, 08:19   #14
deguix
Major Dude
 
deguix's Avatar
 
Join Date: Dec 2002
Location: Everett - MA, USA
Posts: 1,354
Send a message via ICQ to deguix
Please attach in .zip, because someone could not have the WinRAR program. (I don't have!)

My Wiki Pages

Working now on:
New projects. (language: any)
deguix is offline   Reply With Quote
Old 11th March 2003, 08:32   #15
kikolo
Junior Member
 
kikolo's Avatar
 
Join Date: Jan 2003
Location: SnSn - Spain
Posts: 10
jeje, i don't have winzip
but a serious app like winrar give you the posibility to compress to an uneficient algorithm like winzip xDDDD (dont worry, is a joke)
I only have winrar 'cause it give me more flexibility and better ratios, but winzip is more... more... marketizing XD
Saludos Totales
Attached Files
File Type: zip setenv.zip (2.8 KB, 3778 views)
kikolo is offline   Reply With Quote
Old 11th March 2003, 15:12   #16
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
The problem is that you have quotes inside that environment variable. You can use it this way:

PHP Code:
StrCpy $R0 "name"
StrCpy $R1 "value"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i(R0, R1).r0'
StrCmp $0 0 error
    Exec 
"other proggie.exe" 
Replace StrCpy with whatever function you need and it should work. If it doesn't try putting a dot before R0 and R1 in the System::Call line. Try one of them, and try both, not sure which one should work.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump