changing remote service password "not found"

  • Thread starter Thread starter hauld
  • Start date Start date
H

hauld

Guest
I testing on two test machines. one of the machine is basically the master server. the second machine is a slave only running 3 services for our application.

I have a C# program that will change the password of the service account running our application services on the two machines.

im using the following code to get the services current "starting" account then return and change the passwords. the odd this is this the program can change 2 of the remote services but fail on the third service stating that it is not found. I have no issue getting the "start" details just when I want to change the third service account.


private bool getRemoteXprServices(ref string[,] aServices, int iPlace, bool bGet, bool bAccount)
{
try
{
ConnectionOptions connectoptions = new ConnectionOptions();
connectoptions.Username = XHF.defInst.tUser.Text;
connectoptions.Password = XHF.defInst.mtPassword.Text;
connectoptions.Authority = "ntlmdomain:" + XHF.defInst.tDomain.Text;
connectoptions.EnablePrivileges = true;

ManagementScope scope = new ManagementScope(@"\\" + aServices[iPlace, 1] + @"\root\cimv2", connectoptions);
scope.Connect();
SelectQuery query = new SelectQuery("select name, startname from Win32_Service Where Name = \"
+ aServices[iPlace, 0] + "\");
if (bGet == true)
{
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
//("Select * from Win32_Service Where Name =Alerter")

foreach (ManagementObject service in searcher.Get())
{
aServices[iPlace, 3] = service["StartName"].ToString();
}
}
}

if (bGet == false) //set account or password
{
string objPath = string.Format("Win32_Service.Name={0}", aServices[iPlace, 0]);
using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
{
object[] wmiParams = new object[11];
if (bAccount == true)
wmiParams[6] = txtBUserID.Text;
wmiParams[7] = txtBPassword1.Text;
object result = service.InvokeMethod("Change", wmiParams);
Globals.ERR("ServiceAccount:: getRemoteXprServices", "The service " +
aServices[iPlace, 0] + " was replaced.", 0);
}
}
}

the "
if (bGet == true)" does not error out getting the third servers.

the "if (bGet == false)" again has no issue on the first two services on the remote machine just the third. im running under a domain administrator and in "run as administrator" mode.

Source:
System.Management
Stack trace:
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementObject.get_ClassPath()
at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass)
at System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args)
at XPR_Hotfix3.Service_Account.getRemoteXprServices(String[,]& aServices, Int32 iPlace, Boolean bGet, Boolean bAccount) in D:\project\Xpressions 3.0\XPR-Hotfix3\XPR-Hotfix3\Service Account.cs:line 185
Path:
Void ThrowWithExtendedInfo(System.Management.ManagementStatus)
Message:
Not found
Data:
System.Collections.ListDictionaryInternal
Error:
System.Management.ManagementException: Not found
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementObject.get_ClassPath()
at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass)
at System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args)
at XPR_Hotfix3.Service_Account.getRemoteXprServices(String[,]& aServices, Int32 iPlace, Boolean bGet, Boolean bAccount) in D:\project\Xpressions 3.0\XPR-Hotfix3\XPR-Hotfix3\Service Account.cs:line 185
above is the error message written to my file.

Continue reading...
 
Back
Top