SyntaxBomb - Indie Coders

Languages & Coding => Blitz Code Archives => Miscellaneous => Topic started by: BlitzBot on June 29, 2017, 00:28:43

Title: [bmx] Permanent Environment Variables by JoshK [ 1+ years ago ]
Post by: BlitzBot on June 29, 2017, 00:28:43
Title : Permanent Environment Variables
Author : JoshK
Posted : 1+ years ago

Description : If you use SetEnv, the environment variable is only visible to your program.  Use this for permanent vars other apps can see.  Must be run in admin mode.

You can use this to make your program request admin mode:
<a href="http://www.restuner.com/howto-insert-trust-info-manifest.htm" target="_blank">http://www.restuner.com/howto-insert-trust-info-manifest.htm</a>


Code :
Code (blitzmax) Select
SuperStrict

SetEnv("MyAwesomeKey","Happy happy fun time")

Function SetEnv:Int(key:String,value:String)
Local stream:TStream=WriteFile("temp.bat")
If Not stream Return False
stream.WriteLine "% reg add ~qHKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment~q /v ~q"+key+"~q /t REG_SZ /d ~q"+value+"~q"
stream.close()
Local proc:TProcess = CreateProcess("temp.bat")
If Not proc Return False
While proc.status()
Delay 1
Wend
If getenv_(key)=value Return True
EndFunction


Comments :


_PJ_(Posted 1+ years ago)

 Doesn't SetEnv set the UserProfile environment variables?


dw817(Posted 1+ years ago)

 I was intrigued at this and made a few changes so it will run in Windows 8.1, and yes - you are right. You have to run it under Administration Mode in order to get it to work.Would be interested in seeing one that does not require this special method of execution.