You can set environment variable using bat file in two different ways.
method 1:
This method is temporary way.It will set environment variable while executing the bat file
let say i want set environment varable MY_HOME as my c://windows drive
set MY_HOME=c://windows
method 2:
This method will set the environment variable permanently to user environment variable category.That mean that variable only valid for that user account.This is use a vb script to set that environment variable.But no need to install vb on your machine.vbscript just like bat commands but different.
write the vb script name in bat file (in my case it's name is demo.vbs)
my bat file:
@echo OFF
demo.vbs
vb script: (in this case inside c://windows folder)
Set objShell = WScript.CreateObject("WScript.Shell")
Set colUsrEnvVars = objShell.Environment("USER")
Set fso = CreateObject("Scripting.FileSystemObject")
colUsrEnvVars("MY_HOME") = fso.GetParentFolderName(wscript.ScriptFullName)
Remeber: This vbscript should be in the directory c://windows folder.Because it's add the system variable as the path where it's included.
**remember to restart the machine after run this bat.
method 1:
This method is temporary way.It will set environment variable while executing the bat file
let say i want set environment varable MY_HOME as my c://windows drive
set MY_HOME=c://windows
method 2:
This method will set the environment variable permanently to user environment variable category.That mean that variable only valid for that user account.This is use a vb script to set that environment variable.But no need to install vb on your machine.vbscript just like bat commands but different.
write the vb script name in bat file (in my case it's name is demo.vbs)
my bat file:
@echo OFF
demo.vbs
vb script: (in this case inside c://windows folder)
Set colUsrEnvVars = objShell.Environment("USER")
Set fso = CreateObject("Scripting.FileSystemObject")
colUsrEnvVars("MY_HOME") = fso.GetParentFolderName(wscript.ScriptFullName)
Remeber: This vbscript should be in the directory c://windows folder.Because it's add the system variable as the path where it's included.
**remember to restart the machine after run this bat.
0 comments:
Post a Comment