C# - Send message to an Active Directory user - c#

I would like to send a message to an Active Directory user so when he/she loggs in next time they see the message though a popup window. Is it possible to do it in any way beside using the usual netsend?

This is usually a mess when trying to push out a message to a user. If you want a message to pop up, I would suggest that you create a small application with a pull mechanism. When the user logs in, the application should run to determine if they have a message waiting (messages could be in a central database or even file location). If they do, the application could pop up the message. In this way, the application would also bypass most of your firewall/network segment issues. You would only need to open communication to a central location for the data rather than diagnosing network issues for every client.
Not only would this method allow you to do exactly what you are asking for, it would allow you to expand your application to do even more. For example, you could require the user to acknowledge the message in a more formal way than just hitting OK (maybe make them check a box first saying "I read and understand the message"). You could also capture the time when the user saw the message (they might not log in for hours after you send the message). It could also be used when the user is currently logged in and you want to send them a message (the app could poll the server).
While there are downsides to this method (creating an app, installing it everywhere, managing it, etc.) I think the benefits would outweigh the downsides if you really need to have a notification system like you are specifying.

On Windows 2003 you've got an old fashion way of doing that.
In the scriptPath attribut of the AD user nod, you put the name of a script or exe file for example username.cmd.
On your DC, you've got a folder C:\WINDOWS\SYSVOL\sysvol\DOMAIN.NAME\SCRIPTS shared with the name NETLOGON. you just create the file username.cmd in this folder. the program username.cmd is going to be played on every logon of the user. In this file you can put a popup message.
It's still working on Windows Server 2008 R2.

Related

asp.net or windows service that listen to if you get a Email

I am trying to make a program that will listen to if I recieve a E-mail I got a smtp server and so on.
I want to make a database object with Title and text from the Mail and I might want to evolve it into also saving the attacted file to the database so I can use it it my asp.net program.
I think I need a windows Service that will be listening to the email if it gets a email it will add it to datbase and wait again but I am not sure how to do that. if its possible to program that into my asp.net project then it would be a good thing also
Here is a small design on how I was thinking about it
if you know anything about it feel free to come up with any kind of solutions for me.
Read incoming emails with POP3 or Exchange. I've made something similar before, which was a system where users could add links (a type of linking-scam actually) to different websites. So there was a bunch of people in Asia that had a full-time job searching for relevant sites and emailing a list of these URL's to a specific email-address. A service I had running would check the POP3 inbox every 5 minutes or so and then post these links to the website.
You should make an application that gets run at specific intervals rather than a service, which is much simpler. If you're using Azure as a host you can use the scheduled task service there to make a POST call to a page on your site so you don't have to run the code in a different eco-system. Well, I guess you can do that anyway with scheduled tasks in windows.
Here's a POP3 client for .NET
You could make a C# service that checks the pop3 server in a configured interval, and store them in the DB. There's something like this here:
http://aspsnippets.com/Articles/Fetch-and-Read-emails-from-POP3-mail-server-using-C-and-VB.Net---Part-I.aspx
But as a regular application, you just have to make it to run as service (I think you have a project template for that in VS). You have some info here:
http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
Okay I figured out a good solution for this problem friends :)
What I did was I downloaded the EAGetMail and implamentet it. it basicly works for you in a time interval it will check your mail and make a txt file with all the mails so it wont read it again. it also got a aplication field so everytime it runs it will run the selected application.
So I made a console application that runs trough my folder where it will save all my email's as .eml file. It will check for a sub folder called read if its not there then create it and then check the root folder for .eml files read them and save information from it to the database and then move the file to read.
We did not want to use pop3 cuz we wanted the mails to stay intact så we dont lose any information. so we ran for the IMAP4.
and in the asp.net I just run a query that checks the database and use the files.

Get Windows logged in user's email when offline

We use this code to get the email of the currently logged in user:
var currentUsersEmail = UserPrincipal.Current.EmailAddress;
This works fine when on the network. However, we have laptop users who run our code remotely and in a disconnected state. The above code causes this exception when in this state:
System.DirectoryServices.AccountManagement.PrincipalServerDownException
Message: "The server could not be contacted."
Does anyone know a way to retrive the current user's email that will work both when connected / on the network and when disconnected?
UPDATE: In case you are wondering why we want to do this. Our system has a bunch of methods that send alerts via email. When our developers are running automated tests, we want the emails to be sent to the current logged in user (i.e. the developer) so they can verify the format.
You could rewrite your application so that it uses UserPrincipal.Current.EmailAddress the first time, and perhaps whenever it is online, and then saves that information in the user's AppData folder or registry for reference when working offline. It would require running the application at least one online before working offline, but I don't see how else you could do it without having to ask the user or use a config file.
There is simply no way the System.DirectoryServices.AccountManagement namespace will work offline. It's like asking how can a database driven application work without access to the database.

Chatting and file sharing using C# in Asp.Net Webforms

NET Web-forms based application in c#. I need to add a module in the application which allows chatting between logged in users and users can share files during chatting, like Skype. Meanwhile I have to keep a PERMANENT RECORD of each and every word of conversation and files transferred during the session, on my server. I have a bit idea about the implementation of module to achieve the desired result, but I am sure that is not a good practice. Here is my idea:
Chatting:
While users are chatting, create a data-table which will contain the sender id, receiver id, and message contents. When ever user presses send button or hit Enter, a new row would be inserted in the data-table with both IDs and message contents and then the data-table will be bound to a div etc. to show updated messages to both users. At the end, on an event (like window close etc) data-table will be converted to the XML and the XML file will be stored permanently either on hard disk or in database.
File-transfer:
During chatting whenever user press enter/send button we will check the message contents, if the message being sent is a file (with some extension) then upload the file on server and provide a download link to the receiver.
I hope you got my point.
Problem:
1) I want to share files asynchronously i.e. transfer to the receiver and save on the server at the same time. Is it possible?
2) How to tell one user that the other user is typing?
Is there any better way to implement this module? What sort of knowledge should I have to properly comprehend and implement the module?
Thanks for any guidance.
For web-based real-time chat the current open source standard bearer seems to be SignalR.
There are quite a few discussions here on SO about that product and those should help move you in the right direction.
As far as storage is concerned, that will depend upon the infrastructure you have available and the costs you are willing to incur to build the system.
You might look into using RabbitMQ for message delivery and if you set that up appropriately, you can attach queue listeners that will also perform logging of chats as needed. (There are well documented .NET/C# clients already available for RabbitMQ.) You may also want to check out the Wikipedia page for RabbitMQ.
File transfer would probably be best done through uploading of the file to the web-server and temporary storage there with a link to the file to be downloaded by the other chat client. That causes the server to increase its bandwidth requirements though.
You might also look into running your own XMPP server and using a web interface through SignalR to interface into the XMPP server. It might leverage the most functionality for easing time to market.
Have you looked into SignalR?

Windows 2008R2 service that runs another app, after cold reboot

Im working on application for Windows Server 2008 R2 (.NET 3.5.1) that would work even after cold reboot, without requring someone to log on any account on the server.
Few words about application itself, it is written in c# application for registering employees work time at the company. Users (employees), have thier cards which are beeing scanned by barcode scanner, each scan means either "work started" or "work stopped", everything is serlialized into xml file which is later on modified and put into .csv but that doesn't matter.
Barcode scanner is working as a keyboard, so all codes are beeing "typed" like from a keyborad, to the PC. I made application read the keys despite the fact that console application is not in focus, or not visible at all.
What i need to do is to make that application work even after cold reboot, it has to be fully automatic.
So far i figured out 2 approaches to do it, one is to create a service which would keep another process alive (if its not working, just turn it on), i didin't have much luck with this one, i have already created service that launches another process for me, but the process is working differently, if i would run it myself, there is no communication with the process so i cannot even tell if its the right one.
Another one is to just put my app into registery /microsoft/windows/current version/run, and enable autologon for user with limited prividges. This actually could work but it is not perfect solution, because after all we do not want to have user logged in on server in company 24/7 right?
I know that most of you are way more experienced in programming than i am, so i would appriciate any solutions how to solve my problem
Lichoniespi
Your options depend on physical security of the system (whether passers-by can do much to it apart from scanning a barcode), but let us assume that it is an easily accessible desktop. In that case, you probably do not want a logged in user.
Use the service approach. You do NOT need a separate process for accessing the keyboard. Create a global hook of type WH_KEYBOARD_LL.
Declare your callback function like this and put it into place with SetWindowsHookEx.
I would use the first approach, create a service, and to comunicate with the running application i would be using a network socket or pipe. For the service be sure that you're using an existing user account (not System) and allow it to interact with the Desktop.

Cause Winforms application to show user credentials dialog when a file operation fails

I have a simple updater program that copies files from a company server to the user's machine.
For most people on the internal LAN this is no problem, but some staff access this from LANs where they are not automatically authenticated with the server in question.
Normally an attempt to access this server (e.g. via Explorer) would simply throw up a user credentials dialog asking the user to provide a login that can access the shared directory.
In my Winforms application I simply use operations like File.Copy to move the files.
How can my application cause Windows to prompt for authentication rather than just throwing an exception?
I'm willing to do a fair bit of work myself but what I was really hoping was that Windows provided a way for this to happen.
Otherwise I'm considering just attempting access and showing an error message instructing the user to authenticate themselves using explorer.
Are there any other nice ways to deal with this problem without reinventing the wheel for a 50 line program? :-)
you could use shell API to make that happen (same API Windows Explorer is based upon) - instead File.Copy you would pinvoke SHFileOperation.

Categories

Resources