get values from asp pass to batch file !!!

A

Ahmad Sabry

Dear Sir,
i'm new to asp.net
i'm looking to How to get values (Variables) pre Declared in web form & pass
it to a batch file
coz i've to get this values to be added to the batch file to Automate the
process of creating records & Zones in our DNS server
May you Help ?
 
P

Phill W.

Ahmad said:
i'm looking to How to get values (Variables) pre Declared in web form & pass
it to a batch file

If the batch file takes the values are arguments, pass them as the
Arguments to the Process that you start to run the Batch file.

Dim p as New Process
With p
With p.StartInfo
.FileName = "[path]\file.bat"
.Arguments = A & " " & B & " " & C
End With
.Start()
.WaitForExit()
End With

HTH,
Phill W.
 
A

Ahmad Sabry

Thanks Mr Phill , But as i told you i'm still new in .net
So there's something missed maybe !
so again , my batch file will be (C:\Do.bat) --------- > & i wrote in it for
example :
==========
@ECHO OFF
mkdir c:\%A%
========== is this correct ? so
in ASP.net i've a text Box & a button
i imported
Imports System
Imports System.Diagnostics
Imports System.ComponentModel
& when I press the Button :
==============================
Dim A As String
A = TextBox1.Text
Dim p As New Process
With p
With p.StartInfo
.FileName = "C:\Do.bat"
.Arguments = A
End With
.Start()
.WaitForExit()
End With
==============================
I get the following Error:
'StartInfo' is not a member of 'Process'.

May you tell me what i missed ?
Thanks in advance
A.Sabry
 
P

Phill W.

Ahmad said:
I get the following Error:
'StartInfo' is not a member of 'Process'.

Do you have another class in your project called Process?

Try changing the declaration of the Process object to be:

Dim p As New System.Diagnostics.Process

Other than that, the code I gave works for me. :-{

Hopefully, your bat file will be doing a /lot/ more than just creating a
directory - you could do that perfectly well in Visual Basic code
directly ...

Regards,
Phill W.
 
A

Ahmad Sabry

Do you have another class in your project called Process?
No oher Classes
Try changing the declaration of the Process object to be:
Dim p As New System.Diagnostics.Process
It works with one Error

[HttpException (0x80004005): Request timed out.]
Hopefully, your bat file will be doing a /lot/ more than just creating a
directory - you could do that perfectly well in Visual Basic code directly
...
i c .. but htat what my leader doesn't sees
i just want it to make a liitle thing correctly to go ahead with my complex
dns commands
i made it before as windows app. by using an external dos Class
it worked but he needs the script to be easier for editing than compiling in
future


sorry mr Phill .. but i really need this to work
 
A

Ahmad Sabry

it works now but not 100%
i mean it opens the CMD prompt
but i think the problem in the way i pass the variable (A)
to the batch file
my Code is:
========================================
Dim A As String
A = TextBox1.Text
Dim p As New System.Diagnostics.Process
With p
With p.StartInfo
.FileName = "C:\Doit.bat"
.Arguments = A
End With
.Start()
.WaitForExit()
End With
========================================
& my batch file:
========================================
@ECHO OFF
mkdir c:\%A%
========================================
So ... where is the mistake ?
 
R

RobinS

If I remember correctly (50/50 chance here),
I think batch files accept parameters as %1%, %2%,
and so on, so if you change %A% in your batch file
to %1%, it should work.

You can run your batch file yourself by
bringing up a cmd window, navigating
to the folder where your batch file it,
and then running it. This would help clarify
if the problem is with the batch file or the
VB code.

Robin S.
 
P

Phill W.

Ahmad said:
i've also Access is denied in the CMD window when it runs

Well that's a bit of a show-stopper.

The ASP must be running under an account that's just not allowed to do
whatever it is your bat file is trying to do.
Find out which account it's running under and make sure that that
account has the necessary permissions.

Regards,
Phill W.
 
Joined
Jun 21, 2011
Messages
1
Reaction score
0
I wonder if you are getting access denied because you're declaring a letter in your batch file, its ignoring it and you are then trying to create a directory called c:\ which is obviously not allowed.

declare your variable in .net as normal then within your batch file you need to set it. so if you

Dim p As New System.Diagnostics.Process
Dim a As String
a = TextBox1.Text

With p
With p.StartInfo
.FileName =
"C:\Doit.bat"
.Arguments = a
End With
.Start()
.WaitForExit()
End With

then within your batch file

set a=%1
mkdir c:\%1%



 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top