Fervent Coder

Coding Towards Utopia...by Rob Reynolds
posts - 278 , comments - 431 , trackbacks - 0

My Links

News


Rob Reynolds

Subscribe to Fervent Coder RSS
Subscribe to Fervent Coder by Email

About Me

I manage several open source projects. Need...
   ...package management for Windows?
   ...automated builds?
   ...database change management (migrations)?
   ...your application to check email?
   ...a monitoring utility?

I also write for



Like what you are reading? Want to buy me a cup of coffee?
PayPal - The safer, easier way to pay online!

Archives

Post Categories

Sites

End2End Automated Testing: Setting Network Permissions Automatically

When setting network permissions, you are going to want to use a random permission name that you can clean up once the test is complete.  The "-q" in the call for CasPol is very important, because it quietly and automatically sets the permission. You can implement the basic code for starting a process using the System.Diagnostics .Net library.
 
Private Const FRAMEWORK_DIRECTORY As String = "Microsoft.NET\Framework\v2.0.50727"
 
Public Sub AssignNetworkPermission(ByVal remoteDirectory As String, ByVal permissionName As String)
    RemoveNetworkPermision(permissionName)
 
    Dim processInfo As New ProcessStartInfo(String.Format("{0}\..\{1}\caspol.exe", _
            Environment.SystemDirectory, FRAMEWORK_DIRECTORY), _
            String.Format(" -q -machine -addgroup LocalIntranet_Zone -url file:""{0}\*"" FullTrust -name ""{1}""", _
            remoteDirectory, permissionName) _
            )
    processInfo.UseShellExecute = False
    processInfo.RedirectStandardOutput = True
    processInfo.CreateNoWindow = False
 
    RunProcess(processInfo, True)
End Sub
 
Public Sub RemoveNetworkPermision(ByVal permissionName As String)
    Dim permissionProcess As New ProcessStartInfo(String.Format("{0}\..\{1}\caspol.exe", _
            Environment.SystemDirectory, FRAMEWORK_DIRECTORY), _
            String.Format(" -q -machine -remgroup ""{0}""", permissionName) _
            )
    permissionProcess.UseShellExecute = False
    permissionProcess.RedirectStandardOutput = True
    permissionProcess.CreateNoWindow = False
 
    RunProcess(permissionProcess, True)
End Sub
 
Private Sub RunProcess(ByVal processInfo As ProcessStartInfo, ByVal waitForExit As Boolean)
    Using process As New Process()
        process.StartInfo = processInfo
        process.Start()
 
        If (waitForExit) Then
            process.WaitForExit()
        End If
    End Using
End Sub

Print | posted on Monday, June 23, 2008 8:41 AM | Filed Under [ Code ]

Feedback

Comments are closed.
Comments have been closed on this topic.

Powered by: