Solved

How to Create an Environment Variable using Visual Basic 6 VB6 in Windows XP?

Posted on 2011-02-19
3
677 Views
Last Modified: 2012-08-13
I need to create an Environment Variable under system variables that has this information:
Variable
LOCALDIR
Value:
Z:\Test\VB

My skills in VB are limited so please post the easiest code, Thanks.
I am using Visual Basic 6pro VB6 and Windows XP Pro.
0
Comment
Question by:daneburr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 20 total points
ID: 34934446
A bit of a hack, but this is how I would do it:

There is a DOS command called "REG" that you can use to directly add the new environment variable definition to the Windows registry.   This is the DOS command that does it (substitute your own symbol name and value, of course).

REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "mynewsystemsymbol" /t REG_SZ /d "mynewvalue" /f

Open in new window


[Once the new environment variable has been defined, having it take effect without logging out and back in again is another question.]

Construct the DOS "REG" command in a string variable and use the "shell" function to execute it.

Dim mySetEnvCommand As String
mySetEnvCommand = "REG ADD ""HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"" /v """ & mynewsystemsymbol & """ /t REG_SZ /d """ & mynewvalue & """ /f"

shell(mySetEnvCommand)

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
An article on effective troubleshooting
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question