473,382 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 8299
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.