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

如何下伺服器

發布時間: 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即完成安裝。

熱點內容
ipad文件加密 發布:2024-05-02 08:20:30 瀏覽:442
粉土壓縮模量 發布:2024-05-02 07:53:59 瀏覽:805
國都證券初始密碼是多少 發布:2024-05-02 07:46:39 瀏覽:109
shell腳本和linux命令行 發布:2024-05-02 07:37:54 瀏覽:968
自己的伺服器搭建微信小程序商城 發布:2024-05-02 07:36:26 瀏覽:426
php單行注釋 發布:2024-05-02 07:36:22 瀏覽:958
買車哪些配置必備 發布:2024-05-02 07:30:20 瀏覽:52
華為手機的自帶鈴聲文件夾 發布:2024-05-02 07:20:14 瀏覽:501
xp系統開機密碼怎麼設置 發布:2024-05-02 06:49:48 瀏覽:759
柱加密區公式 發布:2024-05-02 06:40:19 瀏覽:4