Jump to content

Setting path cariable permanently


Doc Symbiosis

Recommended Posts

Hi there,

I want to add the following directory to my Path variable: "c:\Program Files\IT+ES command line applications" permanently. I tried the following vb-script, but after restart, when I want to run a command, e.g. net user, it says, that it can't find this command. In my own directory, I can run the commands. It seems to add the directory in a right way, but I think there's missing some escape Character or something like this, cause, when I add the directory manually, everything works fine.

Anyone got an idea or another way to do this?

Set wshshell = CreateObject("WScript.Shell")

key_path_cur = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path"
key_path_001 = "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment\Path"
key_path_002 = "HKLM\SYSTEM\ControlSet002\Control\Session Manager\Environment\Path"

app_dir = "%PROGRAMFILES%\IT+ES command line applications"
app_dir = wshshell.ExpandEnvironmentStrings(app_dir)

cur_path = wshshell.RegRead(key_path_cur)

new_path = cur_path&";"& app_dir

wshshell.RegWrite key_path_001, new_path
wshshell.RegWrite key_path_002, new_path

Link to comment
Share on other sites


care to elaborate the purpose?

like, do you want to be able to do something like such

set lastgood=%systemroot%\lastgood

so that you could then do

%lastgood% and goto the above directory

if this is the purpose, remember, when using dynamic values, like %systemroot, you can just use, a string, but rather an expanable string value.

also changing reg keys, then exporting, and edit the .reg file to only have what you need, can make things easier, but remember to make a backup first, to restore to, b4 you restart the computer, if you think it might b0rk things.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...