วันอังคารที่ 19 เมษายน พ.ศ. 2554

ERROR The terminal server has exceeded the maximum number of allowed connections

windows server 2003 error

สืบเนื่องจากบทความที่แล้ว ต้องมีการ remote ไปยัง server บ่อยมาก
โดยปกติ windows server 2003 จากอนุญาติให้เข้าใช้ server ได้เพียง 2 session เท่านั้น

ปัญหาเกิดก็คือ user ของผมกับเพื่อนหลุดพร้อมๆ กัน ทำให้ session มัน disconnect ไม่ใช่ log off ทำให้ไม่สามารถเข้าใช้ซ้ำกันได้ เมื่อพยายามจะรีโมตมันก็ฟ้องว่า
"Terminal server has exceeded maximum number of allowed connection"

เลยต้องหาวิธีตามเน็ตก็พบว่า เพียงใช้คำสั่ง

mstsc /v:<ไอพีของเครื่องเซิร์ฟเวอร์> /f -admin


ก็จะ log in เข้าระบบได้ แต่บางบทความก็พบว่าให้ใช้คำสั่งนี้แทน

mstsc -v:<ไอพีของเครื่องเซิร์ฟเวอร์> /f -console

ref http://www.demoncodez.com/os-network/145-error-the-terminal-server-has-exceeded-the-maximum-number-of-allowed-connections.html

Batch File แก้ปญหา : “Terminal Server Has Exceeded the Maximum Number of Allowed Connections”

  1. สร้าง batch file ตาม code ทางด้านล่าง
  2. เปิด batch file
  3. ป้อน ชื่อ Server
  4. ป้อน Username
  5. ป้อน Password
  6. ใส่ ID ที่ต้องการ Reset Session

@ECHO OFF
SET EXEC=%SYSTEMROOT%\system32\dllcache

SET SERVER=
SET /P SERVER=Enter IP or server name: %=%

SET USER=
SET /P USER=Enter user name: %=%

SET PASS=
SET /P PASS=Enter password: %=%

NET USE \\%SERVER% /user:%USER% %PASS%

:START

%EXEC%\query session /server:%SERVER%

SET SID=
SET /P SID=Enter session ID to reset: %=%

%EXEC%\reset session %SID% /server:%SERVER%

SET CONT=
SET /P CONT=Reset more sessions? %=%

IF /i “%CONT%” EQU “y” GOTO START

SET REMOTE=
SET /P REMOTE=Launch remote desktop? %=%

IF /i “%REMOTE%” NEQ “y” GOTO END

mstsc /v:%SERVER% /f

:END



ref http://km.ru.ac.th/computer/?p=359

วันเสาร์ที่ 9 เมษายน พ.ศ. 2554

การทำโปรแกรม ปิง (Ping)

Public Class PingCheck_V2
Dim tmp(10) As String

Private Sub PingCheck_V2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
string_ip()
Button1.Enabled = False
Button2.Enabled = True
timer_data()
End Sub
Private Sub string_ip()
tmp(1) = "xx.xx.xx.xx"
tmp(2) = "
"xx.xx.xx.xx"
tmp(3) = "
"xx.xx.xx.xx"
tmp(4) = "209.85.175.147" 'Google
tmp(5) =
"xx.xx.xx.xx"
tmp(6) =
"xx.xx.xx.xx"
tmp(7) =
"xx.xx.xx.xx"
tmp(8) =
"xx.xx.xx.xx"
tmp(9) =
"xx.xx.xx.xx"
tmp(10) =
"xx.xx.xx.xx"
End Sub
Private Sub check_ip(ByVal string_ip As String, ByVal tag_name As Integer)
If My.Computer.Network.Ping(string_ip) Then
alert_string(tag_name, Color.Green)
Else
alert_string(tag_name, Color.Red)
End If
End Sub
Private Sub alert_string(ByVal tag_name As Integer, ByVal string_color As Color)

For Each object_label As Object In Me.Controls
If TypeOf object_label Is Label Then
If CType(object_label, Label).Tag = tag_name Then
If string_color = Color.Red Then
CType(object_label, Label).ForeColor = Color.Red
Else
CType(object_label, Label).ForeColor = Color.Green
End If
End If
End If
Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = True
PictureBox1.Image = ProPing.My.Resources.Resources.sonic
ProgressBar1.Value = 30
timer_data()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Enabled = True
Button2.Enabled = False
PictureBox1.Image = ProPing.My.Resources.Resources.sonicwarp
ProgressBar1.Value = 0
Timer1.Stop()
Timer2.Stop()
Label1.ForeColor = Color.Orange
Label2.ForeColor = Color.Orange
Label3.ForeColor = Color.Orange
Label4.ForeColor = Color.Orange
Label5.ForeColor = Color.Orange
Label6.ForeColor = Color.Orange
Label7.ForeColor = Color.Orange
Label8.ForeColor = Color.Orange
Label9.ForeColor = Color.Orange
Label10.ForeColor = Color.Orange
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Time_Count.Text = Time_Count.Text - 1
ProgressBar1.Value = Time_Count.Text
If Time_Count.Text = "0" Then
Time_Count.Text = "30"
timer_data()
End If
End Sub
Private Sub timer_data()

Timer1.Interval = 30000 '1000 = 1 วินาที
Timer1.Enabled = True
Timer2.Interval = 1000 '1000 = 1 วินาที
Timer2.Enabled = True
Time_Count.Text = "30" 'Now.Second
Timer1.Start()
Timer2.Start()
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 30
For i As Integer = 1 To 10
check_ip(tmp(i), i)
Next

End Sub
End Class

การ Import Excel ทั้งหมดลง Datagrid

Public Class Test_Import_Excel

Dim sFilePath, sFileName As String
Dim sSlash As Single

Dim strConnection As System.Data.OleDb.OleDbConnection
Dim myPath As String = sFilePath & sFileName

Private Sub Test_Import_Excel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'B a s s i e
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With OpenFileDialog1
.Title = "Import Sage CSV file"
.InitialDirectory = "C:\Documents and Settings\htran\My Documents\vbnet\Welcome"
.Filter = "File (*.xls;*.csv;*.txt)|*.xls;*.csv;*.txt|All files (*.*)|*.*"

.ShowDialog()

sSlash = InStrRev(.FileName, "\")
sFilePath = Mid(.FileName, 1, sSlash)
sFileName = Mid(.FileName, sSlash + 1, Len(.FileName))
TextBox1.Text = .FileName
End With

myPath = sFilePath & sFileName

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try

Dim objDataSet As System.Data.DataSet
Dim objAdapter As System.Data.OleDb.OleDbDataAdapter

strConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & myPath & " '; " & "Extended Properties=Excel 8.0;")
objAdapter = New System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", strConnection)
objDataSet = New System.Data.DataSet
objAdapter.Fill(objDataSet, "Customers")
DataGridView1.DataSource = objDataSet.Tables(0).DefaultView
strConnection.Close()

Catch ex As Exception
Dim er As String
strConnection.Close()
End Try
End Sub

End Class

การ Import Excel แบบเลือกจุดได้

Option Explicit On
'Option Strict On
Imports Microsoft.Office.Interop
Imports System.Object
Imports System.Exception
Imports System.SystemException
Imports System.Runtime.InteropServices.ExternalException
Imports System.Runtime.InteropServices.COMException

Public Class Test_Import_Excel_V2

Dim sFilePath, sFileName As String
Dim sSlash As Single
Dim myPath As String

Private Sub Test_Import_Excel_V2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'B a s s i e
End Sub

Private Sub export_to_excel()
OpenLgExcel()
Dim xlAPP As Excel.Application
Dim xlWB As Excel.Workbook
Dim XlWs As Excel.Worksheet

xlAPP = CreateObject("Excel.Application")
'##########################################################################################
'EX
'xlWB = xlAPP.Workbooks.Open(Application.StartupPath & "\Template\" & "Invoice.xls"))
xlWB = xlAPP.Workbooks.Open(myPath)
'##########################################################################################
'EX
'XlWs = xlWB.Sheets("Invoice")
'XlWs = xlWB.Sheets(2)
XlWs = xlWB.Sheets(2)
'##########################################################################################

TextBox2.Text = XlWs.Range("D2").Value

xlAPP.Visible = True
xlAPP.Workbooks.Close()
xlAPP.Quit()
XlWs = Nothing
xlWB = Nothing
xlAPP = Nothing
CloseLgExcel()
End Sub

Public Sub OpenLgExcel()
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
End Sub

Public Sub CloseLgExcel()
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("th-TH")
kill_process_Excel()
End Sub

Public Sub kill_process_Excel()
Try
Process.GetProcessesByName("EXCEL")(0).Kill()
Catch ex As Exception
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With OpenFileDialog1
.Title = "Import Sage CSV file"
.InitialDirectory = "C:\Documents and Settings\htran\My Documents\vbnet\Welcome"
.Filter = "File (*.xls;*.csv;*.txt)|*.xls;*.csv;*.txt|All files (*.*)|*.*"

.ShowDialog()

sSlash = InStrRev(.FileName, "\")
sFilePath = Mid(.FileName, 1, sSlash)
sFileName = Mid(.FileName, sSlash + 1, Len(.FileName))
TextBox1.Text = .FileName
End With

myPath = sFilePath & sFileName
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
export_to_excel()
End Sub

End Class