|
I need to change the startup type of already installed Windows services. I can start and stop them with their display name and was wondering if the same can be done for the startup type? I could look in the registry I guess and just edit that but would it be the best way to go about it?
How can I tell which service is which in the registry?
|
|
|
|
|
You can gio into the service manager and change it. Right-click the service and select "Properties" in the context menu.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I posted in C# so I could figure it out programmatically. I know how to do it by hand.
|
|
|
|
|
ziopino70 wrote: so I could figure it out
Ummm... no you didn't...
|
|
|
|
|
Hi,
0. I don't think you can change the type, other than by altering the server code itself.
1. I never used it but WMI offers a Win32_Service class; not sure what it offers exactly.
2. The ServiceController class has a ServiceType getter, no setter.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
You can modify this registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YourServiceName ,
value Start :
Values that will be interesting to you:
2 - automatic, 3 - manual
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
|
|
|
|
|
|
I wouldn't use the registry to accomplish this. You could always look to use WMI to accomplish this. Here's a sample that might help (I knocked it up in Notepad, so I apologise if the syntax isn't 100% correct):
public enum StartupType
{
Automatic,
Disabled,
Manual
}
public void SetStartupType(string serviceName, StartupType startupType)
{
string type = startupType.ToString();
using (ManagementPath mp = new ManagementPath(string.Format("Win32_Service.Name='{0}'", serviceName)))
{
if (mp != null)
{
using (ManagementObject mo = new ManagementObject(mp))
{
object[] parameters = new object[1] { type };
ManagementObject.InvokeMethod("ChangeStartMode", parameters);
}
}
}
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
Here is an example to change the startup mode of any service.
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class CallWMIMethod
{
public static void Main()
{
try
{
ManagementObject classInstance =
new ManagementObject("root\\CIMV2",
"Win32_Service.Name='ALG'",
null);
ManagementBaseObject inParams =
classInstance.GetMethodParameters("ChangeStartMode");
inParams["StartMode"] = "3";
ManagementBaseObject outParams =
classInstance.InvokeMethod("ChangeStartMode", inParams, null);
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
}
}
}
}
Regards,
Sunil G.
|
|
|
|
|
Hi,
I've set my WindowStartPosition for the form to be centered. I am also changing the size of the form in the FormLoad event as some of the group boxes are not visible.
When the form displays on the screen it's centered based on the OLD size, not the new size. Is there a better place to resize the form so that it remains centered, or a way to force the centering somehow?
Thank you,
Glenn
|
|
|
|
|
|
set the Form.Size (or Width, or Height, or both) in the Form's constructor. Or, if they are constant, why not set them in Visual Designer; I use the properties pane for such purpose.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi,
I'm trying to capture a CTRL/I key via a KeyDown event within a RichTextBox, the code is working perfect for the CTRL/B and CTRL/U keys (Bold and Underline), however the CTRL/I appears to erase the input and never gets to the KeyDown event. What do I need to do to get this to work.
if (e.KeyCode == Keys.B && e.Control)
ToggleFormat(FontStyle.Bold);
if (e.KeyCode == Keys.I && e.Control)
ToggleFormat(FontStyle.Italic);
if (e.KeyCode == Keys.U && e.Control)
ToggleFormat(FontStyle.Underline);
Thank you,
Glenn
|
|
|
|
|
Are you hooking the other events? Like KeyPreview or KeyPress? It works perfectly for me.
The only thing I have in my KeyDown event is:
if (e.Control && e.KeyCode == Keys.I)
{
MessageBox.Show("Ctrl+I");
}
So, if it's not getting there, then you must be handling the "I" KeyDown in some other method.
[UPDATE]
Sorry, I didn't see it was a RichTextBox. Just add this into your KeyDown:
if (e.KeyCode == Keys.I && e.Control)
{
e.SuppressKeyPress = True;
e.Handled = True;
ToggleFormat(FontStyle.Italic);
}
modified on Tuesday, May 11, 2010 1:40 PM
|
|
|
|
|
Hi,
Thank you for your response. It is actually executing the ToggleFormat(FontStyle.Italic); however after setting the font to Italic, it is erasing what was highlighted. CTRL/B and CTRL/U does not erase what was highlighted with the mouse.
So a better question is how do you prevent CTRL/I from erasing. I tried playing around with the AcceptTabs without any luck.
Glenn
|
|
|
|
|
Well, as I said, you would have to use the SuppressKeyPreview value within the Keydown code. Though what I found was that sometimes, it didn't work. For instance, if I set SuppressKeyPreview to true and then did a MessageBox, it went ahead and erased the line.
This was the code that I got to work:
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.I)
{
e.SuppressKeyPress = true;
e.Handled = true;
SetItalic();
}
}
private void SetItalic()
{
if (richTextBox1.SelectionFont.Italic)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Regular);
}
else
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Italic);
}
}
This code toggled Italic without erasing anything.
|
|
|
|
|
That did the trick!! -- Thank you very much!!
Glenn
|
|
|
|
|
try
myRTB.AcceptsTab=true;
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hello
The property AllowsSomePage in the PrintDialog allow to define a page range to Print
However it will be much more usefull in the PrintPreview dialog
Do someone knows if there is some ways to customize the PrintPreview dialog to add this feature ?
Thanks for any help
|
|
|
|
|
One of my so called 'colleagues' has just written a class with over 8000 lines of code. Apart from it being a nightmare to understand is there any peformance implications or any other good reasons I can use as evidence to try and put a stop to this practice! It's not a witch hunt, honest...
|
|
|
|
|
IMO readability is key.
If there are huge methods, consider splitting them up (and reusing some parts).
If there are lots of small methods, consider replacing them by fewer more general-purpose ones.
In short, look for ways to do the same thing with less code, however not at the expense of readability.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
From a maintenance standpoint, yes, there will be a performance hit. From a execution standpoint, that's a lot of code, and so it's going to impact overall performance of the app. Without seeing the code, we can't recommend changes, but I would start by performing a code review to see WHY the class is 8000 lines long. You might be able to move some of the functionality into a global static class, or if some of the code is used elsewhere, make a base class from which to derive other classes.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
This article[^] recommends 2000 lines of code max, which sounds manageable, though it is about readability more than anything. We have a few classes at around 3000-4000 lines, however most of that is GUI code. The Infragistics grid is particularly good at adding 1000 random lines of code to your class just because you set the border to be blue! Use of regions and partial classes help.
For a non-GUI class I would suspect it is doing the job of two or more classes if there is that much code in there.
Time to refactor with an axe.
|
|
|
|
|
Tony Pazzard wrote: lines of code
What's
a
line
of
code?
|
|
|
|
|
PIEBALDconsult wrote: What's a line of code?
a comment or a statement, except when that would exceed reasonable width and needs to be chopped.
Most people prefer spaces over newlines for separators ...
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|