The desktop application is being developed with a demo version that is supposed to run for a few minutes and after that would request the user to restart the application to run again (the user has to input their login and password to access it), since I dont know much in this field the way I can think of doing this without the user bypassing it would be having a realtime communication between both or something of the sorts.
After X minutes the server sends a
message to the client to close/disable
the client requiring the user to
restart it, it also limits the daily
usage on the demo for the same user.
As I am very inexperienced in this type or communication I would like to consult you guys with what options I have here ?
The desktop application is developed in c# to run mainly on windows OS as for the server we only have linux available and as to what sort of service, if it is possible to make a webapi or session in php or perl to work with it that would be reliable enough would be nice but if that is not possible we are open to hear other options.
PS: If I have'nt given enough information or am missing anything important here please drop me a comment i will update as soon as possible.
I'd give a go to HTTPS with mutual certificate-based authentication as the safest option. The desktop app can poll the server (=ask periodically) and quit in case of no response / no connection / negative reponse.
However, based on the type of app you are developing and the target audience, you can expect an important amount of users to have connectivity problems or have no connectivity at all.
Because of this, at the end of the day, you can come up with a lot simpler solution, like measuring run-time locally without any server involved, and gain pretty much the same effect.
I don't think you need to involve a server to do this.
Just have the desktop application save the date and time when it started. Periodically on a timer you can check the current time, and see if too much time has elapsed for the demo version, and tell the user they have to quit.
It is very unlikely many users will try to get around this. They are more likely to dump your trial software in favour of something that treats them decently!
Checking DateTime.Now could work as Ben stated, but you'd be better off with System.Timers.Timer. Set interval to be your desired interval between auth calls in milliseconds. Attach a handler to the elapsed event that asks for auth info. System.Timers.Timer works in a separate thread so you can take advantage of some parallelism here. Changing the system time shouldn't have any effect on System.Timers.Timer but I am not positive on that point.
Related
I have made a desktop software in C# and i am going to make a 30 day free trail of the software ,now i will check the date and time from some server to check the date ... My question is, can the hacker hack this and produce somekind of key or steps to make it full version or produce some crack of it in the market for everyone(I know that a hacker can hack any product )???
Actually, a hacker can figure out what you are checking a date by REST API, by the monitoring of http traffic, then change the DNS name of your API to local host locally and provide you fake REST API response.
Sure, any software running on the desktop can be decompiled or reverse engineered. Then a patch can be created to disable any security features you've build into the application.
But this requires a lot of work. Not many applications are valuable enough for some hacker to spend so much time on it.
As others have already replied, it's trivially easy to intercept http(s) requests made to a server. Why don't you just use the date/time from the machine/device itself? Not many people will be willing to live with a date set back on their machine just to run your software illegally.
The real problem is where do you store that date. The first time the user legitimately installs your trail, that date won't be present. What is to prevent users from deleting that date and starting the trail period over?
To protect yourself from all this, run (parts of) your software in the cloud. But in that case, you'll need an authentication mechanism for your users.
I have a requirement that a Windows Forms C# .NET 2.0 program running in user-space (not a service) must always be running. As I'm not infallible and make coding mistakes, I wanted to know of any extra safeguards I could use to ensure this requirement is met. The things I've been thinking of are TaskScheduler to check it every 5 minutes, A stub watcher or a secondary process. Are these good / bad ideas?
Thanks,
Richard
EDIT: The reason I didn't use a service (the obvious and sensible answer!) was the program runs in a kiosk type environment and has has a heavy GUI component. The service option didn't work well across Windows 2000 - W7.
EDIT: The second reason not to use a service was the app needs internet access and on some of our customer sites, proxies are set up to only allow specific users (not the local system account) so it would be tricky to ensure access if multiple users log onto the machine.
Task scheduler is a cheap solution for this which does work. I use this to keep our Perforce Proxy server running (had some issues with the service), and so far there's been no problems - though now I've said that the server's probably exploded!
However, the most complete solution is a Windows service which invokes your app. You can make that service catch error return codes from the app, restart it on failure and notify you by email, which may help you diagnose and fix those issues. I think the Task Scheduler does something similar but it won't be able to provide as much insight into your application as a custom service.
If you're unsure of how to do that, then something like this should work:
http://www.codeproject.com/KB/install/csharpsvclesson1.aspx
There are three approaches that you can take:
Heartbeat Message.
A heartbeat is useful in a distributed application and is simply message that is sent (from let say a client to server) to confirm that it is still healthy/running.
Manager Process
A stub program, implemented as either a user process or a service. It launches the main application, monitors any unhandled exceptions, reports errors, and restarts on failure.
An exception guard on the entry point.
A try-catch-all in the application entry point.
I would recommend either of the first two options; the third option, the try-catch-all, is a particular nasty hack for the lazy and inexperienced programmer (IMHO).
I have successfully used both heartbeat and manager process in a large distributed application.
UPDATE
As for ready-to-go™ restart managers, take a look at the Windows API Codepack as discussed in Emmanuel Istace blog post (http://istacee.wordpress.com/2013/09/21/automatic-recovery-restart-in-net-application/).
You can install the package from https://www.nuget.org/packages/WindowsAPICodePack-Core/
I once used a command line SMTP mailer that, as a limit of the trial version, allowed you to receive up to 10 emails with it per Windows session. If you rebooted your computer, you could receive 10 more. I thought this kind of shareware crippling was pretty neat, and I'd like to replicate it in my app.
I'm just stuck on how to do it. I know how to limit the user's actions, but how can I tell if the computer has been restarted since the application has been last run?
The OS is Windows and the language is C#.
You should be able to find events in the event log, such as the event log service start that would tell you if the computer has restarted.
Here's how to read the event log in C#:
http://msdn.microsoft.com/en-us/library/k6b9a7h8%28VS.71%29.aspx
// C#
foreach (System.Diagnostics.EventLogEntry entry in EventLog1.Entries)
{
Console.WriteLine(entry.Message);
}
Note: you should provide the language and OS you are using.
If you're using .NET, you can use Environment.TickCount for this. This gives you the number of ms since the system started. Note that it rolls over every ~24 days, so you'll have to compensate for that (if you care).
For Windows, if you want to check the computer booted
Type on the Command Prompt
C:\>net statistics server
One of the statistics will be
Statistics since 22-Jun-11 10:46:20 which was the last time the computer booted
For Windows platform you can use uptime.
C:\>uptime
\\SPOCK has been up for: 2 day(s), 0 hour(s), 45 minute(s), 34 second(s)
The answer above is for Pre-Windows Server 2008 systems, but for Windows 2008 there is a much easier way of finding the uptime for a Windows 2008 server.
Task Manager > Performance > Up Time
Couldn't you just keep a counter of the number of events your application has performed. And then stop when the counter reached threshold? If your application contains a service then it could be embedded as part of the service which would be restarted with the windows sessions. I suspect that is how the SMTP server worked, at least that is the simplest way that I would implement something like that. It would keep most novice/intermediate system admins restarting the box, and the smart ones probably deserve to have the software for free anyway.
I'm using c# to communicate with twitter and i need to code a schedule system to send twitter messages at a user defined date.
The messages to be sent are in a database with the date and time of deliver.
Which is the best method to check the db for scheduled messages and send it when the time arrives?
How accurate do you need the timing to be? Could you get away with polling the database every 5 minutes, saying "Tell me all the messages which need to be delivered before current time + 5 minutes" and then sending them all? (And marking them as sent in the database, of course.) Does it matter if they're a bit early or late?
You can do the scheduling on the C# side to make it more accurate, but unless you really need to I'd stick with a very simple solution.
(Depending on your database there may be clever ways of getting callbacks triggered etc... but again, I'd stick with the simplest solution which works.)
In addition to the windows service option (or background thread), you could just set up a scheduled task to run an app that polls the DB and sends the tweets once every defined interval.
Windows schedules can be setup using C# if needed and are really easy to set up manually.
There are several ways to do this, but I guess the best way is to set up a Windows Service that will periodically poll (frequency is up to you) the DB for any scheduled tweets that hasn't been sent.
Needless to say you'll need to handle scenarios such as the Internet connection or DB being down, etc.
In fact the solution consists in using a windows service but it can't communicate directly with the ASP.NET MVC app. I've added a Web Service that handles the task and a System.Threading.Timer in Windows Service to periodically call the Web Service.
I want to develop an Online Reminder service in ASP.NET 2.0 (C#) and SQL2005. But I am not getting the concept of reminder service. What I know is using an online reminder service I can schedule a reminder for future dates, which is sent to me (who schedule reminder) via email or SMS on that date. But in asp.net how to do this, caz anyone can schedule a reminder for any date, how we'll know that when to send that mail to the person. We have to put some loop or what.
So please guide me, what is the concept of an online reminder service and how I can easily develop this application using ASP.NET and SQL
Edited
I am on Shared hosting server, so that solution must be able to work on shared hosting.
Or
Please tell me if anyone knows about any FREE and open-source reminder service CMS which I can download and study it.
Microsoft SQL Server 2005 have scheduling (sql jobs) and email features. You may even donot need to use ASP.NET.
Ideally, you would have a windows service that would periodically (every few minutes) check if any new reminders need to be sent out. Since you are on shared hosting, you probably can't install a service though.
I'm not very familiar with windows shared hosting, but if you have the option of creating scheduled/cron job type tasks you could probably do it that way.
If you can't create a scheduled task on your server, another option would be to create a scheduled task on your home PC with a program/script that runs every few minutes and simply hits a special web page on your site. That page could then have the code that checks for reminders and sends them out. It's a bit of a hack, but it should work.
Have a look at Quartz.Net (http://quartznet.sourceforge.net/). You can create an instance of the quartz scheduler in your Application_Start event and as long as the ASP.Net application is running, it will poll the database and trigger any functions you have registered with it. Since you are on a shared host environment, this is probably your best bet unless your hosting provider has a scheduler that can trigger a WebForm (or ASP.Net MVC Controller) periodically.
First you will obviously need to create a user interface and database to store the reminders. That part you got. The next step is to create a service which periodically queries the database for reminders that are due for notification.
The best way to do this is to write a lightweight Windows Service which, as you suggest, uses a loop and a reasonable sleep time (so as not to monopolize the CPU) to continually check the database for reminders and dispatches notifications. It then processes each reminder based on your requirements.
But since you are on shared hosting, you can't deploy a Windows Service, so the next best thing is to run a background thread on Application_Start of your global.asax. There are many examples of how to do this, e.g.:
http://www.west-wind.com/WebLog/posts/67557.aspx
What are some best practices for managing background threads in IIS?
Shared hosting will not work well with what you are trying to do. You could create a background polling thread on Application start, but it will get shut down at some point and may actually be prohibited by your hosting company. An infinite loop will most likely be detected by your hoster and result in your account being automatically shut down, especially if it is using a fair bit of CPU. As John suggests, there may be a scheduled tasks or hosted cron option with your ISP, but generally, those are just for doing things like nightly backups, not really having the level of granularity you need.
Simple answer is, you most likely need something other than a hosted account. You may need to look into a VPS shared hosting service or you may wish to consider looking into MS Azure or Amazon EC2. To do this right, you need to create an application, or better, a service that runs constantly, something a shared hosting account will not provide.
There also a few services out there who can call a specific web page on your service periodically. You could use that to make the page check if there are any reminders that need to be sent.
However since you're then relying on an external site you can't control this might not be the ideal solution if it is very important that the reminders are always being sent.
1) Create a database for storing messages, with a datestamp
2) Create an SQL job, that selects all messages in a time period
3) From the SQL job, you can initialize an .net based SQL Function, that would send out the emails with the System.Net.Mail namespace.
You might consider a 'hack' using the Cache expiration in for triggering events. Create new cache keys that expire at specific Date-Times to run the reminder or make it recur at defined intervals, checking a queue to see if anything new should be sent.
See:
Easy Background Tasks in ASPNET