473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Access Sql server Agent Windows service on remote machine

I want to stop Sql server Agent Windows service.
I am using below code to stop or start the windows service. Which is I am doing sucessfully.
Expand|Select|Wrap|Line Numbers
  1.  ManagedComputer mc = default(ManagedComputer);
  2.       mc = new ManagedComputer();
  3.       Service svc = default(Service);
  4.       svc = mc.Services["SQLSERVERAGENT"];
  5.  
  6.       if (svc.ServiceState == ServiceState.Running)
  7.       {
  8.           svc.Stop();
  9.           Response.Write (computerName + "Service Stoped");
  10.       }
  11.       else
  12.       {
  13.           svc.Start();
  14.           Response.Write (computerName + "Service Started");
  15.       }
  16.  
But I want to stop that service from another machine in my network.
When I try to do that I am getting following error so please help me to remove that error.

Microsoft.SqlServer.Management.Smo.SmoException was unhandled by user code
HelpLink="http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00. 1399.00&LinkId=20476"
Message="An exception occurred in SMO while trying to manage a service."
Source="Microsoft.SqlServer.Smo"
StackTrace:
at Microsoft.SqlServer.Management.Smo.Wmi.ManagedComp uter.TryConnect()
at Microsoft.SqlServer.Management.Smo.Wmi.WmiSmoObjec t.get_Proxy()
at Microsoft.SqlServer.Management.Smo.Wmi.WmiSmoObjec t.get_Proxy()
at Microsoft.SqlServer.Management.Smo.Wmi.WmiSmoObjec t.ImplInitialize(String[] fields, OrderBy[] orderby)
at Microsoft.SqlServer.Management.Smo.Wmi.WmiSmoObjec t.Initialize()
at Microsoft.SqlServer.Management.Smo.Wmi.ServiceColl ection.GetObjectByName(String name)
at Microsoft.SqlServer.Management.Smo.Wmi.ServiceColl ection.get_Item(String name)
at TestService.tempFunc() in e:\Working Folder\BI_Server_Monitor.root\BI_Server_Monitor\BI _Server_Monitor\TestService.aspx.cs:line 37
at TestService.Page_Load(Object sender, EventArgs e) in e:\Working Folder\BI_Server_Monitor.root\BI_Server_Monitor\BI _Server_Monitor\TestService.aspx.cs:line 21
at System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.UnauthorizedAccessException
Message="Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
Source="mscorlib"
StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExcept ionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(O bject o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementScope.Connect()
at Microsoft.SqlServer.Management.Smo.Wmi.ManagedComp uter.TryConnect()
InnerException:
Dec 18 '08 #1
7 8266
PRR
750 Expert 512MB
You need to specify login info and computer name
ManagedComputer
Secondly you require permissions for WMI calls to work on remote machines
HRESULT: 0x80070005 ="Errors originating in the core operating system. WMI may return this type of error because of an external failure, for example, DCOM security failure."
Look at the links given in this thread
Also look at ServiceController class
Dec 18 '08 #2
There is absolutely no problem with my code.
Problem is in the machine Which I am accessing.

I sure that there are some setting which are blocking my request for service object.
Please help me whether it is firewall or something else.

Thanx
Dec 19 '08 #3
PRR
750 Expert 512MB
@sachinkale123
You need permission and admin account that is validated on the remote pc for WMI to work on remote PC.. Your local login wont work... You need the remote PC login credentials.. and that too of a admin ...
check this
Dec 19 '08 #4
I created a user with administrator rights.
Turned off the firewall.

Still no success...now I am getting furstrated...
Please help me..
I am using different code which is as follows:
Expand|Select|Wrap|Line Numbers
  1.  ConnectionOptions connection = new ConnectionOptions();
  2.                 connection.Username = "Test";
  3.                 connection.Password = "Test";
  4.                 connection.Authority = "Kerberos:administrator";
  5.  
  6.                 ManagementScope scope = new ManagementScope("\\\\MachineName\\root\\CIMV2"
  7.                     , connection);
  8.  
  9.                 //"\\\\ADJ-IND-01-0010\\root\\CIMV2"
  10.                 scope.Connect();
  11.  
  12.                 ObjectQuery query = new ObjectQuery(
  13.                     "SELECT * FROM Win32_Service");
  14.  
  15.                 ManagementObjectSearcher searcher =
  16.                     new ManagementObjectSearcher(scope, query);
  17.  
  18.                 foreach (ManagementObject queryObj in searcher.Get())
  19.                 {
  20.                     Console.WriteLine("-----------------------------------");
  21.                     Console.WriteLine("Win32_Service instance");
  22.                     Console.WriteLine("-----------------------------------");
  23.                     Console.WriteLine("Caption: {0}", queryObj["Caption"]);
  24.                     Console.WriteLine("Description: {0}", queryObj["Description"]);
  25.                     Console.WriteLine("Name: {0}", queryObj["Name"]);
  26.                     Console.WriteLine("PathName: {0}", queryObj["PathName"]);
  27.                     Console.WriteLine("State: {0}", queryObj["State"]);
  28.                     Console.WriteLine("Status: {0}", queryObj["Status"]);
  29.                 }
  30.                 //Close();
  31.             }
  32.             catch (ManagementException err)
  33.             {
  34.                 //MessageBox.Show("An error occured while querying for WMI data: "
  35.                 //   + err.Message);
  36.             }
  37.  
Giving me error

The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
Dec 19 '08 #5
PRR
750 Expert 512MB
On the remote computer see to it that Remote Procedure Call (RPC)
and Remote Procedure Call (RPC) Locator services are enabled and running...
and secondly
Grant DCOM Remote Launch permissions

1. Click Start, click Run, type DCOMCNFG, and then click OK.
2. In the Component Services dialog box, expand Component Services, expand Computers, and then expand My Computer.
3. On the toolbar, click the Configure My Computer button.

The My Computer dialog box appears.
4. In the My Computer dialog box, click the COM Security tab.
5. Under Launch and Activate Permissions, click Edit Limits.
6. In the Launch Permission dialog box, follow these steps if your name or your group does not appear in the Groups or user names list:
1. In the Launch Permission dialog box, click Add.
2. In the Select Users, Computers, or Groups dialog box, add your name and the group in the Enter the object names to select box, and then click OK.
7. In the Launch Permission dialog box, select your user and group in the Group or user names box. In the Allow column under Permissions for User, select Remote Launch, and then click OK.
More Info
If all is working fine... you should be able to atleast read/loop through the service names....
Also you can go in for a client server application where local client executes starting and stopping services/processes... Doing it remotely you will compromise the remote system...
Dec 19 '08 #6
Thanx for the reply.
Dec 23 '08 #7
PRR
750 Expert 512MB
@sachinkale123
Welcome, do continue to post your queries on Bytes
Dec 23 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ravi | last post by:
I am posting this message after reading all the previous posts with the above subject. I have a SQL2K named instance running on a Windows 2K machine under Local system Account and it uses SQL...
6
by: John | last post by:
Hi We have an access app (front-end+backend) running on the company network. I am trying to setup replication for laptop users who go into field and need the data synched between their laptops...
3
by: Lyle Fairfield | last post by:
In a recent thread there has been discussion about Data Access Pages. It has been suggested that they are not permitted on many or most secure sites. Perhaps, that it is so, although I know of no...
0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere and VSS Remoting This article makes a detailed...
21
by: Kevin Swanson | last post by:
I'm attempting some remote registry manipulation via C#. I've written a test app to simply grab a specified key from a specified hive on a specified machine. The call to OpenSubKey is throwing...
2
by: Vaap | last post by:
I did lot of googling to see if I can solve the SQL server not found problem while trying to run ASP.Net community starter kit from an XP machine to Windows 2003 server hosting SQL server 2000...
1
by: Jody Gelowitz | last post by:
We are having an issue in that when trying to read a file that is on Server2 from Server1 (through our ASP.NET project), we receive the error: Access to the path "\\Server2\MyShare\MyFile.tif" is...
0
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
2
by: pratcp | last post by:
I have a remote server (a shared hosting webserver) where I have few users ftp some flat files. I need to access these files using a windows app/windows service written using c# and run it on a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.