Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing parameters to a bat file 1

Status
Not open for further replies.

MarkMeerten

Programmer
Aug 20, 2003
37
0
0
BE
Hello,
I'm writing a little wizzard. while i'm "walking" trough the sequence of the wizzard (html & javascript) i collect several parameters.
These parameters have to be pasted into a textfile wich is the "ini" file of a program.
Writing to a textfile with javascript isn't possible according to me so i want to do the following:
i've got a bat file wich writes the variables to a regkey. Then i read the regkey's and write them into a file with jscript.
say my batfile (mybat.bat) looks like this:
@echo off
add regkey hklm\software\myprog= %1
add regkey hklm\software\myprog\param = %2

i run the batfile in commandline:
mybat.bat var1 var2

This works fine.
BUT...
in my wizzard i try to do the following:
window.location.href = 'mybat.bat var1 var2'

AND THIS REFUSES TO WORK!!!

window.location.href = "mybat.bat' opens the batfile (after prompting)

any ideas how i can pass my variables to my batfile???


Greetz,

Mark

 

Mark,

>> Writing to a textfile with javascript isn't possible according to me

You'd be partially wrong there. Using IE's FileSystemObject, you can read and write text files (in IE/Win only), as long as you are fine running ActiveX Objects. If this is the case, and you don't mind the browser restriction, let me know, and I'll dish out some code.

Regarding passing the parameters - I don't think that this is possible. Running a batch file by setting the window location is one thing (and probably wont work in all browsers). Passing parameters to a batch file is not something that browsers were designed to do, and so you'll probably find you cannot do it.

Hope this helps!

Dan
 
Dan,
Sounds verry interresting! I really don't mind the browser restriction (we only work with IE here). I think i'm running the ActiveXObjects (is there any way to check this?)
So you can "dish out some code" ;-)

Thanx in advance,

Mark
 
Mark,

Here's the code to do it in IE using the FileSystemObject ActiveX control

Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

	// instantiate new FileSystemObject
	var fsObj = new ActiveXObject('Scripting.FileSystemObject');

	// create ASCII text file C:\myIniFile.ini
	var myTextFile = fsObj.CreateTextFile('C:\\myIniFile.ini', false);

	// write data to the file
	myTextFile.WriteLine('This is line 1');
	myTextFile.WriteLine('This is line 2');
	myTextFile.WriteLine('This is line 3');

	// close the file
	myTextFile.Close();

//-->
</SCRIPT>
</HEAD>

<BODY></BODY>
</HTML>

Hope this helps!

Dan
 
hello Dan,
i'm affraid you're code isn't what i'm looking for.
to do the things you're doing i assume that the pages have to be on a webserver.( or am i wrong?)
I can't place the pages on a webserver. They'll have to run as a &quot;standalone&quot; app. The reason therefor is verry long and borring so i'll spare you from that ;-)
If there are any other possibillities (is that correctly written????????) i'd like to hear from it!

Greetz,
Mark
 

>> i'm affraid you're code isn't what i'm looking for

Did you try it?

>> I can't place the pages on a webserver. They'll have to run as a &quot;standalone&quot; app.

This code cannot be run on a webserver - it can only be run locally.

>> i assume that the pages have to be on a webserver

I assume you didn't try the code before dismissing it.

Dan
 
Yes i've tried it!
yes it was locally and it still didn't work.

do i have to save the file as .htm? or as something else?

i'm wondering what i did wrong!

Greetz,

Mark
 
I'VE FOUND THE SOLLUTION!!!
the problem was a setting in Internet Explorer!!!
I went to 'Internet Options' setup, 'Security'
tab,select 'Custom Level' , Enabled 'Initialize and script ActiveX controls not
marked as safe'.
Afther this i've tried it again and it worked!!

Now i've got to try to change this setting compagny wide and i'm done.

Thanx a lot for your tips Dan!!!

Bye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top