EDN Admin
Well-known member
Hello everyone,
I had developp a application that is keep alive by a windows service on Windows XP. Now when I try to install the service in windows 7 I get the following error message: "Unhadled Exception: System.InvalidOperationException: Cannot open Service Control Manager
on computer `.`. This operation might require other previleges. ---> System.ComponentModel.Win32Exception: Access is denied ___ End of inner exception stack trace --- at System.ServiceProcess.ServiceInstaller.Install(IDictionary stateSaver) at MyPopUpService.IntegratedServiceInstaller.Install(String
ServiceName,String DisplayName, String Description, ServiceAccount Account, ServiceStartMode StartMode) at MyPopUpService.ServiceHandle.installService() at MyPopUpService.Progrma.Main(String[] args)"
Here is my code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; class IntegratedServiceInstaller
{
<span style="color:Blue; public <span style="color:Blue; void Install(String ServiceName, String DisplayName, String Description,
System.ServiceProcess.ServiceAccount Account,
System.ServiceProcess.ServiceStartMode StartMode)
{
System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = <span style="color:Blue; new System.ServiceProcess.ServiceProcessInstaller();
ProcessInstaller.Account = Account;
System.ServiceProcess.ServiceInstaller SINST = <span style="color:Blue; new System.ServiceProcess.ServiceInstaller();
System.Configuration.Install.InstallContext Context = <span style="color:Blue; new System.Configuration.Install.InstallContext();
<span style="color:Blue; string processPath = Process.GetCurrentProcess().MainModule.FileName;
<span style="color:Blue; if (processPath != <span style="color:Blue; null && processPath.Length > 0)
{
System.IO.FileInfo fi = <span style="color:Blue; new System.IO.FileInfo(processPath);
String path = String.Format(<span style="color:#A31515; "/assemblypath={0}", fi.FullName);
String[] cmdline = { path };
Context = <span style="color:Blue; new System.Configuration.Install.InstallContext(<span style="color:#A31515; "", cmdline);
}
SINST.Context = Context;
SINST.DisplayName = DisplayName;
SINST.Description = Description;
SINST.ServiceName = ServiceName;
SINST.StartType = StartMode;
SINST.Parent = ProcessInstaller;
System.Collections.Specialized.ListDictionary state = <span style="color:Blue; new System.Collections.Specialized.ListDictionary();
<span style=<span style="color:#A31515; "text-decoration:underline"> SINST.Install(state);
<span style="color:Blue; using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(<span style="color:#A31515; @"SYSTEMCurrentControlSetServices{0}", ServiceName), <span style="color:Blue; true))
{
<span style="color:Blue; try
{
Object sValue = oKey.GetValue(<span style="color:#A31515; "ImagePath");
oKey.SetValue(<span style="color:#A31515; "ImagePath", sValue);
}
<span style="color:Blue; catch (Exception Ex)
{
System.Console.WriteLine(Ex.Message);
}
}
}
[/code]
My code block at the line that I underlined and bolded. If you see why please help me.
Many thanks,
View the full article
I had developp a application that is keep alive by a windows service on Windows XP. Now when I try to install the service in windows 7 I get the following error message: "Unhadled Exception: System.InvalidOperationException: Cannot open Service Control Manager
on computer `.`. This operation might require other previleges. ---> System.ComponentModel.Win32Exception: Access is denied ___ End of inner exception stack trace --- at System.ServiceProcess.ServiceInstaller.Install(IDictionary stateSaver) at MyPopUpService.IntegratedServiceInstaller.Install(String
ServiceName,String DisplayName, String Description, ServiceAccount Account, ServiceStartMode StartMode) at MyPopUpService.ServiceHandle.installService() at MyPopUpService.Progrma.Main(String[] args)"
Here is my code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; class IntegratedServiceInstaller
{
<span style="color:Blue; public <span style="color:Blue; void Install(String ServiceName, String DisplayName, String Description,
System.ServiceProcess.ServiceAccount Account,
System.ServiceProcess.ServiceStartMode StartMode)
{
System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = <span style="color:Blue; new System.ServiceProcess.ServiceProcessInstaller();
ProcessInstaller.Account = Account;
System.ServiceProcess.ServiceInstaller SINST = <span style="color:Blue; new System.ServiceProcess.ServiceInstaller();
System.Configuration.Install.InstallContext Context = <span style="color:Blue; new System.Configuration.Install.InstallContext();
<span style="color:Blue; string processPath = Process.GetCurrentProcess().MainModule.FileName;
<span style="color:Blue; if (processPath != <span style="color:Blue; null && processPath.Length > 0)
{
System.IO.FileInfo fi = <span style="color:Blue; new System.IO.FileInfo(processPath);
String path = String.Format(<span style="color:#A31515; "/assemblypath={0}", fi.FullName);
String[] cmdline = { path };
Context = <span style="color:Blue; new System.Configuration.Install.InstallContext(<span style="color:#A31515; "", cmdline);
}
SINST.Context = Context;
SINST.DisplayName = DisplayName;
SINST.Description = Description;
SINST.ServiceName = ServiceName;
SINST.StartType = StartMode;
SINST.Parent = ProcessInstaller;
System.Collections.Specialized.ListDictionary state = <span style="color:Blue; new System.Collections.Specialized.ListDictionary();
<span style=<span style="color:#A31515; "text-decoration:underline"> SINST.Install(state);
<span style="color:Blue; using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(<span style="color:#A31515; @"SYSTEMCurrentControlSetServices{0}", ServiceName), <span style="color:Blue; true))
{
<span style="color:Blue; try
{
Object sValue = oKey.GetValue(<span style="color:#A31515; "ImagePath");
oKey.SetValue(<span style="color:#A31515; "ImagePath", sValue);
}
<span style="color:Blue; catch (Exception Ex)
{
System.Console.WriteLine(Ex.Message);
}
}
}
[/code]
My code block at the line that I underlined and bolded. If you see why please help me.
Many thanks,
View the full article