How to properly execute C# file over local network? - c#

Overview
C# File - Users PC
PHP Server - Hosts Webpages for application
Server and Users PC on local network
I have a c# file that reads weight from a USB scale. How would I trigger this file to run so it feeds into my program. The problem is I am using PHP to host our webpage/application so its not running client side and the scale is not hooked up to the server but to the clients PC.
The C# script would have to be on the clients in order to read the scale so how would I trigger this to happen?
Is this even possible and if not what would be a better way?
Important Edit
I was able to run the Scale Script (C#) when I wanted by having PHP and C# use TCP sockets.
The C# would listen for PHP to send something and when it did it would read the scale and send this information back to PHP becuase PHP was listening for a response. Mixed in with a little Ajax and it updates in the web browser.
Gave Chris Credit because he was the most helpful with answering my questions

It sounds like what you really want is for the client application to submit the data to the website itself, and the most suitable approach is probably to expose a web service from your server.
This service should accept weight data, along with some sort of customer key or whatever, to correlate the records correctly on the server side. I've never created a web service in PHP personally, so I can't give any advice on the implementation of that, but it is fairly trivial to hook a C# client app up to a web service once you've exposed its metadata (assuming you use SOAP).

you can't start C# application from a web page in a way that'll work in every browser every time. BUT, you can have some workarounds:
Use ActiveX component that read the data in the client and upload it to the server. the biggest cons is that it'll only work in Internet Explorer
use Silverlight client application that runs on elevated mode (v4) and upload the data to your server.
refer your clients to download application (the C# application you wrote about) and run it - this application will upload the data to your server.
hope this helps.

C# isn't a scripting language, it's a language that compiles into executable binaries or libraries. You won't be able to execute C# code on the client's computer via a website because C# code needs to be compiled before it can run.
Presumably what you really want is for your compiled C# binary to be executed on the client's machine via your website. You won't be able to easily do that. There are a lot of security measures in place to prevent browsers from running programs on your computer. There may be ways to hack around these security measures by using plugins (such as ActiveX), but it's not something that will be a one-liner.
Edit: I think you need to step back and think about what you're trying to do in a broad sense. You're trying to create a website that can read information from a user's USB port. This is the type of thing that browsers are designed to prevent, and for good reason. I wouldn't want random websites to be able to access peripheral hardware without my explicit permission. If you want this website to function the way you're expecting, you're going to have to seriously think about the security implications. You'll need some kind of client-side code (ActiveX, Silverlight, ...), and the user will need to explicitly give permission to for this all to happen. It won't be easy, and it won't be automatic. And I'm damn glad that's true.

Related

Can I connect to database with another language

Hi i have a C# WinForms app. I wrote essential methods on C#. But I need a login form and its not safe since apps like dotpeek can inspect the source code and hack it. Can i communicate with another application that is written in another language (java,c,python etc). I need to send input data from WinForms C# to another app then it should connect to database and check if login succesfull then return a value back to C# WinForms app. Is that possible, how can i implement that? I dont want to write all application in another language since C# has good methods to process images/pixels and gui support with very small memory usage.
I got the point you are trying to make.
One thing to admit is that you can't completely avoid decompiling of apps. C# or C++, no matter anything can be reverse engineered.
If you still need it, a comparatively safer approach is to not put the checking app at the client's machine. Create an API and host the database on a server.
Then initiate just an Http Request to the server from your Windows Forms app.
Then you have the full control of Login API and database. Many applications use OAuth similar to this. Another examples are apps verify it's license using an online API.
You can get a LightSail Windows server in around $10 a month if you want to setup. Try exploring
Your concern is not baseless. C#, or for that matter, any .net language running on the CLR, will be easier to inspect than a language like C or C++.
Having said that, no app will be completely secure, and communicating between apps has its own problems. How does one app verify the other? etc. You can create a web service that would communicate with the database (and communicate with the web service using HTTP or WCF) which would mean your app wouldn't have direct access to the database, but that would only protect the database from your app, it would still allow someone to inspect your app and use the web service, impersonating your app. Also, you would need to host the web service on some web hosting service, and then you would have to trust that service to not inspect your app...
You can reduce the problem by storing the password etc. as byte arrays, but regardless of what you do, I don't know of a way to completely safeguard your app. If a malicious app/actor is on your computer they can inspect your app.
As for your question itself - look into WCF or named pipes (includes a simple example).

Can a web application hosted on another machine receive data from a local .NET application without sending data to the server?

Some information:
I've got a USB scale attached to a local machine that's being read by a .NET application. I've also got a web server that needs to get these scale readings and display it to the end user in a browser window(IE 10).
We have a solution now that does this already, by having the win app send data to the web server which relays it back to the user with a jscript control. It does the job, but it causes performance issues as the scale is constantly updating and sending data to the server and back, and if there's a delay it causes all sorts of issues. so I'm looking for a solution that DOES NOT send this data over HTTP at all, but still displays in the web form.
It seems like it should be easy to just have the jscript retrieve this same data somehow but it's apparently not so simple. There's security issues, among other things. I've looked into things like Silverlight and ActiveX controls, which seem like they may be capable of doing the job but I was hoping there would be a better(or just simpler) way of doing it, perhaps with jscript directly. I thought of just using some local file that both of these applications can access but it seems like there would be issues with permissions and synchronization. Any thoughts?
I don't know that you would consider this simple, but it seems as if a more correct way to do it would be to setup a web service on the computer that is connected to the scale and then query this web service using ajax from the browser.

Creating a web application that can be accessed both online and offline

I am newbie to the web programming. I have been working as desktop application programmer for the last 8 years. Now one of my projects is to create a web application using HTML 5 and some java script that can be live on the cloud as well as downloadable as a desktop application to work offline. I don't need any database to store any data. I am thinking of writing a C# win form application with a web browser control to load the HTML pages and the .js files.
My questions are:
Is it possible to achieve? if so, is there any other way than what I mentioned above?
What about the security concerns such as accessing the files(the html files, java script files, etc)? Whether this can be called into my application from the local hard disk?
If I can run it as a desktop application, how to make sure that the source code is not accessed by anyone in the client machine?
It's achievable, but why you would want to wrap it in a C# web browser control doesn't really make sense to me. With HTML5 you can define cache manifest files to create offline apps that run in any browser that supports it, no need to wrap it with anything as long as the client has a capable browser. They don't even have to know it's an offline app!
Not quite sure what you mean here with regards to security concerns. That's a massive topic. Just use common sense and realize that anything you store on their computers will be accessible by them (e.g. do not give them your public/private key pair or store any passwords or anything you don't want them reading in the files you're sending to them) and use a secure connection to send sensitive data back and forth between the client and your server.
You really can't prevent anyone from accessing the source code if it's on their machine. The best you can do is obfuscate it to a reasonable degree before deployment to make it harder on the person trying to read it.

Getting a PrintScreen of Client PC over Web Application

I want to get "PrintScreen" of Client PC when he access a particular Web Page.
I tried GOOGLEing this IDEA! but was unable to get much,
Infact what i got know on stackoverflow itself is Javascript PrintScreen
JavaScript cannot be used for such functionality.
So, I would like to know can it be done in Ajax,ASP.NET with C#/VB or in PHP
because at the end i want to save this image/s continously to database either SQL Server or MySQL or Oracle.
Is this feasible by ActiveX Objects?
To my knowledge, it will be difficult to go ahead with javascript.Yet i plan to use more of client resourses than server resources while executing this functionality.
Browsers do not have access to client computer resources. What you describe there can't be achieved without a third party dll (if you mentioned .Net) installed on your computer and that can be done only on demand by the client. But the whole idea is, as stated before a privacy invasion and any attempt to install anything on the client computer will be regarded as a security threat from any AV software.
Simply NOT Possible by the why you need this ?
I don't know "JavaScript cannot be used for such functionality" before. But since you have figure it out, I can tell you that ASP.NET can't help you on this if JS can't. Because all ASP.NET at client side is javascript. Ajax things are actually working through javascript. ASP.NET just generates those javascripts for you to make your code working like a WebForm.

Best way of executing code over the internet

basically, I am needing to execute a program on the viewers computer through a website. This program must be capable of talking to device drivers however, which makes it an unlikely candidate for activex. The website will only be used by clients(as in, it's not a public site) so having to change security settings isn't too big of a deal.
Also, we could possibly have them install an application on their computer, and then when they click a button on the website this activex control just executes the application they already installed to avoid device driver problems..
Does anyone have any ideas on how to do this well? I have a feeling activex won't just let you arbitrarily execute local applications. Also, it is preferred to be possible to do without certificates and signing(though it will eventually be over https)
(it's only tagged C# because that's the programming language to be used on both the client and server)
If you only need to tell the application to simply launch or launch with certain data, you can look into registering a protocol handler and create links, that the user can click, similar to myapp://the/data/you/need/to/send.
It sounds like you will have control over the client and server sides, so why not use WCF and set up the client application to connect to the server via a duplexed communication. On the server side keep a list of the clients that have connected to it and then when you need to trigger the client side code it will iterate over the list of clients and send the message to execute the code. And when the client disconnects it will be unregistered from the server.
See this link for more information on the duplex services.
Also, we could possibly have them install an application on their computer, and then when they click a button on the website this activex control just executes the application they already installed to avoid device driver problems..
Ding ding. That's pretty much what you'll have to do.

Categories

Resources