473,779 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

executing DOS command on client machine using c#.net

17 New Member
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 8362
rohitkumar
17 New Member
anybody plz its very urgent
Nov 22 '07 #2
Frinavale
9,735 Recognized Expert Moderator Expert
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 Recognized Expert Moderator Expert
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
rohitkumar
17 New Member
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 Recognized Expert Moderator Expert
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
27497
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 purpose is to start a process remotely. The problem initially was that the perl script could not 'see' any mapped drives as it would alway return 'access denied' so I'm trying to not only rewrite the script but fix this problem and my idea was...
6
5091
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 machine A from a script running on machine B. Does anyone know how to do this easily in python? Thanks a lot.
1
2795
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 correct order to create the database. What is the syntax for executing script files from Transact-SQL?
0
1078
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
7467
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 copy the same program to a network share (I have a drive mapped to it) and execute the same program I get an error message that reads === Start Error Pop-up Window === Reporter.exe has encountered a problem and needs to close. We are sorry for...
29
2505
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 the application on the web, it give me an error about net framework version information.
7
2109
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 moving that functionality into a web service. To clarify - on the UI the user is collecting and entering data and then it gets stored into the database. Most fields are input but there are some that are calculated and stored. The calculated...
1
1710
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 visual studio for the windows application.i installed the set up file on my local machine it works fine, when I installed the set up file on a remote machine in the same network it says Unhandled Exception: System.DllNotFoundException: Unable to load...
0
1815
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 to get the mac address which i can get by connecting to the remote machine and by executing ifconfig command. Now to connect to a remote machine in python i tried using pexpect module by which i can ssh to remote machine and get the mac...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.