Click here to Skip to main content
15,346,557 members
Home / Discussions / C#
   

C#

 
AnswerRe: ASAP Pin
Ingo23-Sep-12 21:53
MemberIngo23-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
Memberrikah3-Oct-12 1:29 
QuestionAsp Classic to ASP .NET C# Pin
zoul138023-Sep-12 16:50
Memberzoul138023-Sep-12 16:50 
AnswerRe: Asp Classic to ASP .NET C# Pin
Abhinav S23-Sep-12 17:40
MemberAbhinav 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
Memberozkary24-Sep-12 16:28 
QuestionCOM port & Windows Service Pin
abshmak23-Sep-12 13:43
Memberabshmak23-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
Memberabshmak23-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
Memberabshmak23-Sep-12 16:17 
AnswerRe: COM port & Windows Service Pin
Bernhard Hiller23-Sep-12 20:42
MemberBernhard Hiller23-Sep-12 20:42 
GeneralRe: COM port & Windows Service Pin
abshmak25-Sep-12 12:54
Memberabshmak25-Sep-12 12:54 
AnswerRe: COM port & Windows Service Pin
Richard Andrew x6424-Sep-12 7:24
professionalRichard Andrew x6424-Sep-12 7:24 
GeneralRe: COM port & Windows Service Pin
abshmak25-Sep-12 12:55
Memberabshmak25-Sep-12 12:55 
AnswerRe: COM port & Windows Service Pin
abshmak25-Sep-12 13:01
Memberabshmak25-Sep-12 13:01 
Questionways to execute C# console application Pin
classy_dog23-Sep-12 13:09
Memberclassy_dog23-Sep-12 13:09 
AnswerRe: ways to execute C# console application Pin
Richard MacCutchan23-Sep-12 21:58
mveRichard MacCutchan23-Sep-12 21:58 
QuestionC# namspace.Properties.Settings Pin
classy_dog23-Sep-12 13:09
Memberclassy_dog23-Sep-12 13:09 
AnswerRe: C# namspace.Properties.Settings Pin
Richard MacCutchan23-Sep-12 22:00
mveRichard MacCutchan23-Sep-12 22:00 
QuestionNeed To Decompile My Lost Solution Pin
SayedAbdElkrim23-Sep-12 7:08
MemberSayedAbdElkrim23-Sep-12 7:08 
AnswerRe: Need To Decompile My Lost Solution Pin
Wes Aday23-Sep-12 8:04
professionalWes Aday23-Sep-12 8:04 
AnswerRe: Need To Decompile My Lost Solution Pin
Dave Kreskowiak23-Sep-12 8:49
mveDave Kreskowiak23-Sep-12 8:49 
AnswerRe: Need To Decompile My Lost Solution Pin
Abhinav S23-Sep-12 23:49
MemberAbhinav S23-Sep-12 23:49 

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.