how to add path entry in variable using javascript?

How do I add to the path variable with javascript. I have this javascript:

<script Language=Javascript>
function blabla()
{
oShell = new ActiveXObject("wscript.shell");
var oFso = new ActiveXObject("Scripting.FileSystemObject");
if(oFso.FileExists("C:\\blabla\\blabla.exe"))
     {
       oShell.Run("C:\\blabla\\blabla.exe");
       window.location.href='http://somethingelse';
     }
else
     {
     alert(blabla is not installed on this computer.')
     }
}
</script>

which starts an application, but this app turns out that it needs a certain path to be added to the path variable. the problem is, I wrote an NT script at startup that adds this path, but it is adding it at every startup. I would like to add it DYNAMICALLY, ie to write it in the memory, not in the variable itself, meaning that everytime the user clicks on the link that launches this script, it gets the variable in the memory only, not in the system.
tonikaramAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xabiCommented:
Try this:

oShell.Run("set PATH = %PATH%;c:\\my_new_path");

xabi

PS: %PATH% is the actual value of PATH, so this line should add "c:\my_new_path" to the existing path.

0
tonikaramAuthor Commented:
it gives me the error The system cannot find the file specified
eventhough I double checked the path is correct
0
NushiCommented:
do you use any server side script?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

tonikaramAuthor Commented:
you mean asp?

I don't use vbscript because entering vbscript in the page ruined other javascript present for drop down menus'n stuff. so I was obliged to use javascript. why, it doesn't work using javascript?
0
NushiCommented:
i meant asp/php/jsp .

>> why, it doesn't work using javascript?
no. you cant do it in JS.

ActiveX is not javascript.
ActiveX is a pre coded application that is embeded in the Operating system.
you can use it with JS as you do in your sample but its not JavaScript.
>>wscript.shell
this allow you to run shell commands.

if a user is blocking ActiveX you cant run your script.

regarding your question i would have try what was suggested above:
oShell.Run("set PATH = %PATH%;c:\\my_new_path");


Nushi.
0
tonikaramAuthor Commented:
I agree with you, but this is the intranet and I have enabled activex for all my users. That linke of code is giving an error "The system cannot find the file specified"
why??

here is the complete script. wherever I put that line it is causing me the error:

<script Language=Javascript>
function blabla()
{
oShell = new ActiveXObject("wscript.shell");
var oFso = new ActiveXObject("Scripting.FileSystemObject");
if(oFso.FileExists("C:\\blabla\\blabla.exe"))
     {
      oShell.Run("set PATH = %PATH%;c:\\my_new_path");
      oShell.Run("C:\\blabla\\blabla.exe");
      window.location.href='http://somethingelse';
     }
else
     {
     alert(blabla is not installed on this computer.')
     }
}
</script>

0
NushiCommented:
in first look this is my impression ( imight be wrong since i havent checked it throuly)
i guess its due to security reasons and not a problem with the file path.

but i will check it throw later on today and i iwll try to solve your problem.

Nushi.

0
xabiCommented:
My be this way:

oShell.Run("cmd /c set PATH = %PATH%;c:\\my_new_path");


xabi
0
NushiCommented:
xabi
your suggestion is good.
the only problem with that is the scope of the path will be only for the cmd
once its closed you los ethe path.

i couldnt do any better then that.
its a security issue that as fas as i can tell i couldnt found any "workaround" to solve it.
if someone was able to do it he can plant a virus in someone computer ans whenever this persone
viewing HTML page (on the writer side) he can do some nustry things on the victim computer.

so i am sorry to disapoint you but your question is not posible
:-((
Nushi.
0
VincentPugliaCommented:
hi,

  You can use the BuildPath method

 newpath = fso.BuildPath(path, "New   Folder");
 
example & other methods links here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthbuildpath.asp

Vinny
0
tonikaramAuthor Commented:
below is the script with all the methods mentionned above tested. the three commented ("//") lines below are the three methods.
- the first line gives nothing, as if the path is still not there (you can see the function definition at the end of the script).
- the second line does nothing, the cmd does run, I see a black window for a flash of a second, but the path is still not there (if I could run my app in the same black window then the path will be there I am sure)
- finally, the third line gives the error "The system cannot find the file specified".

I feel getbuildpath method is my solution, how do I call/use that funciton properly? I know I haven't in the first line commented below.

function blabla()
{
oShell = new ActiveXObject("wscript.shell");
var oFso = new ActiveXObject("Scripting.FileSystemObject");
if(oFso.FileExists("c:\\blalba\\blabla.exe"))
     {
//       GetBuildPath("C:\\mynewpath")
//       oShell.Run("cmd /c set PATH = %PATH%;C:\\mynewpath");
//       oShell.Run("set PATH = %PATH%;C:\\mynewpath");
     oShell.Run("c:\\blabla\\blabla.exe");
     }
else
     {
     alert('blabla is not installed on your computer.')
     }
}

function GetBuildPath(path)
{
   var fso, newpath;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   newpath = fso.BuildPath(path, "C:\\mynewpath");
   return(newpath);
}  




0
VincentPugliaCommented:
Hi tonikaram,

   May I ask a few questions first?  
 1) Is this going on a server or simply on the client's desktop?
 2) Why do you need to 'build a path'?  Is it that you do not know the path, or that the path changes from machine to machine?
 3) what is the final path you are looking for?
 4) Are you intent on 'finding a path', or simply locating and running an application?

Vinny
 
0
tonikaramAuthor Commented:
1) it is a webpage I am writing that simply launches an application. this application needs one folder to be added to the path.
2) I don't need to build a path, I just need that for this session ( the line: oShell.Run("c:\\blabla\\blabla.exe") ) the path gets one more folder added. as in a "local environment".\
3) the final path should look like: %path%;c:\pathtolocalenv (meaning the old path + the new folder)
4) I don't need to know the original path, just add
0
tonikaramAuthor Commented:
so, nobody has a solution? :(
0
NushiCommented:
>> so, nobody has a solution? :(

there isnt any soltion since it will be a security problem if there was.
imagine web site which can set any class path he need and then read/add/delete file ?
ActiveX does allow you some "workaround" in some cases but you cant be too gridy...

you should eigther ask to delete this question
or spare the points to those who spent their time for you.

:-))
Nushi.
0
tonikaramAuthor Commented:
ok

I have two questions though:

- what does the buildpath function do? because I am sure I didn't use/call it properly.
- the command oShell.Run("c:\\blabla\\blabla.exe") works like a charm, wonder why the oShell.Run("set PATH = %PATH%;C:\\mynewpath") doesn't? you would agree that both of them are as unsafe. don't forget that this the intranet, added to the "Trusted sites" of internet explorer for all the users, and the setting "Initialize and script ActiveX controls not marked as safe" is set to "enabled" for all the users. this is not standard web browsing, but a boosted-up intranet.

kay
0
VincentPugliaCommented:
Hi kay,

  After rereading your original question, I think I have a better idea of what you are asking for -- though I am still not certain.  I think you want to do one of 2 things: either append a 'working' directory for the executable, or change the path to the executable.

  Any rate if you wish to change the path, this is what you would use (simply change somePathVar to the desired string or pass it as a var):

if(oFso.FileExists("C:\\WINDOWS/NOTEPAD.EXE"))
     {
         oldPath = "c:\\windows/notepad.exe"
         fileName = oldPath.substring(oldPath.lastIndexOf("/"))
         newPath = oFso.BuildPath(somePathVar, fileName)
         alert(newPath)

If, on the other hand, you wish to append a 'working directory', you actually want to be able to change the environment of the executable -- which should be possible through oShell.Run command.

Vinny


0
tonikaramAuthor Commented:
"If, on the other hand, you wish to append a 'working directory', you actually want to be able to change the environment of the executable -- which should be possible through oShell.Run command."

what I wish to do is append a directory to the path, exactly as if I am loading a local environment for that executable. how is it possible through the oShell.Run command?

I want to do this:
1- set path = c:\blabla
2- run the executable (which will find its dll's in the path above, without the path above it will not find its dll's)

kay
0
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
tonikaramAuthor Commented:
question may be deleted..
today, I have still not found the solution.
0
SpazMODicCommented:
PAQed, with points refunded (250)

SpazMODic
EE Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.