|
Tks, i have found the solution....
I have set on after install:
Dim ckey As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\Myapp", True)
If ckey.GetValue("Type") <> Nothing Then
ckey.SetValue("Type", (ckey.GetValue("Type") Or 256))
End If
And it works....
Nice....
|
|
|
|
|
This is a really good article for how to do this in C#.
If, however, you're not using C#, and are using the Platform SDK,
you can simply specify the DesktopInteract mode in the CreateService() API call e.g.:
SC_HANDLE schService = CreateService(schSCManager,
"MyService",
"MyServiceDisplayName",
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
"\"MyQuotedFullPathToExe\"",
NULL, NULL, NULL, NULL, NULL);
Note that in order for the interact mode to function, the service must use the LocalSystem account (second to last parameter = NULL).
Also note that if you set the 'Type' registry value directly to 0x00000110 or similar, this will not work on Windows 2003 server, so the programmatic way is definitely the better bet.
Hope this helps!
|
|
|
|
|
hello All:
Can anyone please can convert the code to vb.net ?
Thanks in advance
Albert
|
|
|
|
|
Public Sub New()
InitializeComponent
Dim si As ServiceInstaller = New ServiceInstaller
si.ServiceName = "WindowsService1"
si.DisplayName = "WindowsService1"
si.StartType = ServiceStartMode.Manual
Me.Installers.Add(si)
Dim spi As ServiceProcessInstaller = New ServiceProcessInstaller
spi.Account = System.ServiceProcess.ServiceAccount.LocalSystem
spi.Password = Nothing
spi.Username = Nothing
Me.Installers.Add(spi)
Dim ckey As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\WindowsService1", True)
If Not (ckey Is Nothing) Then
If Not (ckey.GetValue("Type") Is Nothing) Then
ckey.SetValue("Type", (CType(ckey.GetValue("Type"), Integer) Or 256))
End If
End If
End Sub
|
|
|
|
|
http://united-arab-emirates-airline.tangoing.info/
http://united-arab-emirates-airline.tangoing.info/
|
|
|
|
|
this.Installers.Clear(); //add by kali, it work well
ServiceInstaller si = new ServiceInstaller();
si.ServiceName = "MonAgent";
si.DisplayName = "MonAgent";
si.StartType = ServiceStartMode.Automatic ;
this.Installers.Add(si);
ServiceProcessInstaller spi = new ServiceProcessInstaller();
spi.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
spi.Password = null;
spi.Username = null;
this.Installers.Add(spi);
// Here is where we set the bit on the value in the registry.
// Grab the subkey to our service
RegistryKey ckey = Registry.LocalMachine.OpenSubKey(
@"SYSTEM\CurrentControlSet\Services\MonAgent", true);
// Good to always do error checking!
if(ckey != null)
{
// Ok now lets make sure the "Type" value is there,
//and then do our bitwise operation on it.
if(ckey.GetValue("Type") != null)
{
ckey.SetValue("Type", ((int)ckey.GetValue("Type") | 256));
}
}
|
|
|
|
|
See the thread "The right way to do it".
This worked for me. The method in the original post (registry edit) didn't work on my Windows Server 2003 system. Looking at the service properties in the SCM, everything looked fine (the "Allow service to interact with desktop" flag was set), and there were no exceptions thrown in the GUI code, it just wouldn't show anything on the desktop (forms, notify icon, etc.)
Using this method, all worked great.
Regards (and thanks),
Robb
|
|
|
|
|
hi,
i tried changing the Registry Key...but my service is not able to run a GUI Application...what is the mistake??.....it is LocalSystem Account and n the properties box , the Desktop Interaction is enabled...
i tried this code,
/***********************code starts here*************************/
Process proc= new Process();
proc.StartInfo.FileName="E:\\MyStarter.exe";
proc.Start();
/***********************code starts here*************************/
what is wrong in my code???
with regards,
C.C.Chakkaradeep
|
|
|
|
|
Hi,
By the way did you resolve this problem ? because I have the same problem ?
Thanks
Laurent
|
|
|
|
|
This is not working for the application. There is uncheck option available after putting this code.
If any one got the demo application plz post here.
Regards,
Lalit Narayan Dubey
S/W Developer,Noida
|
|
|
|
|
Hello Laurent,
I think this is not the proper solution. Because I felt one thing very interesting i have created on application ..
There this registry chnage us working fine the service is desktop interactive.
But in other application its failing to check the check box option. Event all the code is same.
So i think its better to find some thig good solution.
Regards,
Lalit Narayan Dubey
S/W Developer,Noida
|
|
|
|
|
Absolutely delightful! I had been looking for this piece of code or at least a direction towards doing it myself for sooo long, and finally got it. Though I was quite fine with the registry-'tampering' code, I impelemented it in VB.NET and though the checkbox was set to true for the service, it didn't quite work I wonder why??
Eventually I used the 'right-way-to-do-it' piece of code and seriously it works like a dream. And moreover I got aware of a whole new concept of altering a service's properties on the fly!
All in all, loved it!
|
|
|
|
|
I have a service that I install to run as the "NetworkService" user, instead of the "LocalSystem" user. I tried flipping that bit by hand in the registry and restarting the service, but my console window does not display, like it does when I run as LocalSystem. So I suspect that the bit (just like the dialog box checkbox) only applies if you are running as LocalSystem. Maybe not, but I though I would mention it.
|
|
|
|
|
So, is there any work around to enable "interact with desktop" for local user account?
|
|
|
|
|
Thank you guys: Robert for the initiative and knowledge, "Anonymous" for WMI suggestion and Richard for "the correct way" to get the thing done.
You don't need "Allow Interact with Desktop" for debugging with MessageBox.Show - ServiceNotification option works nicely.
Blake is right, of course, that interactive services are dangerous but
sometimes one needs a quick and dirty solution.
I really had to write a quick and dirty demo and Richard's suggestion to use ChangeServiceConfig was very helpful. It took a couple hours to declare and put in work the related P/Invoke functions (OpenSCManager, OpenService, ...) - the great PInvoke site (http://www.pinvoke.net) doesn't have them yet. Since I do the job on ProjectInstaller.Committed event I don't need to call LockServiceDatabase.
I'd like to attach here my class (about 150 lines, written carefully) but there is no place for attachments here, unfortunately.
Israel Shnaidman
|
|
|
|
|
I am interested in why this is dangerous. You say "Blake is right of course . . ." but I couldn't find a message from anyone called Blake, or anything about the dangers. Why is this dangerous? Why should it only be used for "quick and dirty". I am writing a "proper" application that will go on sale top the public. Should I not use this method? If not, what is the recommended alternative?
Dave
|
|
|
|
|
Hi Israel,
I am trying to load a form from OnStart method of windows service.
Plz help me by giving proper line of code or way to move.
Amit
|
|
|
|
|
Thank you,Thank you,Thank you,Thank you,Thank you,
Thank you,Thank you,Thank you,Thank you,Thank you,Thank you,Thank you,
Thank you,Thank you,Thank you,
Thank you,Thank you,Thank you,Thank you,
|
|
|
|
|
Thank you, thank you, thank you, thank you.
Thank you.
|
|
|
|
|
Thank you, thank you, thank you, thank you.
Thank you, thank you, thank you, thank you.
Thank you, thank you, thank you, thank you.
Thank you, thank you, thank you, thank you.
|
|
|
|
|
I have written a Windows Service that monitors executing apps and if it isn't able to interact with the desktop the System.Diagnostic.Process.Responding always returns true even if the app has gone "Not Responding". This causes me another problem when the apps are running on another machine I have all sorts of security issues
Ian (Freebasing On Boredom.......)
BEING IN THERAPY
And yet, having therapy is very much like making love to a beautiful
woman. You... get on the couch, string 'em along with some half-lies and
evasions, probe some deep dark holes, and then hand over all your
money.
|
|
|
|
|
<br />
private void ServiceInstaller_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)<br />
{<br />
ConnectionOptions coOptions = new ConnectionOptions();<br />
<br />
coOptions.Impersonation = ImpersonationLevel.Impersonate;<br />
<br />
ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);<br />
<br />
mgmtScope.Connect();<br />
<br />
ManagementObject wmiService;<br />
<br />
wmiService = new ManagementObject("Win32_Service.Name='" + ServiceController.ServiceName + "'");<br />
<br />
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");<br />
<br />
InParam["DesktopInteract"] = true;<br />
<br />
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);<br />
<br />
ServiceController.Start();<br />
}<br />
this is the way to do this.
this code was provided by microsoft msdn support for the problem "interact with desktop".
after the installation, you will be able to run a service than can interact with the desktop.
greetings!
|
|
|
|
|
I have tried your suggestion.
It gives me an Exception during the installation, but if you do it on different
event - Commited, than it will work.
I absolutely agree that this is the right way of doing it.
Going through the registry -.... is a last reserve.
|
|
|
|
|
Great Information THANKs for saving time
|
|
|
|
|
I tried this (with .net framework 2.0) and it wouldn't work.
Using this code on the AfterInstall event rolls back the installation, and using Committed gives an error that is ignored: but the 'Interact with Desktop' checkbox is still unchecked.
What to do?
|
|
|
|
|