Currently working on a project where I automatically track individual users system lock/unlock time and write that information to an excel sheet placed on network drive (using INTEROP). This exe is placed on the system startup so that when the user logins it automatically starts. The idea behind this application is to track user locked/unlocked time to calculate their utilization without user knowledge (Personally I would hate this kind of hidden approach, but this is what I’m expected to come up with)
The exe works absolutely fine till the time the user is on the office network, but the problem is if the user logs in from home then he will be out of the network till the time he connects to the VPN. But if the user locks/unlocks the system before he gets on the VPN, the tool throws an error "Microsoft Excel cannot open the file, check spelling or path".
I don’t want this to happen because the tool is throwing the path along with the error and the whole purpose of having this application hidden goes for a toss. Just wanted to check with you guys if there is anyway I can suppress this error message and close this application if this happens.
Any help on this will be very useful. I have given the code below
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Visible = False
Me.ShowInTaskbar = False
Timer1.Start()
Timer1.Interval = 100
RichTextBox1.Text = ""
End Sub
Private Sub WorkStationReader_locked(ByVal ivarreturn As Object) Handles WorkStationReader.locked
If ivarreturn(1) = True And Locked = False Then
Locked = True
RichTextBox1.Text += ivarreturn(0).ToString & "" & Date.Now.ToString
RichTextBox1.Text += vbCrLf
Dim xlApp As Microsoft.Office.Interop.Excel.Application
xlApp = New Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
xlApp.Visible = False
Try
Dim xlBook As Excel.Workbook = xlApp.Workbooks.Open("\\99.99.999.99\Excel\Satish.xlsx")
Dim xlSheet As Excel.Worksheet = xlBook.ActiveSheet
Dim xlSheet2 As Excel.Worksheet = xlBook.Worksheets("Sheet1")
Dim iRow As Integer
iRow = 1
With xlApp
Do While .Cells(iRow, 1).value <> ""
.Cells(iRow, 1).activate()
iRow = iRow + 1
Loop
.Cells(iRow, 1).value = ivarreturn(0).ToString & "" & Date.Now.ToString
End With
xlBook.Save()
xlApp.Quit()
Dim strX As String = RichTextBox1.SelectedText
If strX.Length = 0 Then strX = RichTextBox1.Text
If strX.Length > 0 Then
Clipboard.SetDataObject(strX)
End If
Catch ex As Exception
MessageBox.Show("Can not open connection ! ")
End Try
End If
If ivarreturn(1) = False And Locked = True Then
Locked = False
RichTextBox1.Text += ivarreturn(0).ToString & "" & Date.Now.ToString
RichTextBox1.Text += vbCrLf
Dim xlApp As Microsoft.Office.Interop.Excel.Application
xlApp = New Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
xlApp.Visible = False
Dim xlBook As Excel.Workbook = xlApp.Workbooks.Open("\\99.99.999.99\Excel\Satish.xlsx")
Dim xlSheet As Excel.Worksheet = xlBook.ActiveSheet
Dim xlSheet2 As Excel.Worksheet = xlBook.Worksheets("Sheet1")
Dim iRow As Integer
iRow = 1
With xlApp
Do While .Cells(iRow, 2).value <> ""
.Cells(iRow, 2).activate()
iRow = iRow + 1
Loop
.Cells(iRow, 2).value = ivarreturn(0).ToString & "" & Date.Now.ToString
End With
xlBook.Save()
xlApp.Quit()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
WorkStationReader.WorkStationISLocked()
End Sub