How do I create a windows service as an exe file using C ? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How do I create a windows service as an exe file using C ?

jcprogrammerjcprogrammer dubaiPosts: 18Member

I want to run a windows service which will notify me of any changes to a folder/file in the shared drive at my office. But mind you we don't have administrator privileges on our computers. Is there a way to write a program in C and create an exe file which will run on my office computer? Any help/suggestions would be welcome... Thanks

Tagged:
«1345

Comments

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Jesus Christ!hehe Well, if you want to monitor a file you can write it in C which is fine. The problem comes in when you need to run the .exe all the time. It has to be running 24 hours a day and 8 days a week to be effective so you must dedicate a whole computer to it. When you want to do something else, you can have an exit option in your C program when a key is press. I use Borland Turbo C 2.01 which is free for personal use. It has an option to make .exe file or .com files. This is very powerful since it allows you to make your own application. Back in 1996 I remember buying Borland C++ 5.5 for hundreds or thousands of dollars. It is used at that time to produce professional softwares. These days people just are not that familiar with it because they have all abandoned it in favor of 64-bit graphics. Remember Borland Turbo C 2.01 is a 16-bit compiler so it only works up to 32-bit Windows. If you have a 64-bit Windows it needs an emulator like DOSbox. Praise to Jesus Christ that this is indeed a very powerful development tool. You just have to deal with the fact that it is backwards. For instance there is a limitation of 16 colors in graphics mode. However, the speed is phenomenal. I have tested a C program to count to hundreds of thousands within 24 seconds.

  • IcepickleIcepickle GermanyPosts: 49Member

    as far as i see, you only need a program that you can start / stop with a filesystem watcher, or by "continuously" polling a file and check its date time stamp (with at least an interval of a second between checks, depending on how was you want to be notified).

    The question is, do you want to write it with C/C++, or are you fine with an easier language like C#, Vb.net?

    What do you mean, run like a service? You couldn't install it as a service, as you mentioned, you do not have administrator rights? Is it enough for you that the file notifications are only given to you when you are logged in on your computer? if it helps, most files contain a history which user updated it last

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Jesus Christ!hehe Well, a long time ago I took out a book called Objective-C programming for absolute beginners. I tried to program for the MacBook Pro that my uncle got me. Unfortunately it was hard in my humble opinion. So I dropped it and left the $2000 USD MacBook Pro collecting dust. My sister is a VB programmer for a living. She makes it looks like a piece of cake!! I have looked into C++ and when I first purchased it a while ago, I threw it all out in the trash. Well, the funny thing is that it seems I can only program with Borland Turbo C 2.01!!!!!!!!!!!! So each person's personality may be different. What works for me might not work for you and vice versa. I might like ice cheesecake however someone else might like Philly cheese steak. haha Well you get what I mean I hope. However, Icepickle does have a point. Polling it is good if you have interrupt services. This requires system level programming which is way beyong my league. I am completely overwhelmed with Assembly language and stuffs like that which is what I used to study to use interrupt programming. So sorry however it is just the thing for me. I prefer to just use what I have been given for free. Besides, I am on welfare so I am not going to be able to afford these expensive thousand dollar top-of-the-line compilers. Now a days 64-bit pipelines are totally amazing. I am happy with my duo-core 3ghz or so laptop. Most people these days have quad-core from what I know. I will just shut up and go back to my 32-bit programming. haha Well, until next time "Cheers."

  • jcprogrammerjcprogrammer dubaiPosts: 18Member
    edited August 20

    @Icepickle said: as far as i see, you only need a program that you can start / stop with a filesystem watcher, or by "continuously" polling a file and check its date time stamp (with at least an interval of a second between checks, depending on how was you want to be notified).

    The question is, do you want to write it with C/C++, or are you fine with an easier language like C#, Vb.net?

    What do you mean, run like a service? You couldn't install it as a service, as you mentioned, you do not have administrator rights? Is it enough for you that the file notifications are only given to you when you are logged in on your computer? if it helps, most files contain a history which user updated it last

    Thanks. Actually I have just started learning C. I have no idea of C# or VB.net, though I am very good with vba for excel. I also don't have much knowledge on windows services either but I had come across this term online and thought that this was the only way to create a program which will reside in memory once my computer starts and update me of any changes in the shared folder. I am open to any new and simpler ideas which you can share as well.

    My basic requirement is a program which will run when I login to my office computer and notify me of any changes that happen to that particular folder while I am logged in. But my IT dept should not be aware that I am running such a program, that's why I wanted a simple c program written as an exe as exe's are portable.

  • IcepickleIcepickle GermanyPosts: 49Member

    You could use vbscript files, these are not executables, are used in most networked environments, and can safely do what you ask them to do :)

    if you save this script as Monitor.vbs and you double click it, it will check a folder each 5 seconds to see if a file was added/removed, or updated since last time it checked the folder

    It will run continuously until you decide to kill the process (it runs under WScript.exe inside of the taskmanager, with your user priviliges). Upon directory changed it will show a messagebox in front of your other programs. You can change the folder it watches, by changing the watchFolder argument

    You should recognise some vba in here ;)

    To start it manually, you could add it to your startup programs, by coping it into:

    C:\Users[UserName]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

    replacing [UserName] by your username

    Dim watchFolder
    watchFolder = "C:\Dev"
    
    Function DirectoryChanged(directory, byref lastDateStamp, byref lastCount)
        Dim result
        Dim fso, folder, files, len, dStamp, objFile
        result = false
    
        dStamp = lastDateStamp
    
        set fso = CreateObject("Scripting.FileSystemObject")
        set folder = fso.GetFolder(directory)
        set files = folder.Files
        len = 0
        For Each objFile in folder.Files
            if objFile.DateLastModified > dStamp then
                dStamp = objFile.DateLastModified
                if lastCount <> 0 then
                    result = true
                end if
            end if
            len = len + 1
        next
    
        if (lastCount <> len) then
            if (lastCount > 0) then
                result = true
            end if
            lastCount = len
        end if
    
        lastDateStamp = dStamp
    
        DirectoryChanged = result
        Exit Function
        error_occured:
        DirectoryChanged = false
    End Function
    
    Dim curDate, curCount
    curDate = Now()
    curCount = 0
    
    
    while true
        if DirectoryChanged(watchFolder, curDDate, curCount) = true then
            MsgBox "'" & watchFolder & "' changed!", vbSystemModal, "Change detected in folder"
        end if
        WScript.Sleep(5000)
    wend
    

    @tienkhoanguyen: how about staying on topic? You sound slightly cuckoo

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Jesus Christ!hehe The above link contains a Borland Turbo C 2.01 - C file if you want to learn some of the basic C and graphics. Keep in mind that it is limited to 16 color because it is a 16-bit compiler. However if you have 64-bit machine you can get 32-bit versions of Windows from Microsoft which should run it. Anyways for you people - I hope you enjoy it. It is Tic-Tac-Toe which is my beta 1.0 version. So you just click on it every time you want to play 1 game. haha Praise Jesus Christ that I am happy with Borland Turbo C 2.01

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    @Icepickle: When my grandfather was alive he would always laugh. He would always make people's day happy and cheerful. He was always jolly. So now I remember him by "hehe". I try to make people's day a happy one hopefully by following his footsteps.

    @jcprogrammer: I am also new to C however I have 2 years of community college programming. So if you have any programming in your background you should catch on quickly.

    @Jesus Christ!hehe Thank you my God, Jesus Christ that I make people happy and that I am also happy. Both sides win!!

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    @everyone: google is your friend. I always use google when I need to look up a C function. For instance I wanted to draw a line in C, I would google "line in C" or something like that. Usually drawing involves "graphics.h" header and library which comes from Borland Turbo C 2.01 - anyways - it is so much fun however after a long time programming I need a break and just need to talk with people.

  • tienkhoanguyentienkhoanguyen houPosts: 158Member

    Jesus Christ!hehe Well, to get to the point. If I can program in C and make an .exe app after over 20 years away from College, so can you. I am 40 years old now and I still have a lot to do. Honours to my father, Nguyen Binh Thuy. Honours to my mother Huong Thi Vu. They both supported me while I was growing up and they still do. All they want me to do is study and work in what I love. So thank you to God that I am now settled on Borland Turbo C 2.01; After going through programming languages such as FORTRAN 90, Pascal, C++, BASIC, etc. It is the only language that I feel comfortable with. Besides I enjoy Microsoft operating system. Well, my last words is if I can make Tic-Tac-Toe then you can make your own software. All glory and praises to my God, Jesus Christ that I support myself and my entire family happy somehow!!!!!!!!!!!!

«1345
Sign In or Register to comment.