October 28, 2020, 11:49:56 PM

Author Topic: [bmx] Permanent Environment Variables by JoshK [ 1+ years ago ]  (Read 1566 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
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[/url]


Code :
Code: BlitzMax
  1. SuperStrict
  2.  
  3. SetEnv("MyAwesomeKey","Happy happy fun time")
  4.  
  5. Function SetEnv:Int(key:String,value:String)
  6.         Local stream:TStream=WriteFile("temp.bat")
  7.         If Not stream Return False
  8.         stream.WriteLine "% reg add ~qHKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment~q /v ~q"+key+"~q /t REG_SZ /d ~q"+value+"~q"
  9.         stream.close()
  10.         Local proc:TProcess = CreateProcess("temp.bat")
  11.         If Not proc Return False
  12.         While proc.status()
  13.                 Delay 1
  14.         Wend
  15.         If getenv_(key)=value Return True
  16. 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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal