Posts

windows-service-setup-project-run-service-as-administrator

You should be able to add a new ServiceProcessInstaller in the InitializeComponent() method of your installer. This class will allow you to set account type, username, and password that you want the service to run as. For example: this.Installers.Add( new System.ServiceProcess.ServiceProcessInstaller() { Account = ServiceAccount.User, Username = @"domain\username", Password = "password" }); If you don't want to hardcode a password into your setup project, then leave it blank and a popup dialog should appear asking for this during install. http://stackoverflow.com/questions/1692679/windows-service-setup-project-run-service-as-administrator

How to Install Windows Service

Creating the solution To create the solution, use "File." "New." and select "Blank Solution. from the Visual Studio development environment. For this example, call the solution "ServiceSolution". All related projects (especially those that will be part of a installation, should become a project within the root solution. This keeps all inter-project dependencies relative to one another an simplifies the process if another developer decides to use a working folder. The next step is to create two new projects as part of this solution the service application and the installation package. Right click on the solution within the Solution Explorer and select "Add." and the "New Project." from the Visual C# projects folder, choose "Window Service". Name the project "TestService". The resulting project should now be in design mode and ready to add the installation components. The C# source file "Service1" and th...

XML Select Single Node

Ref http://msdn.microsoft.com/en-us/library/h0hw012b.aspx <pre> <bookstore xmlns="http://www.lucernepublishing.com"> <book> <title>Pride And Prejudice</title> </book> </bookstore> </pre> XmlDocument doc = new XmlDocument(); doc.Load( "booksort.xml" ); //Create an XmlNamespaceManager for resolving namespaces. XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace( "bk" , "urn:samples" ); //Select the book node with the matching attribute value. XmlNode book; XmlElement root = doc.DocumentElement; book = root.SelectSingleNode( "descendant::book[@bk:ISBN='1-861001-57-6']" , nsmgr); Console.WriteLine(book.OuterXml);

Create Log file for Application

1. Create Log Folder in the project folder 2. Create Batch file and Add following @echo --------------------------------------------------------- @rem ************* Project nameBatch Commands ************* @echo -------------------------------------------------------------- @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( Set Month=%%A Set Day=%%B Set Year=%%C ) @set ProjDir=C:\Projects\project@set logfile=%ProjDir%\Log\log%Month%%DAY%%Year%.txt@echo %logfile%@set app_exe=%ProjDir%\ProjFolder\bin\Debug\Project.exe%app_exe% >> %logfile% cls

File Watcher Windows service : Waits until a file can be opened with write permission

/// /// Waits until a file can be opened with write permission /// public static void WaitReady ( string fileName ) { while ( true ) { try { using ( Stream stream = System . IO . File . Open ( fileName , FileMode . Open , FileAccess . ReadWrite , FileShare . ReadWrite )) { if ( stream != null ) { System . Diagnostics . Trace . WriteLine ( string . Format ( "Output file {0} ready." , fileName )); break ; } } } catch ( FileNotFoundException ex ) { System . Diagnostics . Trace . WriteLine ( string . Format ( "Output file {0} not yet ready ({1})" , fileName , ex . Message )); } catch ( IOException ex ) { System . Diagnostics . Trace . WriteLine ( string . Format ( "Output file {0} not yet ready ({1})" , fileName , ex . Message )); } ...

How do I create shared assemblies

How do I create shared assemblies ? How to install an assembly in the Global Assembly Cache in Visual Basic .NET or in Visual Basic 2005? A shared assembly is one that is used by multiple applications on the machine. A shared assembly must have a name that is globally unique. The .NET Framework supports these naming requirements through a technique called strong names. Shared assemblies must have a "strong name" consisting of the name of the assembly, the version, a 64 bit hash of a public key (called a ´token´) and the culture. To create a strong name for an assembly (that is, to generate a public/private key pair), you'll have to use another utility called sn.exe. In this article, we will create a Visual Basic 2005 component called myGAC. We will also create a key file named mykeys.key. We will sign our component with this key file and place it in Global Assembly Cache To create a Component we have to create a Class Library project by using Visual Studio .NET. Step ...

Disable the Anchor Tag Using JavaScript

function DisableTheAnchorTag() { var btnA= document.getElementById("name of the a tag"); if(btnA!= null) { btnA.onmouseover=function y(){this.style.cursor='default'} btnA.setAttribute('onclick', "void(0);"); } }