• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

setting environment variables using VB

Hello,
We are thinking to migrate one of our file & print server from NetWare to Windows 2003.
In the NetWare Logon script we set a search drive which contain some batch files, exe files etc..
I like to understand how can I add path to environment using vb script.
by the way, in windows 2003, if I want to let users to run batch files from this drive, is that the way to do it ?

Thanks.

Adi.
0
abendv_10
Asked:
abendv_10
  • 2
  • 2
1 Solution
 
vinnyd79Commented:
If you are looking to add a path to the existing Path environment variable then try this.Add this to a text file with a .vbs extension:

Dim objShell,objEnviron
Set objShell = CreateObject("Wscript.Shell")
Set objEnviron = objShell.Environment("System")
objEnviron.Item("Path") = objEnviron.Item("Path") & ";C:\MyPath"

Set objEnviron = Nothing
Set objShell = Nothing
0
 
abendv_10Author Commented:
Hi vinnyd79,
It works but I have two problems.
1.This script add the path  ";C:\MyPath" Everytime I logon in addition to the same path that allready exist from the last logon. then the Environment variables PATH has more and more ";C:\MyPath".

2. To execute this script the users must be Administrators on the Machine. In Terminal Server Environment it is a big
problem.


Correct me if I worng.

any way you helped me and I give you the points.
I will be hapy for more advices.

Adi.
0
 
vinnyd79Commented:
For #1 you could check if the path exists before adding:

Dim objShell,objEnviron
Set objShell = CreateObject("Wscript.Shell")
Set objEnviron = objShell.Environment("System")

If Instr(objEnviron.Item("Path"),"C:\MyPath") = 0 Then
   objEnviron.Item("Path") = objEnviron.Item("Path") & ";C:\MyPath"
End if

Set objEnviron = Nothing
Set objShell = Nothing


The script seems to work for non-admin users in my environment. Does it give an error or does it just not add the Path?
0
 
abendv_10Author Commented:
The Error is "Permission denied"
                   code: 800A0046

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now