flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
EaxRax 18 Aug 2013, 15:19
Wrote a small program to set the environment variable, but it does not install it. Why can't I set an environment variable? What am I doing wrong?
Code: include 'C:\Program Files\FASM\INCLUDE\win32a.inc' format PE Console 4.0 entry Start section '.text' code readable executable Start: nop invoke SetEnvironmentVariableA, _data.EnvironmentName, _data.EnvironmentContents ; check for an error. test eax, eax jz Exit invoke GetEnvironmentStrings nop Exit: invoke ExitProcess, 0 section '.data' data readable writeable _data.EnvironmentName: db 'Path', 0 _data.EnvironmentContents: db 'C:\Program Files\ENVAR', 0 section '.idata' import data readable library kernel, 'KERNEL32.DLL' import kernel,\ SetEnvironmentVariableA, 'SetEnvironmentVariableA',\ GetEnvironmentStrings, 'GetEnvironmentStrings',\ ExitProcess, 'ExitProcess'
|
|||||||||||
![]() |
|
AsmGuru62 18 Aug 2013, 15:35
How did you see that it does not work?
Maybe need GetEnvironmentStringsA? |
|||
![]() |
|
AsmGuru62 18 Aug 2013, 17:09
I see... you were hoping to change the OS environment variables.
Please read this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx It describes where in the registry the environment is located. So, basically, yes, you need to write into Registry. |
|||
![]() |
|
EaxRax 18 Aug 2013, 17:18
Thanks, now I will read!
|
|||
![]() |
|
EaxRax 19 Aug 2013, 17:29
I read article. Written, need to make changes to a registry key "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\ Environment". Has looked for functions working with the registry on MSDN. Has found these functions, but so it is a lot of them, that eyes run up. And i do not know, what function should use.
Can anyone knows which function to change an environment variable in the registry? Prompt me, please! |
|||
![]() |
|
AsmGuru62 19 Aug 2013, 18:42
This tested (and worked) on XP SP3.
I am not checking any of return codes - just ran it in OLLYDBG and looked into Environment. New variable appeared OK. Code: lpSubKey db 'System\CurrentControlSet\Control\Session Manager\Environment',0 lpValue db 'MyFreshVar32',0 bufData db 'THIS VARIABLE HAS BEEN ADDED BY FASM!',0 HKey dd 0 ... invoke RegOpenKeyExA, HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_SET_VALUE, HKey mov ebx, [HKey] mov esi, bufData invoke lstrlenA, esi inc eax invoke RegSetValueExA, ebx, lpValue, 0, REG_SZ, esi, eax invoke RegCloseKey, ebx ... ; --------------------------------------------------------------------------- section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',user32,'USER32.DLL',gdi32,'GDI32.DLL',advapi32,'ADVAPI32.DLL' include 'API\Kernel32.Inc' include 'API\User32.Inc' include 'API\Gdi32.Inc' include 'API\AdvApi32.Inc' ; <-- this one needed to work with Registry |
|||
![]() |
|
EaxRax 19 Aug 2013, 20:18
AsmGuru62 That's it!
![]() ![]() ![]() ![]() P.S. Questions on this topic no more! |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.