Doc Symbiosis Posted January 26, 2006 Posted January 26, 2006 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_dirwshshell.RegWrite key_path_001, new_pathwshshell.RegWrite key_path_002, new_path
gdogg Posted January 27, 2006 Posted January 27, 2006 care to elaborate the purpose?like, do you want to be able to do something like suchset lastgood=%systemroot%\lastgoodso that you could then do%lastgood% and goto the above directoryif 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.
Doc Symbiosis Posted January 28, 2006 Author Posted January 28, 2006 Just found my mistake. The trouble came from, that the newly created regvalues have type REG_SZ. So I added the type and everything works finewshshell.RegWrite key_path_001, new_path,"REG_EXPAND_SZ"wshshell.RegWrite key_path_002, new_path,"REG_EXPAND_SZ"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now