How to run Windows service when user is authenticated in OS - c#

I have Windows service created with C#, but this service is working good when I start manually.
If I want to set automatically start, this service not work correctly.
If I want to login with my account this service not work.
I have installer in my project.
What can I do?

Related

How do I log into a web service that was auto-generated by Azure Mobile Web Services?

Microsoft's Azure Mobile Web Services lets you download a .NET or JavaScript Service and a client that talks to the Service. These are written in C#, or JavaScript. I chose to get one in C#. There is are several parts in the generated solution
A Windows 8.1 desktop client (yourname.Windows)
A windows mobile client (yourname.WindowsPhone)
A Azure Mobile Web Service (yournameService)
A shared .net assembly named (yourname.Shared)
You can right click on yournameService and click Publish and it takes you through a wizard which publishes your application directly from Visual Studio to an Azure server. At some point in the wizard it establishes automatically some rather complex credentials (because you have already logged into an Azure web subscription). Generally you can just click Next, Next, and get it published.
Now you have a webservice, which opens up in your web browser, but which requires you to log in. What I want to know is, how do you know the user name and password used for this login?
http://yourapp123.azure-mobile.net/help
Then you click "Try it out", and a web browser authentication dialog pops up.
Why is this a problem? So far as a user I have input:
My Visual Studio login credentials,
My connection to Azure (perhaps same, perhaps different as visual studio login)
During wizard I've determined login credentials to publish to Azure, using values I have no idea where they came from, and so I left them alone. These seem to be the only credentials I had any opportunity to enter, and any change from the defaults renders the wizard inoperable, so I'm sure that's not where I enter my user and password.
I created a username and password when I created the Mobile WebService, and these do NOT work when I try to log in.
Leave the user name blank. And put in your application key as password. You can find your application key from your Azure portal > Mobile service > manage keys.
The reason being is that AMS uses a Zumo header to decide proper authentication. Which is what the application key is used for. So it's making sure only people or applications which has the application key can access the web service. Hope this helps.

Windows Authentication in Windows App

I have a stand alone Windows app. I want to bring Windows Authentication into the app for logging purposes. I can't find anything on the web about how to do that. Or something similar. The app was written in C# VS2012.
If you only need to log the information, then getting the current user running the app should be enough. To get the current user you can use the WindowsIdentity.GetCurrent() method, which returns a WindowsIdentity that has a Name property:
Console.WriteLine(System.Security.Principal.WindowsIdentity.GetCurrent().Name);

Why does Windows Authentication fail when using Windows Azure Emulator?

I created a Cloud Service project containing an MVC Application in a Web Role, and a Worker Role. In the MVC project, I am using Windows Authentication...and certain fields are managed based on the user being authorized (no biggie).
When I "Set As Startup Project" to the MVC project, my Windows Identity Principal comes across fine...and everything displays & works as expected (which is good).
Then, it becomes time to work-on & debug the Worker Role. To do so, I must run the Windows Azure Emulator by choosing "Set As Startup Project" to the Cloud Service project itself (and then pressing F5). Doing so fires-up all the Cloud Service roles within the Windows Azure Emulator.
However, when I do this the IsAuthenticated property is false...and all my HTML elements disappear.
QUESTION(S):
- Why does running the Windows Azure Emulator locally prevent Windows Authentication?
- If I need to "setup" the emulator...how?
PORTION OF THE SERCURITY CODE:
Nothing special here...
var identity = filterContext.HttpContext.Request.LogonUserIdentity;
if (!identity.IsAuthenticated)
RedirectToAccessDeniedPage(filterContext);
PORTION OF THE WEB CONFIG:
Nothing special here...
<authentication mode="Windows" />
<identity impersonate="false" />
When you setup the MVC project as the startup project, you are essentially running the project locally on your machine through IIS. IIS will automatically use your current NT credentials as the currently logged in user, which makes sense.
As hinted by Parv Sharma in his comment, when you set the cloud service as the startup project, a separate VM emualtor is started, simulating what would happen in the cloud. Although the VM also runs your application in IIS, it has no idea who you are since you haven't logged in yet. And because your local NT credentials are not stored in that VM (and it doesn't make sense to store user credentials in a VM regardless), IIS doesn't recognize you as being logged in.
So you will need to implement a form of authentication form that will allow users to authenticate against a Directory Store, which is what Azure Directory Services is all about. Here is the MSDN documentation for Azure Directory Services scenarios which contains a link for a sample implementation.

Windows Azure Deployment Change

I created a program and deployed it into the Windows Azure Portal but now I want to change the account that it is associated with but it won't let me. Is this possible and if it is could someone point out how to do it because I can't find a way so far. I created a web service that held data that is consumed by a client and I want to change the associated Windows Azure Account but it keeps trying to publish the service onto the account I used to begin with instead of the new one, even when I sign into my new windows azure account. Using VS to publish the service to the portal
Thanks.

Switch user that services run as dynamically

I have a Windows Service that runs, and currently, it runs under whatever account installed the service onto the computer.
Is there some way, using code, that I can switch the active user that the service runs as, dynamically, without any user interaction or GUI? I'm a little inexperienced when it comes to services, so I'm not sure if this is possible. Any info on the topic would be appreciated. (VB and C# code is okay)
Assuming you included a class that inherits from Installer as part of your service code to handle the service installation you can change the Account for the Service Process Installer component to specify LocalService, NetworkService, LocalSystem or User. However, if you specify User then you will either need to encode the username and password in the code. If you set it to User and don't provide these values then when InstallUtil.exe is run to install the service it will prompt for the Username and Password.

Categories

Resources