Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-02-19
3
Medium Priority
?
690 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
1 Comment
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

810 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