Pages

Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Friday, 16 August 2013

How to fix /windows/system32/config/system misssing or corrupt WITHOUT XP Recovery CD

So I came across the dreaded /windows/system32/config/system file is misssing or corrupt recently and I didn't have my XP disk to hand.  No matter which Forum I went to or blog post I read, nobody really had a viable solution so I thought I would write up the guide myself.

Obviously you dont have the XP Recovery CD if you are reading this, but if you do then Microsoft's guide on MSDN is pretty thorough and worth reading, although this way is much quicker if you have what you need at hand.


What you need:


Because you don't have the Recovery disk you need some way of accessing the files on the hard drive, so I have suggested a few ways of doing so, there will be others and please comment if you know other simple ways of doing so
  1. USB to SATA/IDE cable.  Because we are working with Windows XP there is a high chance you may still have a Hard Drive with an IDE interface so buy your cable accordingly.  There is a picture below to help if you are unsure. You will need a second PC to plug this into to allow you to access the files. (Cheap)
  2. USB Caddy or Enclosure.  Again, ensure your Hard Drive interface matches that of the caddy otherwise it will not fit. SATA to SATA, IDE to IDE. You will then just need a USB to USB cable to connect the two. You will need a second PC to plug this into to allow you to access the files. (Cheap)
  3. Download Windows Mini XP or Mini 7.  You will need to download a .iso file of either of these, they are available from many sources, one of which is Hirens Boot CD.  When you download it, use software like ImgBurn to burn it onto the CD.  When your computer is booting, go to set-up (usually pressing F2) and ensure that booting from CD is your first option. Once you boot from CD you should be working in a cut-down version of either of these operating systems and should have access to the files on your hard drive.  (Free)
  4. Download Knoppix.  Knoppix is similar to using Mini Xp or Mini 7, it is just a small operating system that you can run from a CD.  So download the image (.iso file) and burn it to a CD using ImgBurn. Go to set-up (usually pressing F2) and ensure that booting from CD is your first option. Once you boot from CD you should be in an environment where you have access to your hard drive.  There are guides to downloading and burning Knoppix to a CD on the internet that will be helpful to you. (Free)
SATA Interface - Hard Drive





IDE Interface - Hard Drive





The Guide:


By this point, whatever method you choose to use, you should have access to the file-system.  Navigate to C:/System Volume Information  (Assuming C: is your drive letter).   This folder contains a folder with restore points from the past that will help you solve your problem.  If the folder is hidden, there is a guide at the end you can follow to make is visible.  You will then want to navigate to the _restore{ [letters & digits] } folder. Inside here you will see lots of folders beginning with RP followed by some digits. Navigate into any of these folders and you need to copy the following files:
  1. _REGISTRY_MACHINE_SECURITY
  2. _REGISTRY_MACHINE_SOFTWARE
  3. _REGISTRY_MACHINE_SYSTEM
  4. _REGISTRY_MACHINE_SAM
  5. _REGISTRY_USER_.DEFAULT
Once you have copied these files you need to navigate to the /windows/system32/config/system folder and paste the files there.
If any of the following files exist, you should delete them:
  1. SECURITY
  2. SOFTWARE
  3. SYSTEM
  4. SAM
  5. DEFAULT
You then want to rename the following:
  1. _REGISTRY_USER_.DEFAULT to DEFAULT
  2. _REGISTRY_MACHINE_SECURITY to SECURITY
  3. _REGISTRY_MACHINE_SOFTWARE to SOFTWARE
  4. _REGISTRY_MACHINE_SYSTEM to transparent
  5. _REGISTRY_MACHINE_SAM to SAM
You can then reboot your machine.  You now want to boot to the Hard Drive so if you changed any settings in the BIOS Set-up then change them back.  You should successfully boot into Windows XP and everything should seem normal, but we now need to do a System Restore.  To do a system restore you:
  1. Click Start, then click All Programs.
  2. Click Accessories, then click System Tools.
  3. Click System Restore, and then click Restore to a previous RestorePoint.
  4. Choose a restore point, preferably not too far in the past otherwise your applications may all require updating or changing. It will not delete any of your data.
 Once the system restore has completed you should have a fully functioning machine again. 

Showing Hidden Files & Folders On Microsoft Windows XP Professional or Windows XP Home Edition:

  1. Click Start,then My Computer.
  2. On the Tools menu, click Folder Options.
  3. On the View tab, click Show hidden files and folders.
  4. Clear the Hide protected operating system files (Recommended) check box. Click Yes when you are prompted to confirm the change.
  5. Click OK.

















Tuesday, 30 July 2013

MySQL Server (5.6), Installer, Connector or WorkBench Wont't Install (Windows 7 64-bit)

If you’re having trouble installing MySQL on Windows 7 (Any other platform will probably be the same) then I’d recommend the following process.  Don’t skip the first steps that describe the uninstall and removal of the previous install as this seems to clear up most issues.   

Caution: deleting the data files will delete any data previously entered into MySQL.

1.  Remove previous MySQL installs (and remnants)
a.  Stop the MySQL service ( Start | Control Panel | System & Security | Administrative Tools | Services)

b.  Remove All programs with MySQL in the name from Windows Add or Remove Programs (Start | Control Panel | Uninstall a Program)

c.  Delete the MySQL data directory (It is a hidden folder) from  (You will lose any stored data so you may wish to make a copy) :
       c:\Users\{Your Username}\AppData\Local\MySQL
       c:\Users\{Your Username}\AppData\LocalLow\MySQL
       c:\Users\{Your Username}\AppData\Roaming\MySQL


d.  Delete the MySQL folders from
        c:\program files\MySQL\
        c:\program files(x86)\MySQL\
        c:\program data\MySQL\                --(this is also a hidden folder)


————–
That’s it for the removal and clean up.  Now, we’ll begin the install.

2.a  Go to the MySQL Website and install the latest MySQL Installer.  It should come in the form of an MSI installer and comes for a 32 bit machine(x86) but will run on a 64-bit machine.

b.  Launch the installer which can be found in your Downloads folder.  Follow the Wizard through to the end and make sure you make note of the password you set for your new installation of the server in case you forget it 

TROUBLESHOOTING
What if it didn’t work?

1.  Check the service from the control panel.  Is it running?  If so, try to log into MySQL.  I’ve seen instances where an error was received, but it completed successfully.  If it’s not running, try to start it and please post the complete error message.

2.  Check the error log.  It’s in C:\Users\AppData\MySQL\MySQL Server 5.6\data   It has an .err extension and you should be able to open it with notepad.  Ignore any errors about the innodb plugin not loading.  It’s a symptom, not the problem.  Look for an error about missing data files or a mismatch in file sizes.

3.  1045 error?  It should indicate Password: No or Password:yes.  If “yes”, it’s not a port issue, not a firewall issue — it’s a password issue.  It’s usually caused by not deleting out the data files from an old install.  The password is kept in the data directory and it’s likely that the password you entered during the previous install doesn’t match what you’re entering now.  You can either re-install after deleting all the files or try to reset your root password.  (resetting root password: http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html )

4.  Still stuck?   Email Oracle's Support Team

Thursday, 25 July 2013

XSLT Error For Solr - HTTP Status 500 - {msg=getTransformer fails in getContentType...

It is common to apply an XSLT stylesheet to an xml file to give it a cleaner look and Solr is no different coming with 4 pre-written xslt files for you to choose from.  

The error message XSLT Error For Solr - HTTP Status 500 - {msg=getTransformer fails in getContentType... is a common one and in most cases is easily fixed.  There are a few reasons that the error message appears:

  1. You have not specified a stylesheet to use
           e.g http://localhost:8080/solr/select?q=*&wt=xslt
    Make sure you have specified a stylesheet and that the stylesheet you specified actually exists
           e.g http://localhost:8080/solr/select?q=*&wt=xslt&tr=example.xsl
  2. A common mistake is to think that a stylesheet has a .xslt file extension - THEY DONT! The file extension is .xsl so be sure when you save your file and when you specify it in your query that you use .xsl
  3. There are errors in you XSL file - Be careful if you are working in an environment that does not do syntax checking (notepad) - It is easy to forget to close a tag or make a spelling mistake.

Stack Trace:
 {msg=getTransformer fails in getContentType,trace=java.lang.RuntimeException: getTransformer fails in getContentType at org.apache.solr.response.XSLTResponseWriter.getContentType(XSLTResponseWriter.java:74) at org.apache.solr.servlet.SolrDispatchFilter.writeResponse(SolrDispatchFilter.java:623) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:372) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:155) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.io.IOException: 'tr' request parameter is required to use the XSLTResponseWriter at org.apache.solr.response.XSLTResponseWriter.getTransformer(XSLTResponseWriter.java:1

Tuesday, 23 July 2013

Setting Up Tika & Extracting Request Handler

Setting Up Tika's Extracting Request Handler

Some of this is covered in the set-up of Solr
Sometimes indexing prepared text files (such as XML, CSV, JSON, etc) is not enough. There are numerous situations where you need to extract data from binary files. For example, indexing PDF files – actually their contents. To do that we can use Apache Tika which comes built in with Apache Solr by using its ExtractingRequestHandler.


Preparation

You should have worked through the set-up for Solr prior to this point and can be found at:

If you wish to have a fully functioning file or web crawler using Nutch that Indexes to Solr then follow the next steps of the guide at:   

Set-Up Guide

  • In the $SOLR_HOME/collection1/conf/solrconfig.xml file there will be a section with heading - Solr Cell Update Request Handler. The code there should be updated or replaced to say:
<requestHandler name="/update/extract" class="solr.extraction.ExtractingRequestHandler">
  <lst name="defaults">
    <str name="fmap.content">text</str>
   <str name="lowernames">true</str>
   <str name="uprefix">attr_</str>
   <str name="captureAttr">true</str>
 </lst>
</requestHandler>
  • Create an "extract" folder anywhere in the system, one option would be putting it in the solr_home folder. Then place the solr-cell-4.3.0.jar file in it from the $SOLR/dist. Then copy the contents of the $SOLR/contrib/extraction/lib/ folder into your extract folder.
  • In the solrconfig.xml file add code for the directory you have chosen:
<lib dir="$SOLR_HOME/extract" regex=".*\.jar" />
  • In the schema.xml file the <field name="text"…..> line needs edited to say
<field name="text" type="text_general" indexed="true" stored="true" multiValued="true"/>
  • To test that it works open command prompt and navigate to any directory containing a pdf file and execute the following code replacing the filename with the file to be used:
curl "http://localhost:8080/solr/update/extract?literal.id=1&commit=true" -F "myfile=@FILENAME.pdf"
  • If all has worked correctly then the following output should be displayed
<?xml version="1.0" encoding="UTF-8"?>
<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">578</int>
  </lst>
</response>

Next Steps

You now have Solr configured properly and ready to use Tika to extract the data that you need.  The next step is configure Nutch, an open source web crawler that will crawl the web to find pages to index:  

How It Works

Binary file parsing is implemented using the Apache Tika framework. Tika is a toolkit for detecting and extracting metadata and structured text from various types of documents, not only binary files but also HTML and XML files. To add a handler that uses Apache Tika, we need to add a handler based on the solr.extraction.ExtractingRequestHandler class to our solrconfig.xml file as shown in the example. In addition to the handler definition, we need to specify where Solr should look for the additional libraries we placed in the extract directory that we created. The dir attribute of the lib tag should be pointing to the path of the created directory. The regex attribute is the regular expression telling Solr which files to load. Let's now discuss the default configuration parameters. The fmap.content parameter tells Solr what field content of the parsed document should be extracted. In our case, the parsed content will go to the field named text. The next parameter lowernames is set to true; this tells Solr to lower all names that come from Tika and have them lowercased. The next parameter, uprefix, is very important. It tells Solr how to handle fields that are not defined in the schema.xml file. The name of the field returned from Tika will be added to the value of the parameter and sent to Solr. For example, if Tika returned a field named creator, and we don't have such a field in our index, then Solr would try to index it under a field named attrcreator which is a dynamic field. The last parameter tells Solr to index Tika XHTML elements into separate fields named after those elements. Next we have a command that sends a PDF file to Solr. We are sending a file to the /update/ extract handler with two parameters. First we define a unique identifier. It's useful to be able to do that during document sending because most of the binary document won't have an identifier in its contents. To pass the identifier we use the literal.id parameter. The second parameter we send to Solr is the information to perform the commit right after document processing.

Source Code

If you are unsure of anything then pop me an email and i can send you sample schema.xml and solrconfig.xml for you to use.

Nutch crawling slowly - Multi-Threaded Solution

Expecting Nutch to be flying through all the websites you want it to crawl but in reality it is sequentially, one by one going through each page. Well you have not configured Nutch to use multiple threads! Multiple threads allows many threads to work in "parallel" and speed up the job significantly.

Preparation

At this point you should have Solr and Tika set-up as well as having Nutch ready to crawl . The guides can be found here:
The required changes that need to be done to make Nutch crawl a file-system require that Nutch is set-up to crawl the web so please ensure you have read the post.
To configure your multi-threaded Nutch crawler is easy:
In the nutch-site.xml add the code between the <configuration> tags add:
<property>
<name>fetcher.threads.per.queue</name>
   <value>10</value>
   <description></description>
</property>

<property>
<name>fetcher.threads.per.host</name>
   <value>10</value>
   <description></description>
</property> 
10 threads was the most efficient to use on the crawling data set I chose and would advise you to start with the number of threads around here, having too many threads will slow the computer down and you may be left working at a similar speed to that of the sequential crawler. 

RESTful Java Web Service For Solr


You have your Solr server set-up, now what?  You want people to be able to perform queries and have some control over what can be input, well you need a Java Web Service!  This is a short guide on how to create your Java Web Service which may not be tailored to your particular needs but you can tweak it as you please.

Set-Up

To set up the Java Web Service you will need:
  • Netbeans 7 with GlassFish
  • Solr Set-up and Running


Steps Involved

Project Set-Up

  • Start Netbeans and Go to FileNew ProjectJava WebWeb Applications and then hit Next.
  • Give your project a name and then hit Next
  • Ensure that Glassfish is the selected server and hit Finish

HelloResource.java

  • Right click the Default Package and create a new Java Class and call it HelloResource.java
  • Enter the following code:

    import java.net.URL;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.QueryParam;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URLConnection;
     
    /**
     *
     * @author alamil
     */
     
    //Looks for hello in the pathname
    @Path("hello")
    public class HelloResource {
     
        /**
         *
         * @param arg
         * @param rows
         * @return
         */
        @GET
        @Path("/query")     //Looks for /query in the pathname
        @Produces("text/xml")       //Returns xml
        public String hello(@QueryParam("q") String arg, @QueryParam("rows") String rows, @QueryParam("filter") String filter){
     
            //Variables
            String xmldoc = "";
            String inputLine;
     
            //If the user has not selected a number of rows to display then 50 is set to defualt
            if (rows == null) 
                rows = "50";
     
            //If the user has not selected fields to filter on then it uses the default
            if (filter == null)
                filter = "id,title";
     
            try{
     
                //Trys to connect to the Solr Server with the query
                URL solr = new URL("http://localhost:8080/solr/select?q=url:(" + arg.replaceAll(" ","%20") 
                        + ")^25%20text:(" + arg.replaceAll(" ","%20") + ")&fl=" + filter + "&rows=" + rows);
     
                URLConnection yc = solr.openConnection();
     
                //Reads the returned xml file from the server
                BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
     
                while ((inputLine = in.readLine()) != null){ 
                        xmldoc = xmldoc + inputLine;
                }
     
                //Close the file
                in.close();
     
                //Return the xml document (Replacing the %20's with spaces)
                return xmldoc.replaceAll("%20", " ");
            }catch (Exception e){
                    return "Exception";
            }
        }
    }

RESTConfig.java

  • Right click the Default Package and create a new Java Class and call it RESTConfig.java
  • Enter the following code:

    import javax.ws.rs.core.Application;
    import javax.ws.rs.ApplicationPath;
    /**
     *
     * @author alamil
     */
    @ApplicationPath("SearchInt")
    public class RESTConfig extends Application {
     
    }

Testing

  • Go to RunRun Project and your server should start
  • A browser window will open to the index.html page that is there which you can tweak and edit to your own liking
  • Start your solr server
  • In your browser, Navigate to:
    localhost:8080/HelloRest/SearchInt/hello/query?q=[query term]&filter=[filter term]&rows=[rows]
  • The input parameters set up are:
    1. q=… : representing the keywords in the query
    2. rows=… : representing the number of rows you wish to have returned
    3. filter=… :representing which fields are displayed to the user
Your server and Solr server may be running from the same port which can cause problems

Monday, 22 July 2013

C# Web Service To Query Solr (REST)

Preparation

You should have a Solr Server set-up on port 8080, configured to use Tika's extracting reuqest handler as well as having the highlighting functionality: 
http://amac4.blogspot.co.uk/2013/08/setting-up-highlighting-for-solr-4.html
http://amac4.blogspot.co.uk/2013/07/setting-up-tika-extracting-request.html
http://amac4.blogspot.co.uk/2013/07/setting-up-solr-with-apache-tomcat-be.html
Now that you have your Solr server up and running, now what? How do you query? How to you make use of the server? Well, you need to create a web service that will query Solr when the method is called from an ASP page. If you want your search service to be used on the web then you should most certainly consider creating a web service to provide you with a clean solution to the problem.
I am a novice when it comes to C# and this was my first involvement with the language, but due to the similarities it holds with Java, it wasn't difficult to understand the basics and get the web service up and running. It will return an xml file based on the input parameters and has the capability of highlighting too

You will require:

  • Microsoft Visual Studio with .NET framework of 3.5 or higher

Running The Web Service

  • Open Microsoft Visual Studio
  • Go to File→New Project and ensure that .NET Framework 3.5 is selected from the pull-down menu. Then select ASP.NET Web Service Application using Visual C#. Give your Web Service a relevant name and hit OK
  • Input the source code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Net;
    using System.Xml;
    using System.Web.UI;
     
    namespace Query
    {
        /// <summary>
        /// Queries the Solr Server based on input parameters and returns the XML response
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class Service1 : System.Web.Services.WebService
        {
     
            [WebMethod(Description = "Query Solr server and return XML response")]
            public XmlDocument QuerySolr(string keyword, string notKeyword, string exact, string rows, string filter,
                string fuzzy, string highlight)
            {
     
     
                /*  Default values should the user not enter anything */
                if (rows.Equals(""))
                    rows = "50";
     
                if (keyword.Equals("") && notKeyword.Equals("") && exact.Equals(""))
                    keyword = "*";
     
                if (filter.Equals(""))
                    filter = "id,title";
     
                if (!exact.Equals(""))
                    exact = " \"" + exact + "\"";
     
                if(!highlight.Equals(""))
                    highlight = "&hl=true&hl.fl=content";
     
                /* Should the user require that a certain word or words are not present */
                if (!notKeyword.Equals(""))
                {
     
                    /* Split each word */
                    string[] nwords = notKeyword.Split(null);
                    notKeyword = "";
     
                    /* Loops and adds the hyphen to each word */
                    for (int i = 0; i < nwords.Length; i++)
                    {
                        notKeyword = notKeyword + "-" + nwords[i] + " ";
                    }
                    notKeyword = notKeyword.Substring(0, notKeyword.Length - 1);
     
                }
     
                /* Should the user enable a fuzzy search a tilda must be added on to the end of each word */
                if (fuzzy.Equals("true") && !keyword.Equals(""))
                {
     
                    /* Splits the words by whitespace */
                    string[] words = keyword.Split(null);
                    keyword = "";
     
                    /* Loops and adds the tilda to each word */
                    for (int i = 0; i < words.Length; i++)
                    {
                        keyword = keyword + words[i] + "~ ";
                    }
                    keyword = keyword.Substring(0, keyword.Length - 1);
     
                }    
     
                /* Will throw an error should it have problems connecting to the Solr server */
                try
                {
     
                    /* Connecting to the Solr server and querying it with the search criteria that the user has provided*/
                    WebClient client = new WebClient();
                    string text = client.DownloadString(
                        "http://localhost:8080/solr/select?q=url:("+ keyword + " " + notKeyword + exact + ")^20%20text:("+ keyword
                        + " " + notKeyword + exact + ")&fl=" + filter + "&rows=" + rows + highlight);
     
                    /* The response is returned as a string so it must turn it into an XML document */
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(text.Replace("%20", " ").Replace("\\", "/"));   //Changes to windows style filepath
     
                    return xml;
     
                }
                catch (Exception)
                {
                    /* Should an exception occur it returns an XML document with details of the problem */
                    XmlDocument xmle = new XmlDocument();
                    xmle.LoadXml("<Problem>Solr server cannot be reached</Problem>");
     
                    return xmle;
                }
            }
     
        }
    }
  • To test the Web Service hit the Green Triangle in the Top Menu
  • A Browser Window should open and display the Web Services that are currently being offered, click on the Query Solr Web Service
  • You should be able to enter the search criteria beneath and hit invoke to test your results