Security Basics mailing list archives

RE: Windows environment variables - thanks


From: "Sánchez Sanz, Javier" <jssanz () indra es>
Date: Thu, 4 Sep 2003 18:23:54 +0200

Hello again, thanks for your help. I used Sentenv.exe also, but it only sets them, but it doesn't remove them. What I 
have done finally is to use WMI scripting (that is what I wanted to know!), and I've done all I want.

FYI:
TO CREATE an entry -user var- (In HKEY_CURRENT_USER\Environment, there is where the user variables are stored). Create 
a .vbs file with the following code, execute it followed with the name of the variable and the value as arguments:
-----------------------------------------
const HKEY_CURRENT_USER = &H80000001
Set objArgs = WScript.Arguments
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "Environment"
Key = objArgs(0)
Value = objArgs(1)
oReg.SetExpandedStringValue HKEY_CURRENT_USER,strKeyPath,Key,Value
-----------------------------------------

And to DELETE IT. This sample just take the name of the variable to delete as argument:
---------------------------------------------
const HKEY_CURRENT_USER = &H80000001
Set objArgs = WScript.Arguments
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "Environment"
strValueName = objArgs(0)

oReg.DeleteValue HKEY_CURRENT_USER,strKeyPath,strValueName
------------------------------------------------------------------

And it can be runned at cmd console and it takes effect in the user session inmediately.

Thanks again for your help.

Javi

-----Mensaje original-----
De: Wood, Richard [mailto:Richard.Wood () wellington co uk]
Enviado el: jueves, 04 de septiembre de 2003 10:19
Para: Sánchez Sanz, Javier
CC: 'security-basics () securityfocus com'
Asunto: RE: Windows environment variables


Hi Javi,

For setting and removing environment variables from the command line, use "setenv.exe". This is a freeware replacement 
for SetX, with better functionality. Also try "pathman.exe" for adding or removing sections from path. This is a 
Microsoft Resource Kit tool.

A quick search on Google should give you all the info you need, including download locations.

Hope this helps,

Richard

-----Original Message-----
From: "Sánchez Sanz, Javier" [mailto:jssanz () indra es]
Sent: 03 September 2003 08:57
To: security-basics () securityfocus com
Subject: Windows environment variables


Hello,
I need to set and remove system or user environment variables at Windows 2000 or XP. But I need to do it by 'hand', I 
mean, with some command, not using the Windows GUI. Does anyone how to do this? If I set variables at the command 
prompt, they only last during the DOS console is open, and what I need is that they are available during the user 
session. I was looking even the registry but I don't found anything. What I found was SetX, a reource kit from 
Microsoft, but it only sets the variables, and I cannot remove them.

Many thanks

Javi


---------------------------------------------------------------------------
Attend Black Hat Briefings & Training Federal, September 29-30 (Training),O  ctober 1-2 (Briefings) in Tysons Corner, 
VA; the world's premier
technical IT security event.  Modeled after the famous Black Hat event inL  as Vegas! 6 tracks, 12 training sessions, 
top speakers and sponsors.
Symantec is the Diamond sponsor.  Early-bird registration ends September 6.Visit us: www.blackhat.com
----------------------------------------------------------------------------


_____________________________________________________________________
This e-mail has been scanned for viruses by MCI's Internet Managed Scanning Services - powered by MessageLabs. For 
further information visit http://www.mci.com


________________________________________________________
The information in this message is confidential and may
be legally privileged. It is intended solely for the
addressee. Access to this message by anyone else is unauthorised. If you are not the intended recipient, any 
disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may 
be unlawful.

The registered office of Wellington Underwriting plc is
88 Leadenhall Street, London, UK   EC3A 3BA.
________________________________________________________


---------------------------------------------------------------------------
Attend Black Hat Briefings & Training Federal, September 29-30 (Training),
October 1-2 (Briefings) in Tysons Corner, VA; the world's premier
technical IT security event.  Modeled after the famous Black Hat event in 
Las Vegas! 6 tracks, 12 training sessions, top speakers and sponsors.  
Symantec is the Diamond sponsor.  Early-bird registration ends September 6.Visit us: www.blackhat.com
----------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------
Este correo electrónico y, en su caso, cualquier fichero anexo al mismo, contiene información de carácter confidencial 
exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgación, copia o distribución a 
terceros sin la previa autorización escrita de Indra. En el caso de haber recibido este correo electrónico por error, 
se ruega notificar inmediatamente esta circunstancia mediante reenvío a la dirección electrónica del remitente.

The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named 
addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited 
without the prior written consent of Indra. If you have received this communication in error, please, notify the sender 
by reply e-mail

---------------------------------------------------------------------------
Attend Black Hat Briefings & Training Federal, September 29-30 (Training),
October 1-2 (Briefings) in Tysons Corner, VA; the world's premier
technical IT security event.  Modeled after the famous Black Hat event in
Las Vegas! 6 tracks, 12 training sessions, top speakers and sponsors.
Symantec is the Diamond sponsor.  Early-bird registration ends September 6.Visit us: www.blackhat.com
----------------------------------------------------------------------------


Current thread: