Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear friends,

When i change Service DisplayName Programmatically then the service Became Unregistor, but when change Manully then there is no problem why?

I want to chane DisplayName by vb.net Prorame
My.Computer.Registry.SetValue("hkey_local_machine\system\currentcontrolset\services\GUI", "DisplayName", txtServiceName.Text)

Please Suggest me, How can i Solve this Problem ?

Regards
Mr. Ravi Kumar
Posted
Updated 23-Aug-12 21:22pm
v2

1 solution

This C#, but will get you idea how this can achieved.

C#
private void ChangeServiceName(string oldName, string newName)
        {
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.Arguments = string.Format("/c sc config {0} displayname= {1}", oldName, newName);
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.FileName = "cmd.exe";
            string output = "";
            string error = "";


            try
            {
                p.Start();
                p.WaitForExit();
                output = p.StandardOutput.ReadToEnd();
                error = p.StandardError.ReadToEnd();
            }

            catch (Exception ex)
            {

                error = ex.ToString();
            }
        }



VB Code sample, please modify appropriately:

VB
Public Sub RenameService(ByVal OldName As String, ByVal NewName As String)
        Dim objProcess As System.Diagnostics.Process

        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = "cmd.exe"
            objProcess.StartInfo.CreateNoWindow = True
            objProcess.StartInfo.Arguments = "/c sc config " & OldName & " displayname= " & NewName
            objProcess.StartInfo.RedirectStandardOutput = True
            objProcess.StartInfo.RedirectStandardError = True
            Dim stringOutput As String = ""
            Dim stringError As String = ""
            objProcess.Start()

            'Wait until the process passes back an exit code
            objProcess.WaitForExit()

            'Free resources associated with this process
            objProcess.Close()
        Catch
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Try
    End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900