Auto logon windows at a specific time. How can i do this in c# ?
Any ideas please...
Purpose : I need to perform some tasks at a specific time in midnight. which needs the windows to be logged on.
Take a look at the Scheduled Task. On the task panel you un-check the option "only after the current user logs on". That's it.
Update
So to make this with a little more explanation:
This was your question:
Purpose : I need to perform some tasks at a specific time in midnight. which needs the windows to be logged on
So to get this to work, you have to split your task a little bit up. At first write your task that should be performed (a batch-script, a self-written application, a third-party application with a configuration file or some command line parameters, etc.).
If you got your task up and you can run it on a single finger tip (e.g. click on a lnk file on your desktop, enter a single command on the command-line, etc.), it's time to automate your task for a specific time schedule. For this purpose Microsoft already provided a powerful tool, called Scheduled Tasks. It is located in the Control Panel. Here you can define Tasks which should be started with dozens of options and time plans. Just step through the wizard and after that make a double click or right click - Properties on the created task. Now step through all the TabPages and take a close look on all the available options. Everything you need can be solved here.
Update 2
So after reading your comment (and a few other):
If my system is locked, then i need it to get unlocked at a point of time
My first question would be: What do you mean with locked?
There are two states in which a system can be locked:
The system is freshly started, no session is running and you need to provide a username and a password to get a session to run.
A user has already logged in and the system is currently locked (cause the user pressed WinL, the screen saver is configured to lock, etc.).
The difference between those two states is, in the first you need to provide a username and a password, in the second one you only need to provide the password only.
What both have in common is you have to press CtrlAltDel to get the needed Dialog and this is not possible from an application.
If you really need to log-on or unlock the screen at a specific time you should start a search about gina.dll and how to replace or enhance it so that you can send a message to it, to do whatever you like. But this dll replacement can't be done in C#. It has do be done in C/C++. And i forgot, that the gina.dll approach only works on XP. For Vista/Win7 they changed the log-on process and the procedure to intercept it, but a search for the provided keywords should reveal the needed informations.
look at this thread.
You can replace your app with userinit.exe.
it runs before Explorer.
Related
i have a rental website and when someone wants to make an offer he has 7 min to pay, if he wont pay the offer will delete.
i have a timer on my form to check the time, and when the timer is on 0:00 and the user didn't pay his offer will delete.
MY question is how can i check if user log out? i mean user can exit from the site (by clicking X) and his session will end.
i want to delete his rent offer if user quit from the website.
Thanks for the helpers.
For this scenario, I don't think its a good idea to rely on browser events, such as onunload & onbeforeunload. User may have opened more than one tabs. So closing one tab will remove the offer. Furthermore, if the user click back button these events will be fired. So don't rely on browser events for this.
(But, if the user clicked on LogOut then you have enough information to delete the offer.)
Perhaps you can use following approach to handle your original problem:
When user create a new offer store these details in the database with two extra columns: OfferCreatedUtcDateTime and PaymentCompleted(which should be false).
If the user completed payment successfully, you can set PaymentCompleted to true.
Then you can use one of the following two options:
Option 1:
Create a windows service which will check above database columns. If the PaymentCompleted == false and OfferCreatedUtcDateTime + offer valid period > CurrentUtcDateTime then you can delete this offer.
Option 2:
As mentioned by #nvoigt in the answer, every time user search for a resource you can ignore or delete offers which satisfies the condition mentioned in Option 1.
Hope this helps.
First do not fulfill offers that are older than your timeout(7mins) I'm assuming that you have OfferCreatedDate timeStamp. Second create a job that will clean all unfulfilled and expired offers. Hope this helps
You cannot. Not reliably. The user will not send you a nice message when he does not do something.
You can program your site to send you a signal if something happens, but you need to know when something doesn't happen. And it can "not happen" in multiple ways, many of them not allowing a signal to be transmitted.
Just imagine your user's train goes into a tunnel or he kills his browser, his computer crashes or cell phone loses battery power. All events that happen daily and all of them will not notify you nicely. They cannot.
So what you need to do is figure out a way to delete all obsolete orders. Either on a timer in an independent service, or maybe before a user places any order. But you need do that in a place independent of the user playing nice with your frontend app.
One way of handling this would be to save the date and time of creation with every offer you give out. Every time you check available resources and create a new offer for a user, delete all offers that are older than your limit before giving out new offers, thereby freeing up the blocked resources.
What about not focusing on how to set the timer to 0 when user session end but check other users timer's when another user create one ?
Then you can still have the checking process for the connected user, when it goes to 0 it stopped but for the case the user close the windows or leave, when another user create a reservation you also and firstly check if there's timer still alive older than 7 minutes and you release them so the user currently doing a reservation can do this one that has just been set as available ?
I need to develop an application that will run on clients. The main focus is to let the application update another -specific- application and be able to monitor own defined states for clients. I'm considering something like a console application with TopShelf because it makes debug a lot easier. However... to install or update this specific application I must use a MSI. But if for example I create a process that executes msiexec the client/end user will be prompt with UAC. This is a big issue because clients should be updated unattended. And UAC must stay the way it is : highest level.
I've read a lot of questions/answer concerning UAC prompt... and to be honest I'm starting to doubt my own approach. I was not able to find any question that I could relate to.. so I would appreciate it if someone could give me some good advise, tips, references etc on a possible way to approach this issue.
Thanks in advance
Create a Task Scheduler job with the "Run with highest privileges" option checked.
You can easily create this job programatically, even using a XML configuration file.
This way the user is prompted to allow UAC only once (when first clicking an exe for example).
I am writing an application in c# to lock or freeze all programs untill user enters a value in the app's textbox and clicks ok.
The purpose of the app would be to get people to enter their time.
As far as I know you can set it to top most but they can end the app with task manager so am stuck here..
formName.TopMost = true;
Any help would be appreciated
Yes, that's correct. The Windows operating system allows multiple programs to run at one time. What you're experiencing is entirely by design.
If I remember correctly, the TopMost property applies only to windows in your process, and as you mention, it's all quite irrelevant: the user can still kill your application using the Task Manager.
There's no legitimate way of getting around that. It's not a "limitation", it's a feature. Any app that prevents itself from being closed by the Task Manager is treading dangerously closely on the category of software that we call malware. Nothing good can come out of pursuits like this.
Relevant reading: The arms race between programs and users
Perhaps a good compromise solution is to make your window/form actually top-most and disable the Close button so that the user knows they shouldn't try and close it. This is almost always enough to stop a user that is not determined to end your application by any means necessary, and that's about all you should ever be concerned with.
See the sample code here for how to make your window/form always appear on top of other running applications by setting the WS_EX_TOPMOST flag or toggling HWND_TOPMOST.
I've also already written a detailed answer here about disabling the Close button the correct way by setting the CS_NOCLOSE class style.
Okay I've spent the afternoon researching and haven't had much luck finding the answer to this. I am trying to prevent an application from launching via some sort of dll or background application. It is to be used in monitoring application usage and licenses at my institution. I have found leads here regarding WqlEventQuery and also FileSystemWatcher. Neither of these solutions appear to work for me because:
With WqlEventQuery I was only able to handle an event after the process was created. Using notepad as a test, notepad was visible and accessible to me before my logic closed it. I attempted to Suspend/Resume the thread (I know this is unsafe but I was testing/playing) but this just hung the window until my logic finished.
With FileSystemWatcher I was not able to get any events from launching a .exe, only creating, renaming and deleting files.
The goal here is to not let the application launch at all unless my logic allows it to launch. Is this possible? The next best solution I came up with was forcing some type of modal dialog which does not allow the user to interact with anything, once the dialog is closed the application is killed. My concern here is killing the application nicely and handling applications with high overhead when they load such as Photoshop or something. This would also interfere with a feature I was hoping to have where the user could enter a queue until a license is available. Is this my best route? Any other suggestions?
Thanks
edit: To clarify this is not a virus or anything malicious. It's not about preventing access to a blacklist or allowing access through a whitelist. The idea is to check a database on a case by case basis for certain applications and see if there is a license available for use. If there is, let the app launch, if not display a dialog letting the user know. We also will use this for monitoring and keeping track if we have enough licenses to meet demand, etc. An example of one of these apps is SPSS which have very expensive licenses but a very limited pool of people using it.
Could you use
System.Diagnostics.Process.GetProcessesByName
in a loop to look for the process?
It might work if you don't use too aggressive a polling rate.
You are indeed close, take a look at the WMI Management Events. http://msdn.microsoft.com/en-us/library/ms186151%28VS.80%29.aspx
Sample code from Microsoft: http://msdn.microsoft.com/en-us/library/ms257355(VS.80).aspx
Subscribing to the appropriate event will provide your application with the appropriate information to perform what you described.
Not sure if this is a GOOD solution but you could do something like pass a key into main so that if the key is not present or valid the application shuts down. Then when you open the application in your code, just pass the key in. Someone would then have to know the key in order to start the application.
This is assuming you have access to the application in question's source code, which upon reading your question again, I'm not so sure of.
I assume you don't have source for the application you want to prevent from loading...
Have you considered using a system policy? That would be the best-supported way to prevent a user from launching a program.
You could have a service running that force-kills any app that isn't "whitelisted", but I can't say how well that would work.
I wonder if you are taking the wrong approach. Back in the day there was a Mac app that would prevent access to the desktop and had buttons to launch a set list of applications.
IDEA
What if you had a wrapper for the approved apps then only allow your wrapper to run on the computer?
I would expect there is some way of hooking an application launch, but can't help directly on that front.
You may be able to improve your current approach by detecting the application's window opening and hiding it (move it offscreen) so that the user can't attempt to interact with it while you are trying to shut it down.
However, another approach that may be possible (depending on your circumstances) would be to write an application launcher. This simply is a replacement for the shortcut to the application that checks your licencing conditions, and then does a Process.Start to launch the real .exe at that point. This would work well for any application. (I used a system like this for starting up applications with specialised environment settings and it works beautifully)
You could combine this with your current approach as a fall-back for "clever" users who manage to circumvent your launcher.
If my understanding is right you want to create an application what will prevent the computer user to start any other process except ones for a white-list.
If this is the case, monitor the process list of processes (in a while loop) using System.Diagnostics.Process (the GetProcesses method gives the list of all running ones)
Just kill the process when it starts.
Or if your machines have Windows 7 (Windows 2008??) you can use AppLocker. http://www.microsoft.com/windows/enterprise/products/windows-7/features.aspx#applocker Just let Windows prevent the startup.
You might want to look at this product: http://www.sassafras.com/licensing.html Personally I can't stand it, but that's because it does what you describe. Might save you some coding.
You could actually edit the registry so when you click a psd, your launcher gets called instead of photoshop. Your launcher then checks for licenses and if there is one starts photoshop with the path of the file.
This is a long shot but you may find it helpful.
Perceived Types and Application Registration
http://msdn.microsoft.com/en-us/library/cc144150(VS.85).aspx
I need my winform program to run as another user (it will run under task scheduler) and not the logged on user. I suspect the trouble is my app is gui based and not command line based (does this make a difference) so the gui needs to load do its thing and then close. Is this possibly under XP or Vista?
Thanks
Scheduled Tasks can be 'run as' a specified user, which can be different to the logged-in user.
You can specify this user when creating the task, or by editing the properties of an existing task.
If your app needs to run as a sheduled task then it can't really have a UI. As a bare minimum it should really be capable of being run via the command line.
The best approach would be to separate the UI from the actual processing so that the you can still run it interactively if required. This would also make testing your app a whole lot easier.
EDIT: Edited for typing and sense
I'd vote for the first option, or to provide an extra possibility: Use Impersonation in your code. Although it might be overkill/not fit your needs here.
Another way you could execute the program is to Programmatically change the user based on a config file or even a DB connection. One sample project is on Code Project:
http://www.codeproject.com/KB/cs/runas.aspx
Hope this helps.
You're looking for the Process.Start method. One of the overloads accepts a user name / password pair. The process will be created using those user credentials.
var app = Process.Start(#"c:\path\to\some\app.exe", userName, password, domainOrEmptyString);