windows-services

C#.NET Getting User Name of machine using Windows Service

微笑、不失礼 提交于 2020-01-11 09:38:08
问题 I am having difficulty getting the User Name of a person logged into a machine using a windows service. When using both System.Environment.UserName or WindowsIdentity.GetCurrent().UserName I get NTAUTHORITY\SYSTEM but when this application gets pushed I need to be able to map to the UserID of the person logged in to the system. The operating system this will be used on will be Windows XP. Any help would be very appreciated. 回答1: For XP only, this advice should apply: Get Window Station for a

How to get current windows username from windows service in multiuser environment using .NET

 ̄綄美尐妖づ 提交于 2020-01-10 06:00:13
问题 I have a windows service which run a WPF application all the time for all the logged in users which works fine, now in the WPF application i can not get a current username as Environment.UserName; returns 'SYSTEM' which is understandable. so what i thought was to find session id of current process which could be retrieved by Process.GetCurrentProcess().SessionId and then get the list of all users logged in to the machine and looping through it to find the session id match with process session

cannot open window service on computer '.' in window application

三世轮回 提交于 2020-01-10 01:04:48
问题 I develop one window application and I also create one service. I start the service using coding in window application, but I am getting an error like cannot open window service on computer '.' I have used below code. ServiceController controller = new ServiceController("SeoMozScheduleService"); if (controller.Status == ServiceControllerStatus.Stopped) { controller.Start(); } If i right click on Application and click on Run as Administrator than it works fine for me... 回答1: To make this

How to pass parameters to Windows Service?

纵饮孤独 提交于 2020-01-10 00:52:11
问题 I tried to pass parameters to a windows service. Here is my code snippet: class Program : ServiceBase { public String UserName { get; set; } public String Password { get; set; } static void Main(string[] args) { ServiceBase.Run(new Program()); } public Program() { this.ServiceName = "Create Users Service"; } protected override void OnStart(string[] args) { base.OnStart(args); String User = UserName; String Pass = Password; try { DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment

How to pass parameters to Windows Service?

非 Y 不嫁゛ 提交于 2020-01-10 00:52:11
问题 I tried to pass parameters to a windows service. Here is my code snippet: class Program : ServiceBase { public String UserName { get; set; } public String Password { get; set; } static void Main(string[] args) { ServiceBase.Run(new Program()); } public Program() { this.ServiceName = "Create Users Service"; } protected override void OnStart(string[] args) { base.OnStart(args); String User = UserName; String Pass = Password; try { DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment

Start / Stop a Windows Service from a non-Administrator user account

前提是你 提交于 2020-01-08 11:21:29
问题 I have a WindowsService named, say, BST. And I need to give a non-Administrator user, UserA, the permissions to Start/Stop this particular service. My service runs on a variety of Windows OS, starting from Windows Server 2003 to Windows 7. How can I do this? I Googled and found some stuff about giving permissions using the command [sc sdset], but I am not exactly sure about the parameters. I do not want to set the permissions for a group, but ONLY to a particular user, UserA in this case. 回答1

Connection between windows service and sql database

若如初见. 提交于 2020-01-07 01:31:15
问题 I am trying to establishing a connection between a Windows service written in C# and a SQL Server Express database. But when connection.open is called I get this exception System.data.sqlClient.sqlexception: {"Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed."} But the same code works fine when I run it as console application.Can someone please help me with this?? _connection = new SqlConnection(

Powershell in c# and permissions

荒凉一梦 提交于 2020-01-06 19:37:06
问题 I am running PowerShell scripts from a Windows service running as SYSTEM account. To increase rights I am letting users select a user that I later impersonate the whole thread as using LogonUser method. This works so that I can access network drives and when I try to print the current user in PowerShell that works too. But I have a case when it does not work: One example is a user trying to load Exchange snapin and run cmdlet: Get-MailboxPermission Then he get error: The term 'Get

How to create a service in Python in Windows?

南楼画角 提交于 2020-01-06 18:13:40
问题 I have found http://code.activestate.com/recipes/576451-how-to-create-a-windows-service-in-python/ But that service does nothing. How can I use that service for running specific Python file? 回答1: You can put your business code in SvcDoRun . The sample at your link just logs a message every three seconds. Just don't forget to check self.hWaitStop periodically. Sometimes it is convenient to create a worker thread and do all work on that thread, or maybe start a child process. An additional

How to create a service in Python in Windows?

时间秒杀一切 提交于 2020-01-06 18:10:56
问题 I have found http://code.activestate.com/recipes/576451-how-to-create-a-windows-service-in-python/ But that service does nothing. How can I use that service for running specific Python file? 回答1: You can put your business code in SvcDoRun . The sample at your link just logs a message every three seconds. Just don't forget to check self.hWaitStop periodically. Sometimes it is convenient to create a worker thread and do all work on that thread, or maybe start a child process. An additional