|
|
@ -32,11 +32,22 @@ |
|
|
|
' 2 = Покси недоступен. |
|
|
|
Public bProxyStatus As Byte = 0 |
|
|
|
|
|
|
|
' Режим и права доступа |
|
|
|
' Возможны следующие значения: |
|
|
|
' 0 = Неопределённое состояние (при старте приложения); |
|
|
|
' 1 = От имени обычного пользователя. VNC еще не запущен; |
|
|
|
' 2 = От имени обычного пользователя. VNC работает в режиме приложения; |
|
|
|
' 3 = От имени обычного пользователя. VNC работает как служба; |
|
|
|
' 4 = От имени администратора. VNC еще не запущен; |
|
|
|
' 5 = От имени администратора. VNC работает как служба; |
|
|
|
Public bExecMode As Byte = 0 |
|
|
|
|
|
|
|
' Настройки приложения |
|
|
|
Private oConfigFile As New IniFile |
|
|
|
|
|
|
|
' Процесс winvnc.exe |
|
|
|
Private VNCProc As Process = Nothing |
|
|
|
Private sVNCServiceName As String = "uvnc_service" |
|
|
|
|
|
|
|
''' <summary> |
|
|
|
''' Инициализация приложения |
|
|
@ -64,6 +75,8 @@ |
|
|
|
|
|
|
|
If sProxyHost.Length = 0 Or sProxyPort.Length = 0 Then Return False |
|
|
|
|
|
|
|
bExecMode = GetExecutionMode() |
|
|
|
|
|
|
|
' Генерируем ID и пароль |
|
|
|
sSupportID = GetSupportID() |
|
|
|
sSupportPasswd = GetSupportPasswd() |
|
|
@ -131,14 +144,28 @@ |
|
|
|
Return False |
|
|
|
End Try |
|
|
|
|
|
|
|
AddHandler VNCProc.Exited, AddressOf VNCProcessExited |
|
|
|
|
|
|
|
Return True |
|
|
|
End Function |
|
|
|
|
|
|
|
Public Function StopVNC() As Boolean |
|
|
|
If VNCProc IsNot Nothing And VNCProc.Id <> 0 Then |
|
|
|
VNCProc. |
|
|
|
Public Sub StopVNC() |
|
|
|
If VNCProc IsNot Nothing And Not VNCProc.HasExited Then |
|
|
|
VNCProc.CloseMainWindow() |
|
|
|
VNCProc.WaitForExit(1000) |
|
|
|
|
|
|
|
If Not VNCProc.HasExited Then |
|
|
|
VNCProc.Kill() |
|
|
|
End If |
|
|
|
End If |
|
|
|
End Function |
|
|
|
|
|
|
|
VNCProc = Nothing |
|
|
|
bExecMode = |
|
|
|
End Sub |
|
|
|
|
|
|
|
Private Sub VNCProcessExited(ByVal sender As Object, ByVal e As System.EventArgs) |
|
|
|
VNCProc.Close() |
|
|
|
End Sub |
|
|
|
|
|
|
|
Private Function GetAllUsersDir() As String |
|
|
|
Dim sRegShellPath As String = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" |
|
|
@ -246,10 +273,110 @@ |
|
|
|
Private Function GetSupportPasswd() As String |
|
|
|
' Проверяем наличие сохранённого пароля на случай перезапуска от имени администратора |
|
|
|
Dim pwd As String = oConfigFile.GetKeyValue("lvnc", "passwd") |
|
|
|
If pwd IsNot Nothing And pwd <> String.Empty Then Return pwd |
|
|
|
If pwd IsNot Nothing And pwd <> String.Empty Then |
|
|
|
If bExecMode = 3 Then |
|
|
|
Return pwd |
|
|
|
End If |
|
|
|
End If |
|
|
|
|
|
|
|
Dim rndGen As New System.Random |
|
|
|
|
|
|
|
Return (rndGen.Next(1000, 10000).ToString) |
|
|
|
pwd = rndGen.Next(1000, 10000).ToString |
|
|
|
|
|
|
|
Dim vncSetPasswd As New ProcessStartInfo |
|
|
|
With vncSetPasswd |
|
|
|
.Arguments = pwd |
|
|
|
.FileName = sRunTimeDir & "\UltraVNC\setpasswd.exe" |
|
|
|
.UseShellExecute = True |
|
|
|
.WindowStyle = ProcessWindowStyle.Hidden |
|
|
|
.WorkingDirectory = sRunTimeDir & "\UltraVNC" |
|
|
|
End With |
|
|
|
|
|
|
|
Try |
|
|
|
Dim p As Process = Process.Start(startInfo) |
|
|
|
p.WaitForExit() |
|
|
|
Catch ex As System.ComponentModel.Win32Exception |
|
|
|
Return String.Empty |
|
|
|
End Try |
|
|
|
|
|
|
|
Return pwd |
|
|
|
End Function |
|
|
|
|
|
|
|
Private Function GetExecutionMode() As Byte |
|
|
|
Dim bMode As Byte = 0 |
|
|
|
|
|
|
|
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then |
|
|
|
bMode = 4 |
|
|
|
|
|
|
|
If IsServiceInstalled(sVNCServiceName) Then |
|
|
|
If GetServiceStatus(sVNCServiceName) = "running" Then |
|
|
|
bMode = 5 |
|
|
|
End If |
|
|
|
End If |
|
|
|
Else |
|
|
|
bMode = 1 |
|
|
|
|
|
|
|
If IsServiceInstalled(sVNCServiceName) Then |
|
|
|
If GetServiceStatus(sVNCServiceName) = "running" Then |
|
|
|
bMode = 3 |
|
|
|
End If |
|
|
|
Else |
|
|
|
If VNCProc Is Nothing Then |
|
|
|
For Each p As Process In Process.GetProcesses() |
|
|
|
If p.ProcessName.Contains("winvnc") Then |
|
|
|
VNCProc = p |
|
|
|
End If |
|
|
|
Next |
|
|
|
|
|
|
|
If VNCProc IsNot Nothing Then |
|
|
|
StopVNC() |
|
|
|
End If |
|
|
|
Else |
|
|
|
bMode = 2 |
|
|
|
End If |
|
|
|
End If |
|
|
|
End If |
|
|
|
|
|
|
|
Return bMode |
|
|
|
End Function |
|
|
|
|
|
|
|
Private Function IsServiceInstalled(ByVal sServiceName As String) As Boolean |
|
|
|
Dim bResult As Boolean = False |
|
|
|
Dim oServiceArray() As ServiceProcess.ServiceController = ServiceProcess.ServiceController.GetServices |
|
|
|
|
|
|
|
For Each oServiceController As ServiceProcess.ServiceController In oServiceArray |
|
|
|
If oServiceController.ServiceName.Trim.ToUpper = sServiceName.Trim.ToUpper Then |
|
|
|
Dim i As New ServiceProcess.ServiceControllerPermissionAttribute(Security.Permissions.SecurityAction.Demand) |
|
|
|
Dim d As New ServiceProcess.ServiceControllerPermission |
|
|
|
Try |
|
|
|
If d.Any Then |
|
|
|
d.ToString() |
|
|
|
End If |
|
|
|
Catch ex As Exception |
|
|
|
End Try |
|
|
|
|
|
|
|
bResult = True |
|
|
|
|
|
|
|
Exit For |
|
|
|
End If |
|
|
|
Next |
|
|
|
|
|
|
|
Return bResult |
|
|
|
End Function |
|
|
|
|
|
|
|
Public Function GetServiceStatus(ByVal sServiceName As String) As String |
|
|
|
Dim sStatus As String = "NA" |
|
|
|
Dim oWinSvc As New ServiceProcess.ServiceController |
|
|
|
|
|
|
|
oWinSvc.ServiceName = sServiceName |
|
|
|
|
|
|
|
Select Case oWinSvc.Status |
|
|
|
Case ServiceProcess.ServiceControllerStatus.Stopped |
|
|
|
sStatus = "stoped" |
|
|
|
Case ServiceProcess.ServiceControllerStatus.Running |
|
|
|
sStatus = "running" |
|
|
|
End Select |
|
|
|
|
|
|
|
Return sStatus |
|
|
|
End Function |
|
|
|
End Module |
|
|
|