Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UnauthorizedAccessException on my Laptop 1

Status
Not open for further replies.

BenThereSeveralTimes

Technical User
Apr 6, 2007
5
0
0
US
Hi,

My Desktop is working fine. My Laptop, however, has started generating an UnauthorizedAccessException when I run the following code:

using System;
using System.Collections.Generic;
using System.Text;
using WatiN.Core;

namespace WatiNGettingStarted
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//try
//{
IE ie = new IE("C:/Documents and Settings/All Users/Documents/My PO/Blue.htm");

ie.Link(Find.ByText("Log On")).Click();

Console.WriteLine("After Log On Click");
//}
//catch (Exception ex)
//{
//Console.WriteLine("Fatal Error: " + ex.Message);

//Console.ReadLine();
//}

}
}
}

The code fails on the line:

ie.Link(Find.ByText("Log On")).Click();

Blue.htm is located on the shared drive.

I took a look at thread732-1094111, but didn't see an obvious solution.

I would appreciate any help

Thanks,

Ben



 
What does it say in ex.Message?

I'm guessing that it can't open the HTM file due to a security contstraint.

Also try rewriting the code to this:

IE ie = new IE("C:/Documents and Settings/All Users/Documents/My PO/Blue.htm");

Text t = Find.ByText("Log On");
Link l = ie.Link(t);
l.Click();

Console.WriteLine("After Log On Click");

This will allow a bit more precision on exactly which operation is failing.
 
Aptitude,

I made the changes you suggested:

using System;
using System.Collections.Generic;
using System.Text;
using WatiN.Core;

using System.Security.Permissions;

namespace WatiNGettingStarted
{
class Program
{
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]

[STAThread]
static void Main(string[] args)
{
//try
//{
IE ie = new IE("C:/Documents and Settings/All Users/Documents/My PO/Blue.htm");

Text t = Find.ByText("Log On");

Link i = ie.Link(t);

i.Click();

// ie.Link(Find.ByText("Log On")).Click();
.
.
.
.

The program is failing on i.Click(); with the following message:

System.UnauthorizedAccessEsception {"Access is denied.\r\n"}

The exception detail is as follows:

System.UnauthorizedAccessException was unhandled
HelpLink="C:\\WINDOWS\\system32\\mshtml.hlp"
Message="Access is denied.\r\n"
Source="htmlfile"
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at mshtml.DispHTMLBaseElement.click()
at WatiN.Core.Element.ClickDispHtmlBaseElement()
at WatiN.Core.Element.Click()
at WatiNGettingStarted.Program.Main(String[] args) in E:\WatiN Projects\Getting Started\WatiNGettingStarted\WatiNGettingStarted\Program.cs:line 28
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Thanks for your help

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top