Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# can not locate file Pin
Richard MacCutchan25-Sep-12 5:43
mveRichard MacCutchan25-Sep-12 5:43 
AnswerRe: C# can not locate file Pin
jschell25-Sep-12 8:34
jschell25-Sep-12 8:34 
QuestionShould i use my DAL in my acceptance tests? Pin
Member 867449224-Sep-12 12:34
Member 867449224-Sep-12 12:34 
AnswerRe: Should i use my DAL in my acceptance tests? Pin
jschell24-Sep-12 12:42
jschell24-Sep-12 12:42 
AnswerRe: Should i use my DAL in my acceptance tests? Pin
V.24-Sep-12 20:16
professionalV.24-Sep-12 20:16 
AnswerRe: Should i use my DAL in my acceptance tests? Pin
BobJanova24-Sep-12 23:54
BobJanova24-Sep-12 23:54 
AnswerRe: Should i use my DAL in my acceptance tests? Pin
Pete O'Hanlon25-Sep-12 0:42
mvePete O'Hanlon25-Sep-12 0:42 
Questionftp download Pin
Member 945456324-Sep-12 5:04
Member 945456324-Sep-12 5:04 
AnswerRe: ftp download Pin
Pete O'Hanlon24-Sep-12 5:09
mvePete O'Hanlon24-Sep-12 5:09 
AnswerRe: ftp download Pin
Eddy Vluggen24-Sep-12 5:16
professionalEddy Vluggen24-Sep-12 5:16 
QuestionASAP Pin
rikah23-Sep-12 21:15
rikah23-Sep-12 21:15 
AnswerRe: ASAP Pin
Ingo23-Sep-12 21:53
Ingo23-Sep-12 21:53 
AnswerRe: ASAP Pin
Ravi Bhavnani24-Sep-12 4:17
professionalRavi Bhavnani24-Sep-12 4:17 
GeneralRe: ASAP Pin
rikah3-Oct-12 1:29
rikah3-Oct-12 1:29 
QuestionAsp Classic to ASP .NET C# Pin
zoul138023-Sep-12 16:50
zoul138023-Sep-12 16:50 
AnswerRe: Asp Classic to ASP .NET C# Pin
Abhinav S23-Sep-12 17:40
Abhinav S23-Sep-12 17:40 
AnswerRe: Asp Classic to ASP .NET C# Pin
Dave Kreskowiak23-Sep-12 18:52
mveDave Kreskowiak23-Sep-12 18:52 
AnswerRe: Asp Classic to ASP .NET C# Pin
ozkary24-Sep-12 16:28
ozkary24-Sep-12 16:28 
QuestionCOM port & Windows Service Pin
abshmak23-Sep-12 13:43
abshmak23-Sep-12 13:43 
Hi Guys,

I have a program that reads stuff from a Searial COM port. It uses one of those USB to COM port gizmos (Prolific driver).
The environment is Win7/Server 2008R2 (all 64 bit), joined to domain, .NET4.

The program works fine when run from within context of an end user.

However, when i try to run the same program as a windows service I get 'The system cannot find the file specified'. I tried to configure the service to run both as a local system account and as a domain service account (added to the admin ug), but still the same error.

I also created a little test program (see the code at the end of the post, it is stolen from somewhere on the internet).

This runs fine when run from the console and opens the port and reports its type (CHAR), but fails with the same error (File not found) when i try to run it as a scheduled job.

Again i tried running it both under my own account and under account of a service (both added as local admins) and it is the same error.

I am pretty sure it is some sort of a security/policy issue but cannot quite figure out what.

Any pointers will be greatly appreciated,

Alexei

C#
static void Main(string[] args)
{
    var portName = @"\\.\COM3";
    var handle = CreateFile(portName, 0, 0, IntPtr.Zero, 3, 0x80, IntPtr.Zero);
    if (handle == (IntPtr)(-1))
    {
        Console.WriteLine("Could not open " + portName + ": " 
            + new Win32Exception().Message);
        return;
    }
    var type = GetFileType(handle);
    Console.WriteLine("File " + portName + " reports its type as: " + type);
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall,
    SetLastError = true)]
public static extern IntPtr CreateFile(
    string lpFileName,
    uint dwDesiredAccess,
    uint dwShareMode,
    IntPtr SecurityAttributes,
    uint dwCreationDisposition,
    uint dwFlagsAndAttributes,
    IntPtr hTemplateFile);

[DllImport("kernel32.dll")]
static extern FileType GetFileType(IntPtr hFile);
enum FileType : uint
{
    UNKNOWN = 0x0000,
    DISK = 0x0001,
    CHAR = 0x0002,
    PIPE = 0x0003,
    REMOTE = 0x8000,
}

AnswerRe: COM port & Windows Service Pin
Wes Aday23-Sep-12 15:22
professionalWes Aday23-Sep-12 15:22 
GeneralRe: COM port & Windows Service Pin
abshmak23-Sep-12 15:31
abshmak23-Sep-12 15:31 
GeneralRe: COM port & Windows Service Pin
Wes Aday23-Sep-12 15:53
professionalWes Aday23-Sep-12 15:53 
GeneralRe: COM port & Windows Service Pin
abshmak23-Sep-12 16:17
abshmak23-Sep-12 16:17 
AnswerRe: COM port & Windows Service Pin
Bernhard Hiller23-Sep-12 20:42
Bernhard Hiller23-Sep-12 20:42 
GeneralRe: COM port & Windows Service Pin
abshmak25-Sep-12 12:54
abshmak25-Sep-12 12:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.