當前位置:首頁 » 雲伺服器 » 如何下伺服器

如何下伺服器

發布時間: 2024-04-02 20:17:56

Ⅰ 如何在windows系統上安裝伺服器

安裝Winfows服務首先要添加安裝程序,添加安裝程序步驟如下:

1、將Windows服務程序切換到設計視圖, 右擊設計視圖選擇「添加安裝程序」

2、切換到剛被添加的ProjectInstaller的設計視圖

一般設置如下:

設置serviceInstaller1組件的屬性:
1) ServiceName = 服務名稱
2) StartType = Automatic ,即自動
設置serviceProcessInstaller1組件的屬性
1) Account = LocalSystem,賬戶一般設置為本地系統
3、生成解決方案

安裝服務:
方法一、使用DOS命令安裝window服務
1、在服務所在的文件夾下的bin\debug文件夾下找到.exe文件(例如WindowsService1.exe)
將此文件拷貝到你想安裝的文件夾中。
2、進入DOS界面

(VS2008-->Visual Studio Tools-->Visual Studio 2008 命令提示)來進入DOS,直接用cmd可能有些命令找不到;
3、輸入

方法二、使用安裝項目安裝windows服務
個人比較推薦這個方法,選擇目錄安裝更靈活,而且不用在DOS環境下運行。
因為本人比較懶,直接給出別人總結的地址

注意,以後每次服務項目有更改的時候,需要編譯服務後,在安裝項目中刷新依賴項!!!

方法三、
在ProjectInstaller.cs的後台代碼中添加安裝服務和卸載服務的代碼

/// <summary>
/// 安裝服務
/// </summary>
/// <param name="stateSaver"></param>
public override void Install(System.Collections.IDictionary stateSaver)
{
Microsoft.Win32.RegistryKey system,
//HKEY_LOCAL_MACHINE\Services\CurrentControlSet
currentControlSet,
//...\Services
services,
//...\<Service Name>
service,
//...\Parameters - this is where you can put service-specific configuration
config;

try
{
//Let the project installer do its job
base.Install(stateSaver);

//Open the HKEY_LOCAL_MACHINE\SYSTEM key
system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
//Open CurrentControlSet
currentControlSet = system.OpenSubKey("CurrentControlSet");
//Go to the services key
services = currentControlSet.OpenSubKey("Services");
//Open the key for your service, and allow writing
service = services.OpenSubKey(conServiceName, true);
//Add your service's description as a REG_SZ value named "Description"
service.SetValue("Description", "描述語言");
//(Optional) Add some custom information your service will use...
config = service.CreateSubKey("Parameters");
}
catch (Exception e)
{
Console.WriteLine("An exception was thrown ring service installation:\n" + e.ToString());
}
}

/// <summary>
/// 卸載服務
/// </summary>
/// <param name="savedState"></param>
public override void Uninstall(System.Collections.IDictionary savedState)
{
Microsoft.Win32.RegistryKey system,
currentControlSet,
services,
service;

try
{
//Drill down to the service key and open it with write permission
system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
currentControlSet = system.OpenSubKey("CurrentControlSet");
services = currentControlSet.OpenSubKey("Services");
service = services.OpenSubKey(conServiceName, true);
//Delete any keys you created ring installation (or that your service created)
service.DeleteSubKeyTree("Parameters");
//...
}
catch (Exception e)
{
Console.WriteLine("Exception encountered while uninstalling service:\n" + e.ToString());
}
finally
{
//Let the project installer do its job
base.Uninstall(savedState);
}
}
代碼添加完成後

添加window service安裝的批處理命令
1)在項目添加一個文本文件,更名為install.bat,編輯文件的內容如下:
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -i "WindowsService1.exe"
@pause
2)在項目添加一個文本文件,更名為uninstall.bat,編輯文件的內容如下
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe -u "WindowsService1.exe"
@pause

說明:上面綠色字體為服務名稱
編譯完成後將debug的文件拷貝到想安裝的目錄下,點擊install.bat即完成安裝。

熱點內容
我姐姐手機上的密碼多少的短視頻 發布:2025-07-02 13:09:10 瀏覽:799
軒逸安全配置全系一樣嗎都有哪些 發布:2025-07-02 13:07:30 瀏覽:522
合肥少兒編程哪家好 發布:2025-07-02 13:05:12 瀏覽:880
安卓快手極速版怎麼簽到 發布:2025-07-02 12:58:21 瀏覽:692
我與編程作文 發布:2025-07-02 12:57:33 瀏覽:230
安卓機在哪裡調振動大小 發布:2025-07-02 12:53:31 瀏覽:848
linux系統如何查看伺服器ip地址 發布:2025-07-02 12:51:57 瀏覽:245
dlna怎麼指定伺服器地址 發布:2025-07-02 12:51:08 瀏覽:215
ftp默認埠是多少 發布:2025-07-02 12:50:32 瀏覽:736
java隱藏 發布:2025-07-02 12:36:39 瀏覽:202