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

Saturday, November 5, 2022

[FIXED] How to completely clear all User Environment variables in Windows C++

 November 05, 2022     c++, environment-variables, windows     No comments   

Issue

I've been trying to make any progress I can in porting a company product written and heavily leaning on Unix, into a Windows compatible build. It's not going so well. I have two different development branches with two different problems. In this problem, I have to port what is essentially a wrapper for the Unix clearenv() function, which completely clears all user environment variables from the table. Probably for security reasons, I could not find an equivalent to clearenv() for Windows, and the one solution I found/came up with, would wipe away all environment variables in the process, including system variables. I want a solution that would get rid of all user environment variables, but not touch system ones.

I know it may be a dumb thing to do, but it's in the code, so I have to try to port it.

Also, if it helps, I'm compiling under MinGW


Solution

From the documentation for CreateEnvironmentBlock:

hToken [in, optional] [...] If this parameter is NULL, the returned environment block contains system variables only.

It will still be a bit messy to go through the process environment block and change it to match the "system only" block that this function returns, but at least you'll have the necessary information.



Answered By - Harry Johnston
Answer Checked By - Senaida (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