понедельник, 25 апреля 2011 г.

Java: how to test, run or not some process in your system?

public static boolean isRunning(String procName) {
    boolean found=false;
    String command="";
    if (System.getProperty("os.name").contains("Windows")) {
        command="tasklist";
    } else {
        command="ps ax";
    }
    try {
        Runtime r = Runtime.getRuntime();
        Process p = r.exec(command);
        p.waitFor();
        BufferedReader br = new BufferedReader (new InputStreamReader (p.getInputStream()));
        while (br.ready()) {
            if (br.readLine().contains(procName)) 
                 found=true;
        }
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        return found;
    }
}

понедельник, 18 апреля 2011 г.

How I get eth0 ip address

hostname -I|sed -e 's/\s.*//g'

If you have any better idea - write it in comments please. Also, if anybody knew how to get external ip address, write it too.

Updated:
ifconfig eth0|grep 'inet '|sed -e 's/[A-Z,a-z,:]//g;s/^\s*//g;s/\s.*//g'

if you're get fear from regexp:

ifconfig eth0|grep 'inet addr'|sed -e 's/[A-Z,a-z,:]//g'|awk '{print $1}'

пятница, 8 апреля 2011 г.

How to get domain administrator privilegies in Windows Server 2003 / 2008

That we need:
  1. Physical access to the server
  2. ERD Commander CD (or other with Locksmith utility)
  3. Head + Hands
Your actions:
  1. Insert CD and boot from ERD Commander
  2. Use locksmith to get privilegies of local administrator
  3. Reboot
  4. Boot windows server in directory restore mode
  5. Login with your local admin username and password
  6. Put cmd.exe, srvany.exe and instsrv.exe in C:\tools (or some other directory)
  7. Run cmd.exe
  8. cd C:\tools
  9. instsrv PassRecovery C:\tools\srvany.exe
  10. Set autorun to this service (in Settings panel or write services.msc) (PassRecovery)
  11. Run regedit
  12. Create subfolder Parameters in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\PassRecovery
  13. Add keys (String): Application (C:\tools\cmd.exe) and AppParameters (/k net user administrator (name of domain administrator) Pa$$w0rd (new password, must be match to security policy) /domain)
  14. example: /k net user admin Pa$$w0rd /domain
  15. In service settings in tab log on enable checkbox Allow Service to interract with desktop, apply.
  16. Reboot
  17. Run
  18. Enjoy.