问题描述
我首先将我的Windows服务作为常规Windows Exe编写,因为它更容易调试。在那里我使用了
AppDir = Application.ExecutablePath.Substring(0,
Application.ExecutablePath.LastIndexOf(" \"))''这个应用程序的位置
Excutable坐着
现在,当我将它转换为服务时,我可以使用哪条路径?或者我可以在
中指定服务中始终用作数据路径的路径吗?我更喜欢
前者,因为我不知道目标电脑的布局。
-
Anil Gupte
I wrote my Windows Service first as a regular Windows Exe because it is
easier to debug. In that I used
AppDir = Application.ExecutablePath.Substring(0,
Application.ExecutablePath.LastIndexOf("\")) '' Where this application
Excutable sits
Now, when I am converting it to a Service, what path can I use? Or can I
specify a path in the service to always use as a data path? I would prefer
the former because I do not know the layout of the target computer.
--
Anil Gupte
www.keeninc.net
www.icinema.com
推荐答案
尝试使用WMI类获取Windows默认路径
Imports System.Management
公共类wmi
私有objOS作为ManagementObjectSearcher
私有objCS作为ManagementObjectSearcher
私有objMgmt作为ManagementObject
私有m_strComputerName为字符串
私有m_strManufacturer为字符串
私有m_StrModel为字符串
私有m_strOSName为字符串
私有m_strOSVersion为字符串
私有m_strSystemType为字符串
私有m_strTPM为字符串
私有m_strWindowsDir为字符串
公开Sub New()
objOS = New ManagementObjectSearcher(" SELECT * FROM
Win32_OperatingSystem")
objCS = New ManagementObjectSear cher(SELECT * FROM
Win32_ComputerSystem)
For each objMgmt in objOS.Get
m_strOSName = objMgmt(" name") .ToString()
m_strOSVersion = objMgmt(" version")。ToString()
m_strComputerName = objMgmt(" csname")。ToString()
m_strWindowsDir = objMgmt(" windowsdirectory")。ToString()
下一页
每个objMgmt在objCS.Get
m_strManufacturer = objMgmt(" manufacturer")。ToString()
m_StrModel = objMgmt(" model")。ToString()
m_strSystemType = objMgmt(" ; systemtype")。ToString
m_strTPM = objMgmt(" totalphysicalmemory")。ToString()
下一页
结束子
Public ReadOnly属性ComputerName()
获取
ComputerName = m_strComputerName
结束获取
结束物业
Public ReadOnly物业制造商()
获取
制造商= m_strManufacturer
结束获取
结束物业
Public ReadOnly物业模型()
获取
型号= m_StrModel
结束获取
结束物业
公开ReadOnly Property OsName()
获取
OsName = m_strOSName
结束获取
结束财产
Public ReadOnly Property OSVersion()
获取
OSVersion = m_strOSVersion
End Get
结束财产
公共ReadOnly属性SystemType()
获取
SystemType = m_strSystemType
结束获取
结束物业
Public ReadOnly物业TotalPhysicalMemory()
获取
TotalPhysicalMemory = m_strTPM
结束获取
结束物业
Public ReadOnly Property WindowsDirectory()
获取
WindowsDirectory = m_strWindowsDir
结束获取
结束财产
Public ReadOnly Property FontDirectory()
获取
FontDirectory = m_strWindowsDir& " \ font" .ToUpper
结束获取
结束财产
结束班
Try the WMI class to get Windows Default path
Imports System.Management
Public Class wmi
Private objOS As ManagementObjectSearcher
Private objCS As ManagementObjectSearcher
Private objMgmt As ManagementObject
Private m_strComputerName As String
Private m_strManufacturer As String
Private m_StrModel As String
Private m_strOSName As String
Private m_strOSVersion As String
Private m_strSystemType As String
Private m_strTPM As String
Private m_strWindowsDir As String
Public Sub New()
objOS = New ManagementObjectSearcher("SELECT * FROM
Win32_OperatingSystem")
objCS = New ManagementObjectSearcher("SELECT * FROM
Win32_ComputerSystem")
For Each objMgmt In objOS.Get
m_strOSName = objMgmt("name").ToString()
m_strOSVersion = objMgmt("version").ToString()
m_strComputerName = objMgmt("csname").ToString()
m_strWindowsDir = objMgmt("windowsdirectory").ToString()
Next
For Each objMgmt In objCS.Get
m_strManufacturer = objMgmt("manufacturer").ToString()
m_StrModel = objMgmt("model").ToString()
m_strSystemType = objMgmt("systemtype").ToString
m_strTPM = objMgmt("totalphysicalmemory").ToString()
Next
End Sub
Public ReadOnly Property ComputerName()
Get
ComputerName = m_strComputerName
End Get
End Property
Public ReadOnly Property Manufacturer()
Get
Manufacturer = m_strManufacturer
End Get
End Property
Public ReadOnly Property Model()
Get
Model = m_StrModel
End Get
End Property
Public ReadOnly Property OsName()
Get
OsName = m_strOSName
End Get
End Property
Public ReadOnly Property OSVersion()
Get
OSVersion = m_strOSVersion
End Get
End Property
Public ReadOnly Property SystemType()
Get
SystemType = m_strSystemType
End Get
End Property
Public ReadOnly Property TotalPhysicalMemory()
Get
TotalPhysicalMemory = m_strTPM
End Get
End Property
Public ReadOnly Property WindowsDirectory()
Get
WindowsDirectory = m_strWindowsDir
End Get
End Property
Public ReadOnly Property FontDirectory()
Get
FontDirectory = m_strWindowsDir & "\font".ToUpper
End Get
End Property
End Class
尝试使用WMI类获取Windows默认路径
导入System.Management
公共类wmi
私有objOS作为ManagementObjectSearcher
私有objCS作为ManagementObjectSearcher
私有objMgmt作为ManagementObject
私有m_strComputerName作为字符串
私有m_strManufacturer为字符串
私有m_StrModel为字符串
私有m_strOSName为字符串
私有m_strOSVersion为字符串
私有m_strSystemType为字符串
私有m_strTPM为字符串
私有m_strWindowsDir为字符串
Public Sub New()
objOS =新的ManagementObjectSearcher(" SELECT * FROM
Win32_OperatingSystem")
objCS =新的ManagementObjectSearcher(" SELECT * FROM
Win32_ComputerSystem")
For each objMgmt in objOS.Get
m_strOSName = objMgmt(" name")。ToString()
m_strOSVersion = objMgmt(" version")。ToString()
m_strComputerName = objMgmt(" csname" ).ToString()
m_strWindowsDir = objMgmt(" windowsdirectory")。ToString()
下一页
For Each objMgmt在objCS.Get
m_strManufacturer = objMgmt(" manufacturer")。ToString()
m_StrModel = objMgmt(" model")。ToString()
m_strSystemType = objMgmt(" systemtype")。ToString
m_strTPM = objMgmt(" totalphysicalmemory")。ToString()
下一页
结束子
Public ReadOnly属性ComputerName()
获取
ComputerName = m_strComputerName
结束获取
结束物业
Public ReadOnly物业制造商()
获取
制造商= m_strManufacturer
结束获取
结束物业
Public ReadOnly物业模型()
获取
型号= m_StrModel
结束获取
结束物业
Public ReadOnly Property OsName()
获取
OsName = m_strOSName
结束获取
结束物业
Public ReadOnly Property OSVersion()
获取
OSVersion = m_strOSVersion
结束获取
结束物业
公共只读属性SystemType()
获取
SystemType = m_strSystemType
结束获取
结束物业
Public ReadOnly物业TotalPhysicalMemory()
获取
TotalPhysicalMemory = m_strTPM
结束获取
结束物业
Public ReadOnly Property WindowsDirectory()
获取
WindowsDirectory = m_strWindowsDir
结束获取
结束物业
Public ReadOnly Property FontDirectory()
获取
FontDirectory = m_strWindowsDir& " \ font" .ToUpper
结束获取
结束财产
结束班
Try the WMI class to get Windows Default path
Imports System.Management
Public Class wmi
Private objOS As ManagementObjectSearcher
Private objCS As ManagementObjectSearcher
Private objMgmt As ManagementObject
Private m_strComputerName As String
Private m_strManufacturer As String
Private m_StrModel As String
Private m_strOSName As String
Private m_strOSVersion As String
Private m_strSystemType As String
Private m_strTPM As String
Private m_strWindowsDir As String
Public Sub New()
objOS = New ManagementObjectSearcher("SELECT * FROM
Win32_OperatingSystem")
objCS = New ManagementObjectSearcher("SELECT * FROM
Win32_ComputerSystem")
For Each objMgmt In objOS.Get
m_strOSName = objMgmt("name").ToString()
m_strOSVersion = objMgmt("version").ToString()
m_strComputerName = objMgmt("csname").ToString()
m_strWindowsDir = objMgmt("windowsdirectory").ToString()
Next
For Each objMgmt In objCS.Get
m_strManufacturer = objMgmt("manufacturer").ToString()
m_StrModel = objMgmt("model").ToString()
m_strSystemType = objMgmt("systemtype").ToString
m_strTPM = objMgmt("totalphysicalmemory").ToString()
Next
End Sub
Public ReadOnly Property ComputerName()
Get
ComputerName = m_strComputerName
End Get
End Property
Public ReadOnly Property Manufacturer()
Get
Manufacturer = m_strManufacturer
End Get
End Property
Public ReadOnly Property Model()
Get
Model = m_StrModel
End Get
End Property
Public ReadOnly Property OsName()
Get
OsName = m_strOSName
End Get
End Property
Public ReadOnly Property OSVersion()
Get
OSVersion = m_strOSVersion
End Get
End Property
Public ReadOnly Property SystemType()
Get
SystemType = m_strSystemType
End Get
End Property
Public ReadOnly Property TotalPhysicalMemory()
Get
TotalPhysicalMemory = m_strTPM
End Get
End Property
Public ReadOnly Property WindowsDirectory()
Get
WindowsDirectory = m_strWindowsDir
End Get
End Property
Public ReadOnly Property FontDirectory()
Get
FontDirectory = m_strWindowsDir & "\font".ToUpper
End Get
End Property
End Class
这篇关于Windows服务的默认路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!