Lotus & VB.NET(3):环境与ID切换的思路

水如烟 2009-07-11 10:44:01
Notes运行环境关键在notes.ini文件,以下处理通过读取注册表获取ini文件全名。

配置文件的键值,如涉及到中文,中文前面要加上char(19).

通过先修改配置文件KeyFilename键值,再运行notes.exe或创建NotesSession,可以达到切换ID的效果。
...全文
159 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
HanMo 2009-08-31
  • 打赏
  • 举报
回复
结帐
水如烟 2009-07-11
  • 打赏
  • 举报
回复
Environment.vb
Imports Microsoft.Win32

Namespace LzmTW.Lotus
Public Class Environment
Private gDirectory As String
Private gPath As String
Private gVersion As String
Private gFile As String
Private iniFile As String
Private ini As LzmTW.uSystem.iniFile '如 x:\Program Files\lotus\notes\notes.ini

Private Sub New()
Me.Initiliaze()
End Sub

''' <summary>
''' 如 x:\Program Files\lotus\notes\data
''' </summary>
Public Property Directory() As String
Get
Return gDirectory
End Get
Private Set(ByVal value As String)
gDirectory = value
End Set
End Property

''' <summary>
''' 如 x:\Program Files\lotus\notes
''' </summary>
Public Property Path() As String
Get
Return gPath
End Get
Private Set(ByVal value As String)
gPath = value
End Set
End Property

''' <summary>
''' 如 x:\Program Files\lotus\notes\notes.exe
''' </summary>
Public Property File() As String
Get
Return gFile
End Get
Private Set(ByVal value As String)
gFile = value
End Set
End Property

Public Property Version() As String
Get
Return gVersion
End Get
Private Set(ByVal value As String)
gVersion = value
End Set
End Property

Private Sub Initiliaze()
Dim LotusKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Lotus")
If LotusKey Is Nothing Then Return

Dim NotesKey As RegistryKey = LotusKey.OpenSubKey("Notes")
If NotesKey Is Nothing Then Return
If NotesKey.SubKeyCount = 0 Then Return

Me.Version = NotesKey.GetSubKeyNames(NotesKey.SubKeyCount - 1) '取最新版本号

Dim VersionKey As RegistryKey = NotesKey.OpenSubKey(Me.Version)

With VersionKey
Me.Directory = .GetValue("DataPath").ToString
Me.Path = .GetValue("Path").ToString
Me.File = System.IO.Path.Combine(Me.Path, .GetValue("Name").ToString)
Me.iniFile = System.IO.Path.Combine(Me.Path, "notes.ini") 'notes.ini 文件
End With

ini = New LzmTW.uSystem.iniFile
ini.File = Me.iniFile
ini.CurrentSection = "Notes"

Me.Server = ini.GetValue("$AFSWServer")
Me.OAPath = ini.GetValue("$AFSWDBPath")

Me.MailPath = ini.GetValue("MailFile").Replace("/", "\")
Me.MailPath = Me.MailPath.Substring(0, Me.MailPath.IndexOf("\") + 1)

End Sub

Private Function IsChinese(ByVal c As Char) As Boolean
Return Not System.Text.Encoding.Unicode.GetBytes(c)(1) = 0
End Function


Private gServer As String
Public Property Server() As String
Get
Return gServer
End Get
Private Set(ByVal value As String)
gServer = value
End Set
End Property

Private gOAPath As String
Public Property OAPath() As String
Get
Return gOAPath
End Get
Private Set(ByVal value As String)
gOAPath = value
End Set
End Property

Private gMailPath As String
Public Property MailPath() As String
Get
Return gMailPath
End Get
Private Set(ByVal value As String)
gMailPath = value
End Set
End Property

Public Property UserID() As String
Get
Return ini.GetValue("KeyFilename").Replace(Me.SpecialChar, "")
End Get
Set(ByVal value As String)
ini.SetValue("KeyFilename", Me.GetSpecialString(value))
End Set
End Property

Public Property MailFile() As String
Get
Return ini.GetValue("MailFile").Replace(Me.SpecialChar, "")
End Get
Set(ByVal value As String)
ini.SetValue("MailFile", Me.GetSpecialString(value))
End Set
End Property

Private Function GetSpecialString(ByVal value As String) As String
If String.IsNullOrEmpty(value) Then Return ""

Dim b As New System.Text.StringBuilder
For index As Integer = 0 To value.Length - 1
Dim c As Char = value.Chars(index)
If Me.IsChinese(c) Then b.Append(Me.SpecialChar)
b.Append(c)
Next
Return b.ToString
End Function

Private ReadOnly SpecialChar As Char = Chr(19)

Private Shared gInstance As Environment
Private Shared internalObject As New Object

Friend Shared Function Instance() As Environment
If gInstance Is Nothing Then
SyncLock internalObject
If gInstance Is Nothing Then
gInstance = New Environment
End If
End SyncLock
End If

Return gInstance
End Function
End Class
End Namespace

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧