472,807 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,807 software developers and data experts.

executing DOS command on client machine using c#.net

I am trying to build a web application which can execute dos print command on the client machine.
This application will read a file stored in server and
it will create a folder on client machine and store the file there for future reference.it will also print the contents on the printer attached on client machine. I M using dos command because other options requires manual file>print options to print the file and number of files is too large.
I Want the user to just click on the print button and all the files will be saved and printed.

First thing I would like to ask is , whatever code I will write for execution of dos command(for creation of folder on client machine and printing)will run on server or client machine.as far as I know c# code will execute on server side. What should I do to make it run on client machine.


I have a asp button on the page which when clicked should
create a folder on the clients hard disk eg: c: using dos command
Expand|Select|Wrap|Line Numbers
  1.     MD somefoldername
  2.  
Save the file there and then print the file using dos command
Expand|Select|Wrap|Line Numbers
  1.  PRINT  filename
  2.  
I'm having the following code:
Expand|Select|Wrap|Line Numbers
  1.  System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
  2.         psi.UseShellExecute = false;
  3.         psi.ErrorDialog = true;
  4.         psi.RedirectStandardOutput = true;
  5.         psi.RedirectStandardInput = true;
  6.         psi.RedirectStandardError = true;
  7.         psi.Arguments = "PRINT c:\\test.txt";
  8. //test.txt is already present on clients c:
  9.         System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
  10.  
  11.  
  12.         System.IO.StreamWriter sIn = proc.StandardInput; // Attach the in for writing 
  13.         System.IO.StreamReader sOut = proc.StandardOutput; // Attach the output for reading
  14.         System.IO.StreamReader sErr = proc.StandardError; // Attach the output for errors
  15.  
  16.         proc.Close();
  17.         string results = "";
  18.         results = "<br /><b>Output : </b><br />" + sOut.ReadToEnd().Trim();
  19.         results = "<br /><b>Error : </b><br />" + sErr.ReadLine().ToString();
  20.  
  21.         // Close the io Streams;
  22.         sIn.Close();
  23.         sOut.Close();
  24.         sErr.Close();
  25.         Response.Write(results);
  26.  
But it never executes as it throws win32 exeception..

I Also tried one other piece of code
Expand|Select|Wrap|Line Numbers
  1.                Process proc = new Process();
  2.                proc.StartInfo.UseShellExecute = true;
  3.               proc.StartInfo.FileName = "calc";
  4.               proc.StartInfo.Arguments = null;
  5.              proc.Start();
  6.                proc.WaitForExit();
  7.  
In this case there is no exception but it do nothing.this code should open the windows calculator.
I have searched the google and everywhere I get the same piece of code never mentioning it will execute on server or client. I tried to execute it on server to but with the same result. I will be grateful for the solution. It's very urgent.
Nov 22 '07 #1
5 8231
anybody plz its very urgent
Nov 22 '07 #2
Frinavale
9,735 Expert Mod 8TB
anybody plz its very urgent
Hi RohitKumar,

Your post is entirely in Caps. Please read the posting guidelines and pay close attention to the section on Things that are generally unacceptable.

-MODERATOR
Nov 22 '07 #3
Frinavale
9,735 Expert Mod 8TB
I Am Trying to build a web application which can execute DOS Print command on the client machine.
What type of application are you building? An ASP.NET Web application or a desktop application that accesses a Web Service?
If you are developing an ASP.NET Web application what you are trying to do is simply not possible without using an ActiveX control. ActiveX controls are considered to be unsafe.

this application will read a file stored in the server and will create a folder on the client machine and store the file there for future reference. It will also pring the contents on the printer attached on the client machine

I am using DOS command because other options require manual File->Print options to print the file and a number of files is too large

I want the user just to click on the Print button and all the files will be saved and printed

First thing I would like to ask is, whatever code I will write for execution of DOS command (for creation of folder on client machine and printing) will run on server or client machine. As far as I know C# code will execute on server side.
I need to know what type of web application you are developing?
An ASP.NET Web application?
If you try to run Dos commands in this type of application, it will execute on the server computer Not on the client computer.

What should I do to make it run on the client machine?
If you are developing an ASP.NET application you would have to write an ActiveX to do this...This is very difficult to do and is not considered safe.

Instead I recommend you just create the files on the server and let the user download them into their own directory. Once the user's finished, just delete these resources.

I have an ASP button on the page which when clicked should create a folder on the client's hard disk eg: C: USING DOS COMMAND
Ah Ha!
You are developing an ASP.NET web application!
The code you have provided will execute on the server alone.

I strongly recommend you reconsider your project's requirements as what you are trying to do is not possible through ASP.NET. You'd have to create an ActiveX control that the user would agree to Install on their computer. It's not easy to do this and ActiveX's are strongly advised against...and your users would be limited to using Internet Explorer Only.

Due to security reasons, your web application cannot control anything on the Client's computers. Web applications are designed to serve the information into Web Pages, not onto the client's computer.

Consider letting the user download the files on their own instead of manipulating the client's computer.

Or you could consider developing a Web Service with a desktop application client that calls your functions. This will let you control the client's computer without any problems.
Nov 22 '07 #4
What type of application are you building? An ASP.NET Web application or a desktop application that accesses a Web Service?
If you are developing an ASP.NET Web application what you are trying to do is simply not possible without using an ActiveX control. ActiveX controls are considered to be unsafe.



I need to know what type of web application you are developing?
An ASP.NET Web application?
If you try to run Dos commands in this type of application, it will execute on the server computer Not on the client computer.



If you are developing an ASP.NET application you would have to write an ActiveX to do this...This is very difficult to do and is not considered safe.

Instead I recommend you just create the files on the server and let the user download them into their own directory. Once the user's finished, just delete these resources.



Ah Ha!
You are developing an ASP.NET web application!
The code you have provided will execute on the server alone.

I strongly recommend you reconsider your project's requirements as what you are trying to do is not possible through ASP.NET. You'd have to create an ActiveX control that the user would agree to Install on their computer. It's not easy to do this and ActiveX's are strongly advised against...and your users would be limited to using Internet Explorer Only.

Due to security reasons, your web application cannot control anything on the Client's computers. Web applications are designed to serve the information into Web Pages, not onto the client's computer.

Consider letting the user download the files on their own instead of manipulating the client's computer.

Or you could consider developing a Web Service with a desktop application client that calls your functions. This will let you control the client's computer without any problems.
I m very sorry for using caps in my posting, i will be more careful in the future.
yes,Frinavale i think you are right i would like to develop a web service with a desktop application client.can you plz help me regarding the application
Nov 23 '07 #5
Frinavale
9,735 Expert Mod 8TB
I m very sorry for using caps in my posting, i will be more careful in the future.
yes,Frinavale i think you are right i would like to develop a web service with a desktop application client.can you plz help me regarding the application

You should start by looking up how Web Services work and how to Consume these Services in a desktop application then get back to us with any specific questions that you have on the topic.

-Frinny
Nov 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sean | last post by:
I can connect to a machine remotely with no problems but I'm having trouble trying to create a process remotely. Initially this was a perl and VB script which I'm converting to python. Its entire...
6
by: Hank | last post by:
Hi, I was wondering how I would execute a file remotely? For example, test.exe resides on machine A, my python script is running on Machine B. I would like to execute "test.exe -parameters" on...
1
by: Phil | last post by:
Hi, I have my create statments for tables, procedures, views, etc in individual Transact-SQL script files (.sql). I wnat to write another script file that executes these scripts in the...
0
by: Daniel | last post by:
will a client application using ado.net get an exception if the command is executing a stored procedure that does a RAISEERROR in its tsql?
5
by: Jose Cintron | last post by:
I created a pretty basic program based on the "Windows Forms Application" template using C++ in VS 2005. When I run the program from my local system it runs properly (do happy dance), now when I...
29
by: =?Utf-8?B?SGVybWF3aWg=?= | last post by:
Hello, Please anybody help me. I have only a little experience with web development. I created simple project using ASP NET 2.0 (VS 2005) It works fine on local computer. When I tried to run...
7
by: google | last post by:
I would like to execute a single JavaScript command from within a web service. The command is a mathmatical statement. I have a web page with some client side logic that does this and I'm now...
1
by: simhadeep | last post by:
Hi I developed a windows application using C# which is used to insert data from sql server 2000 to oracle 10g data base. I developed a Installer file using set up and deployment projects in...
0
vinoj
by: vinoj | last post by:
Hi All, These are the following things which i want to do:- 1. I will be taking the ipaddress, username and password from the user using cgi ffrom the browser. 2. Now i want...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.