My PC is in Domain A and a remote server in Domain B, I want to restart a service on server from my PC using c# or any other language or script.
Notes:
I am connected to the server via VPN that means i can manually RDP the server and can manually restart the service.
I am not able to access services on server using connect to other computer under action button from local services window.
I have admin rights to the server.
I can't(not allowed) add any component to server.
I have different set of credentials for Remote machine
You should first try the sc command to make sure you're able to start that service remotely using the current permissions and credentials. If that works, take a look at System.ServiceProcess.ServiceController.
When you say you're an admin on the remote machine, I'm assuming that means you're logging in with different credentials. I don't believe either of those will allow you to use alternate credentials -- i.e., the commands will execute with Domain A privileges and those privileges are most likely insufficient for what you're trying to do.
Can you use a batch file? I usually use something like this:
NET USE \\computername\IPC$ /U:domainname\username password
SC \\computername START service
Related
I have a server with a bunch of installers on it. However my program stops when I attempt to initiate connection to the server.
Process.Start(#"\\{Server ip}\Software_Depot\Installers_Master\Snagit\v2019\snagit.exe");
What I'm trying to do here is initiate the installation of snagit.exe from our server.
Check the permissions of the elevated user that’s being used. If it’s a local admin account, it might not have permissions to the network share.
You could either add a “net use .... domain-user password” or use a domain account to launch your .net app.
I'm writing a windows service that must to write log files in a remote server, which is part of my network via secure VPN connection (P2P), so i can write log files in a directory (like "\10.10.10.10\MylogFolder\log.txt") via Console Application, that I use to test my business classes.
Via Console App, it works correctly but when I try to inject the business class to the service, it doesn't work...
I believe that it's a Installation/Privilege issue, I've already put my WinService to install using LocalSystem privileges but it didn't work as well.
Can you help me?
Thanks in advance!
LocalSystem is a very limited account for network access.
You'll need to set the service account to be something that has the required privileges on the remote machine.
i have a huge problem with my Windows-Service (C#). We had a system change on a few servers (from windows 2012R2 to Ubuntu) and for all these servers i wrote a monitoring tool as windows service running on a windows server. In this service i checked a few things on the server which worked fine. One of the things i had to check was if some special windows services (e.g. iis) are in state = running.
So - is there ANY possibility to check an Ubuntu-Service programmatically from my monitoring service? Can i set commands on the Ubuntu shell? Or start a bat File?
ServiceController sc = new ServiceController("servicename", "ubuntu-IP"))
Using a ServiceController doesn't work i guess because of Windows != Ubuntu?!
It should be an "easy" way to do it - so if it would be too ornate i just don't do it.
Any information would be appreciated.
EDIT: totally rewrote, I misunderstood the question.
Linux does not use services the way Windows does, first of all there is no infrastructure to remotely check and manage the services like in a windows domain.
You have two options there:
1-Connect through SSH with an account with admin privileges and issue "service (servicename) status", this wil yield if the service is running or not. To connect through SSH the servers must have an SSH server configured and use some C# library for the SSH connection (per example this: https://sshnet.codeplex.com/)
2-Create a C# service and use Mono on your servers, in this way that service can execute commands locally like "ps" or use Process.GetProcesses(), then you can comunicate this process with your Windows process the way you best like, per example TCP or UDP.
I'm trying to run an WQL query(SELECT * FROM MSBTS_SendPort) on an BizTalk host but when I run this query in my console application on an remote primary BizTalkHost I get an COMException who says "Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'."
If I run the same console application on the primary BizTalkHost then everything works.
I'm issueing an double-hop authentication issue, so therefore what I want will never work. See this link for more information. My workaround for this issue is to create an wcf-webservice on an biztalk host and let the wcf service handle the WMI query.
If you want to use powershell for remote biztalk administration look at this link.
Looks you execute the query on the remote machine as a anonymous user - you have to be in the user context of a user that is authorized to read from the BizTalk Management database.
You could start with trying to run the console application on the remote machine using "run as" and enter the credentials that you probably login as on the BizTalk machine.
If that works you should start looking to impersonation a different user in you code.
I have two machines, we'll call them machine A and machine B. Machine B is running a Windows service written in C#.net, as the Local System account. Machine A tells machine B's service (using WCF) to open a file located on the network. Since local system is not a network user, it does not have access to network files, and is unable to open the file. Currently, I am reading files from machine A and serializing them as strings to machine B, and then writing them locally on B. I've considered making a generic network account for machine B, so it can have access to the network, however this is undesirable. Is there any way I can make machine B open files using the user account of machine A? I've taken a look at the system security principal's identity classes, would this be a case to use them?
MSDN - How to: Impersonate a Client on a Service
Impersonating a client on a Windows
Communication Foundation (WCF) service
enables the service to perform actions
on behalf of the client. For actions
subject to access control list (ACL)
checks, such as access to directories
and files on a machine or access to a
SQL Server database, the ACL check is
against the client user account
Also don't forget to configure your service to use Windows Authentication and use a supported binding.