PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] What is the equivalent of setenv in Windows?

 August 21, 2022     c, environment-variables, setenv, windows     No comments   

Issue

I am trying to find an equivalent for setenv to use in a C program. What I am trying to do is to modify the values of all the environment variables of the currently running process. I am trying to use putenv but it doesn't change the variables` values in any way. What could I do?


Solution

Those are the correct methods for setting the environment variables. The issue you are hitting is that SetEnvironmentVariable which is what is used by the C Runtime setenv does not change system-wide environment variables; only the environment of the currently running process.

Changing the system-wide or per-user environment variables on Windows is normally done using scripts or UI. To modify the system-wide environment variables from a C program, you need (a) to run it with administrator rights, (b) you need to modify the System Registry, and (c) you need to send a WM_SETTINGSCHANGE Win32 message to get the changes picked up by the Windows shell.



Answered By - Chuck Walbourn
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing