PC Review


Reply
Thread Tools Rate Thread

Delete environment Variables

 
 
Manoj Nair
Guest
Posts: n/a
 
      17th Mar 2005
Hi,
How can i delete a specific environment variable through code

Thanks in advance
Manoj


 
Reply With Quote
 
 
 
 
CometJoe
Guest
Posts: n/a
 
      17th Mar 2005
Setting the value of an existing environment variable to "null" will
delete it from the current process's environment.
This will create a new var & then delete it.
Hope this helps,
Joe


using System.Runtime.InteropServices;


public class Test
{
[DllImport("kernel32.dll", CharSet=CharSet.Auto,
SetLastError=true)]
public static extern bool SetEnvironmentVariable( string
sVarName, string sVarValue );

public Test()
{
}

public string TryThis()
{
string NewEnvVar = "junk";
string NewEnvValue = "testing";
//SetEnvironmentVariable ( NewEnvVar, NewEnvValue );

string sTest = Environment.GetEnvironmentVariable (
"junk" );

SetEnvironmentVariable( "junk", "" );
sTest = Environment.GetEnvironmentVariable ( "junk"
);

return sTest;
}

}



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
 
Reply With Quote
 
Manoj Nair
Guest
Posts: n/a
 
      17th Mar 2005
Joe,
Thanks for the help
Manoj

"CometJoe" <(E-Mail Removed)> wrote in message
news:4239a3f0$1_3@127.0.0.1...
> Setting the value of an existing environment variable to "null" will
> delete it from the current process's environment.
> This will create a new var & then delete it.
> Hope this helps,
> Joe
>
>
> using System.Runtime.InteropServices;
>
>
> public class Test
> {
> [DllImport("kernel32.dll", CharSet=CharSet.Auto,
> SetLastError=true)]
> public static extern bool SetEnvironmentVariable( string
> sVarName, string sVarValue );
>
> public Test()
> {
> }
>
> public string TryThis()
> {
> string NewEnvVar = "junk";
> string NewEnvValue = "testing";
> //SetEnvironmentVariable ( NewEnvVar, NewEnvValue );
>
> string sTest = Environment.GetEnvironmentVariable (
> "junk" );
>
> SetEnvironmentVariable( "junk", "" );
> sTest = Environment.GetEnvironmentVariable ( "junk"
> );
>
> return sTest;
> }
>
> }
>
>
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
> http://www.usenet.com



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Environment Variables Eka1618 Microsoft Access VBA Modules 6 13th Aug 2008 02:28 PM
Environment variables Xarky Windows XP Basics 1 15th Dec 2004 01:50 PM
Environment Variables Ron Reese Microsoft Windows 2000 Applications 1 9th Feb 2004 03:15 PM
Environment Variables in .NET NetPointer Microsoft Dot NET 2 15th Sep 2003 02:45 PM
User Environment variables overriden by system env variables Bonny Windows XP Setup 0 11th Jul 2003 06:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:30 PM.