VS2008 (VB.NET) : Creating a windows services

Here’s a rough detail on the steps required to create a new windows services:

1. Create new window services project
2. In the toolbox, right click -> select “choose item”
3. Add Timer from namespace “system.timers”
4. Drag and drop into the Service1.vb designer window of the timer object that you have just added.
5. Double click the Timer object, add below codes into Timer1_Elapsed sub codes:
'create a new event log
'Check if the Event Log Exists
If Not Diagnostics.EventLog.SourceExists("Service") Then
Diagnostics.EventLog.WriteEntry("Service", "Service_Log")
' Create Log
End If
'Write to the Log
Dim MyLog As New EventLog()
MyLog.Source = "Service"
Diagnostics.EventLog.WriteEntry(MyLog.Source, "First Web Service Application running", EventLogEntryType.Information)
'EventLog.WriteEntry("Timer1 is Beginning")

6. Activate the timer by adding below code onto the OnStart sub code:
Timer1.Enabled = True
7. Right click the designer window of the Service1.vb and select “add installer”
8. In the designer window of the newly added ProjectInstaller.vb interface, select the ServiceProcessInstaller1 object. Change the Account property value to “LocalSystem”.
9. Select the ServiceInstaller1 object and change the “DisplayName” value to the value that you wish to display in the Services listing later. The “StartType” value provide the flexibility to automatically or manually start up the services upon windows restart.
10. Once done, proceed to Build -> Project
11. Adjourn to the Release folder and make sure the executable file is present.
12. Open up command prompt, execute the below statement:
For installation of the windows services.
Installutil executable.exe
To uninstall:
Installutil executable.exe /U
13. Proceed to the Services listing, search for the windows service name that you have provided in the “DisplayName” of step #9, and right click to start it.
14. Proceed to Eventlog, Application section and you will see the latest entry of log created by the application has been added.

Feel free to leave your comments and queries should there be any!

Written by admin on August 17th, 2010 with no comments.
Read more articles on Knowledge Base and Programming.

Sale: MITSUBISHI Electric Gate Turn-Off (GTO) Thyristors

Searching for the thyristors? My client are currently having the items on shelves and it’s on sales! The said products are genuine item from Japan with certificate proven. If you’re looking for one, feel free to head over SMI website for further queries.

All queries are also welcome here.

Functionalities of GTO Thristors:
1. Frequency changer (high-power inverter)
2. DC chopper
3. AC/DC switch
4. SVG (reactive power evoluction device)
5. BTB (power system link device)

Written by admin on August 16th, 2010 with no comments.
Read more articles on Entertainment.

Execute batch sql files

A friend of mine was asking me if there is any way to execute of list of sql files automatically without having to open it one by one to execute it.

I gave him this site which shared this code:

CREATE TABLE ##SQLFiles ( SQLFileName VARCHAR(2000))
GO

INSERT INTO ##SQLFiles
EXECUTE master.dbo.xp_cmdshell ‘dir /b “C:\SQL Scripts\*.sql”‘
GO

DECLARE cFiles CURSOR LOCAL FOR
SELECT DISTINCT [SQLFileName]
FROM ##SQLFiles
WHERE [SQLFileName] IS NOT NULL AND
[SQLFileName] != ‘NULL’
ORDER BY [SQLFileName]

DECLARE @vFileName VARCHAR(200)
DECLARE @vSQLStmt VARCHAR(4000)

OPEN cFiles
FETCH NEXT FROM cFiles INTO @vFileName
WHILE @@FETCH_STATUS = 0
BEGIN
— The following SET command must be on a single line or else an error will be generated.
— It is split in this script for readability purposes.
SET @vSQLStmt = ‘master.dbo.xp_cmdshell ”osql -S Server Name -U User Name -P Password
-d Database Name -i “C:\SQL Scripts\’ + @vFileName + ‘””’
EXECUTE (@vSQLStmt)

FETCH NEXT FROM cFiles INTO @vFileName
END

CLOSE cFiles
DEALLOCATE cFiles
GO

DROP TABLE ##SQLFiles
GO

It helps but there’s no error handling. Need some fine tuning here…

Written by admin on August 4th, 2010 with no comments.
Read more articles on Knowledge Base and Programming.

« Older articles

No newer articles