?
Solved

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

Posted on 2011-02-19
3
Medium Priority
?
680 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 80 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Determining the an SCCM package name from the Package ID
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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