I have written a VB app using the RS323.vb code from the VB resource kit.
When I try to run the code from a network drive I get a securityexcepti on
error. If I copy the file to the local c drive it works perfectly. I have
seen posts that say the best thing to do is change the runtime security
policys on the PCs. I would rather code the program so I don't have to
change the security policy at all. I have seen a few examples of permission
code but none are dealing with a serial port. Below is a partial copy of
the code I am trying to make work. I think I doing this correctly, but it
still gives the SecurityExcepti on when run on the network drive. Part of
the problem, I think, is which permission do I need to use in the Dim
compermission line? The ultimate goal is to put this application on a
network drive and let people use it without making any changes to the PC.
Can this be done? Thank you for your time.
Jason Dravet
'Imports System.Security
Imports System.Security .Permissions
Public Class Form1
Inherits System.Windows. Forms.Form
Private msCommPort As New Rs232
Dim setmute As Boolean = True
Dim volumelevel As Integer = 24
Dim compermission As FileIOPermissio n
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
compermission = New FileIOPermissio n(PermissionSta te.Unrestricted )
compermission.P ermitOnly()
msCommPort.Open (1, 9600, 8, Rs232.DataParit y.Parity_None,
Rs232.DataStopB it.StopBit_1, 4096)
msCommPort.Writ e("PON")
System.Threadin g.Thread.Sleep( 5000)
msCommPort.Writ e("AVL:000")
msCommPort.Clos e()
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
msCommPort.Open (1, 9600, 8, Rs232.DataParit y.Parity_None,
Rs232.DataStopB it.StopBit_1, 4096)
msCommPort.Writ e("POF")
msCommPort.Clos e()
Button4.FlatSty le = Windows.Forms.F latStyle.Flat
Button4.BackCol or = Color.Gray
Button4.Text = "Muted"
End Sub