How to run a program from an aspx page?

Q

Quentin Huo

Hi:

I want to run cacls.exe to check the user right from an ASPX page. In ASP, I
can do:

Set wshobj=Server.CreateObject("WScript.Shell")
resobj=wshobj.Run("cmd /c echo Y| cacls c:", 0, True)
Set wshobj=Nothing

But I don't know how to do this in ASPX page (writen in C#).

Can anyone help me? Can you show me a simple sample or tell me some websites
that have tutorials on it?

Thanks a lot!

Q.
 
K

Kevin Spencer

System.Diagnostics.Process.Start(filename);

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
Q

Quentin Huo

Hi:

I tried the following code, but it didnot work and I didnot get any error
message:

Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/C cacls D:\\inetpub >
D:\\temp\\aclTemp.txt";
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.StartInfo.CreateNoWindow = true ;
myProcess.Start() ;

I don't know where the problem is. Can you help me?

Thanks!

Q.
 
K

Kevin Spencer

I'm not sure what you mean by "didn't work." You set up the Process to hide
its' Window, run the cmd utility and run from that a program that displays
an ACL in the Window. The Window is hidden, as per your instructions. What
did you expect to see?

Perhaps if you tell me what you're trying to accomplish by this, I can help
more.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
Q

Quentin Huo

Hi, Kevin:

What I want is to get the account infomation of a certain directory, for
example d:\inetpub, from the program "cacls.exe". In another words, I want
to know which account has what right in the directory (folder).

I just want to use the code that I sent to you to store the result of
running calcs.exe in the text file "D:\\temp\\aclTemp.txt".

But after the program ran, the aclTemp.txt is still empty (I created it
before ran the program.). So I think the piece of the codes didnot work.
BTW, the codes is in an ASPX page. However, I didnot get any error message.

Where is the problem? This is my first time to use ProcessStartInfo, so I
have no idea.

If you need more information, please let me know.

Thanks!

Qing
 
K

Kevin Spencer

I just want to use the code that I sent to you to store the result of
running calcs.exe in the text file "D:\\temp\\aclTemp.txt".

Not quite. If, for example, I ran into you on the street, and asked where
you were going, and you told me "to the bus stop" I would have no idea where
you were going, as the real destination is the destination you expect the
bus to take you to. So, when I ask what you're trying to accomplish, and you
tell me "to store the result of running cacls.exe in the text file..." you
haven't told me what you want to accomplish by doing that; you've only told
me how you want to accomplish it.

Now, when you say "I want to know which account has what right in the
directory" you're getting closer to what your business rule is. What do you
plan to do with that information?

The reason I ask this is that ASP uses scripting, and has very limited
funtionality and permissions, and it is often necessary with ASP to dow
"workarounds" to get information that is not normally available to
scripting. ASP.Net is a fully-compiled "real" programming technology, with
the entire resources of the Common Language Runtime Library, and anything
else you need, natively. If you could tell me what your business requirement
is (where is the bus taking you?) I can suggest a way to do it without the
klugy workarounds.

For example, you say you want to spawn an instance of the cmd.exe utility to
run another program. In fact, you could skip the cmd.exe utility altogether
and simply run the other program. But I don't think you really want to run
cacls.exe, and besides, you've got the command-line syntax wrong for what
you're trying to accomplish. It is almost never necessary to run a
shelled-out command-line to accomplish anything with .Net, but I need to
know what you want to do with this information first before I can advise
you.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
Q

Quentin Huo

Hi:

I want to control the access right to some resources in my computer by
control the ACLs. For example, I don't want everybody can access files in my
some folders. So I will give different users with different rights: some can
only read and some can write. And I may have to change the rights of some
users sometimes.

cacls is a program to change or modify the ACLs. for example:

cacls myfile.txt /e /g mrhope:f

it means Grants the user "mrhope" full rights to the myfile.txt file

cacls runs under the command line, so I need to "spawn an instance of the
cmd.exe utility" to
run it.

Thanks

Q.
 
K

Kevin Spencer

Okay, now I'm REALLY confused. You ARE writing an ASP.Net application,
correct? If so, you should know that the application runs under ONE user
account only, not under any user accounts that belong to people using client
browsers. So, I have no idea how you're supposed to control access to that
file by setting file permissions on it.

There are classes in the CLR that enable you to grant and deny users
permissions to files. But again, I'm not seeing the logic of your method.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
Q

Quentin Huo

Hi:

OK, let me make it easier:

I want to run a command under the command line:

cacls D:\\inetpub > D:\\aclResult.txt

Can you tell me how to do this by using System.Diagnostics.Process.Start?

Thanks

Q.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top