=> dimasite

IT for(;;) fun!

Archive for the ‘SysAdmin’ Category

Windows Services from command line & Findstr: the Windows’ “grep”

Posted by Dmitrij Ivanov on February 3, 2011

If you need to interact with windows services and have detailed information about them using the command line you could dig into SC command functionalities. SC has more options but I’ll show you just few of them. If you want some more I invite you to read the related help documentation. So let start.

Show all active services. The “active” status is shown by default.

c:\>sc query

...
NOME_SERVIZIO    : uCamMonitor
NOME_VISUALIZZATO: CamMonitor
        TIPO                   : 10  WIN32_OWN_PROCESS
        STATO                  : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        CODICE_USCITA_WIN32    : 0  (0x0)
        CODICE_USCITA_SERVIZIO : 0  (0x0)
        PUNTO_CONTROLLO          : 0x0
        INDICAZIONE_ATTESA     : 0x0

NOME_SERVIZIO    : WSearch
NOME_VISUALIZZATO: Windows Search
        TIPO                   : 10  WIN32_OWN_PROCESS
        STATO                  : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        CODICE_USCITA_WIN32    : 0  (0x0)
        CODICE_USCITA_SERVIZIO : 0  (0x0)
        PUNTO_CONTROLLO          : 0x0
        INDICAZIONE_ATTESA     : 0x0

NOME_SERVIZIO    : wuauserv
NOME_VISUALIZZATO: Windows Update
        TIPO                   : 20  WIN32_SHARE_PROCESS
        STATO                  : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_PRESHUTDOWN)
        CODICE_USCITA_WIN32    : 0  (0x0)
        CODICE_USCITA_SERVIZIO : 0  (0x0)
        PUNTO_CONTROLLO          : 0x0
        INDICAZIONE_ATTESA     : 0x0
...

Show all inactive services. Mind the space between the equal char and the status name.

c:\>sc query state= inactive

...
NOME_SERVIZIO:     WebClient
NOME_VISUALIZZATO: WebClient
        TIPO                    : 20  WIN32_SHARE_PROCESS
        STATO                   : 1  STOPPED
        CODICE_USCITA_WIN32     : 1077  (0x435)
        CODICE_USCITA_SERVIZIO  : 0  (0x0)
        PUNTO_CONTROLLO         : 0x0
        SUGGERIMENTO_ATTESA     : 0x0

NOME_SERVIZIO:     WPCSvc
NOME_VISUALIZZATO: Parental Controls
        TIPO                    : 20  WIN32_SHARE_PROCESS
        STATO                   : 1  STOPPED
        CODICE_USCITA_WIN32     : 1077  (0x435)
        CODICE_USCITA_SERVIZIO  : 0  (0x0)
        PUNTO_CONTROLLO         : 0x0
        SUGGERIMENTO_ATTESA     : 0x0
...

the following will not work

c:\>sc query state = inactive
c:\>sc query state =inactive

Show active and inactive services

c:\>sc query status= all

Show information about the specified service name

C:\>sc query FontCache

NOME_SERVIZIO: FontCache
        TIPO                   : 20  WIN32_SHARE_PROCESS
        STATO                  : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        CODICE_USCITA_WIN32    : 0  (0x0)
        CODICE_USCITA_SERVIZIO : 0  (0x0)
        PUNTO_CONTROLLO          : 0x0
        INDICAZIONE_ATTESA     : 0x0

Start the service called FontCache

C:\>sc start FontCache

NOME_SERVIZIO: FontCache
        TIPO                   : 20  WIN32_SHARE_PROCESS
        STATO                  : 2  START_PENDING
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        CODICE_USCITA_WIN32    : 0  (0x0)
        CODICE_USCITA_SERVIZIO : 0  (0x0)
        PUNTO_CONTROLLO          : 0x0
        INDICAZIONE_ATTESA     : 0x7d0
        PID                    : 1480
        FLAG                   :

Stop the service called FontCache. You must have administrative privileges!

C:\>sc stop FontCache

NOME_SERVIZIO: FontCache
        TIPO                   : 20  WIN32_SHARE_PROCESS
        STATO                  : 3  STOP_PENDING
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        CODICE_USCITA_WIN32    : 0  (0x0)
        CODICE_USCITA_SERVIZIO : 0  (0x0)
        PUNTO_CONTROLLO          : 0x0
        INDICAZIONE_ATTESA     : 0x0

Also, take a look at sc create and sc delete commands, which allow you to manage the registration of your own service.

If you would like to have more control over the output information you can combine the SC command with the, unknown for many people command, findstr. Findstr basically searches strings inside the files and shows the occurrences. The /R option permits to use regular expressions as input for the search. I’m using the pipe | operator to pass the output of SC command as input for the findstr command.

Show only active services names. Since the output is localized you should replace the string NOME_SERVIZIO with an appropriate translation of service name.
. means every char
* zero or more occurrences of the previous char

C:\>sc query | findstr /R "NOME_SERVIZIO.*"

...
NOME_SERVIZIO    : Appinfo
NOME_SERVIZIO    : AudioEndpointBuilder
NOME_SERVIZIO    : AudioSrv
NOME_SERVIZIO    : Power
...

Considering the regular expressions special chars, the output of the command

C:\>sc query | findstr /R ".*"

is the same as

C:\>sc query

Show services names which contain the word “Audio”.

C:\>sc query | findstr /R "NOME_SERVIZIO.*Audio"

NOME_SERVIZIO    : AudioEndpointBuilder
NOME_SERVIZIO    : AudioSrv

Show services names which contain the word “Audio” followed by the word “Bui”.

C:\>sc query | findstr /R "NOME_SERVIZIO.*Aud.*Bui"

NOME_SERVIZIO    : AudioEndpointBuilder

Sometimes I use the “more” command which shows the file content page by page. I use the pipe | operator to pass the output of previous command as an input for the “more” command.

c:\>sc query | findstr /R "NOME_SERVIZIO.*" | more

NOME_SERVIZIO    : Appinfo
NOME_SERVIZIO    : AudioEndpointBuilder
NOME_SERVIZIO    : AudioSrv
...
-- More  --

Hit the space bar to show the next page, otherwise press the Enter key to show the next row.
That’s all.

Advertisements

Posted in SysAdmin | Tagged: , , , , , , | 1 Comment »

How to install and setup a ssh server using Cygwin on Windows

Posted by Dmitrij Ivanov on November 29, 2010

I’ve spent some time to find a solution for a free ssh server. I’ve tried http://www.freesshd.com but I saw that is different from what I expected and eventually I’ve decided to install Cygwin with my bare hands. As the result I obtained the following step by step guide.
I estimated duration of the installation should be of 15 minutes. You need administrator privileges to install the application.

1 – Create a new local folder c:\cygwin
2 – Download Cygwin’s setup from http://www.cygwin.com and save setup.exe in c:\cygwin. Cygwin is a Linux-like environment for Windows.
3 – Run c:\cygwin\setup.exe and

Select install from internet option
Select c:\cygwin as root directory and All users option
Select the Local Package Directory c:\cygwin
Choose one of the available download sites, for example http://mirrors.xmission.com

4 – We don’t need to install all the packagies. Type openssh in search textbox and press Enter.
5 – Click the ‘Skip’ word on found item until the value of the column ‘Bin?’ becames X

6 – Click Next button to start installation
7 – In Start menu right click on My Computer then click on Properties, select Advanced property page and click on Environment Variables button.
8 – Find the variable Path and click the Edit button and at the end of the string add the following value ;c:\cygwin\bin

The Path variable contains a semicolon-delimited list of directories in which the command interpreter will search for executable files.

9 – From the Program menu open Cygwin Bash Shell
10 – Optional settings. A few of cygwin distributions could have folder access problems, to avoid this you can try the following settings

chmod +r /etc/passwd
chmod u+w /etc/passwd
chmod +r /etc/group
chmod u+w /etc/group
chmod 755 /var
touch /var/log/sshd.log
chmod 664 /var/log/sshd.log

11 – In Cygwin Bash Shell type ssh-host-config answer yes for any question; for the ssh daemon value type Cygwin ssh
If will prompted “This script plans to use cyg_server, Do you want to use a different name? Answer no. You can repeat the configuration and change the settings as you prefer.

12 – As last command type cyglsa-config to register lsa authentication package

13 – In Services window now you will find a service named CYGWIN sshd

Reboot the system and the job is done.

Finally you can remove c:\cygwin\setup.exe and the folder c:\cygwin\http%3a%2f%2fmirrors.xmission.com%2fcygwin%2f

I hope it could help someone.

Posted in SysAdmin | Tagged: , , , , , | Leave a Comment »

Find large folders and big files

Posted by Dmitrij Ivanov on November 21, 2010

If you need a quick tool with minimal functionalities which shows in the intuitive treemap graph your file system, probably you are searching for SequoiaView.

SequoiaView

SequoiaView

If you need a fast, freeware and portable solution the best choise is Steffen Gerlach’s Scanner.

Scanner

Scanner

I hope will help you.

Posted in SysAdmin | Tagged: , | Leave a Comment »

Install Active Directory on Windows Server 2003 and 2008

Posted by Dmitrij Ivanov on September 20, 2010

If you need to play a little bit with an active directory and you dont know how to insall it on Windows Server 2003 the following link may be can help you. For intallation instructions on Windows Server 2008 check this step by step guide.

Posted in SysAdmin | Tagged: | Leave a Comment »

Visual Studio 2010 could be slow on XP, Vista and Windows Server 2003/2008 systems

Posted by Dmitrij Ivanov on September 17, 2010

The cause of the slowness may depend on UIA  (Windows Automation) installed on your system. UIA3 is shipped with Windows 7  and is raccomended Windows Update patch on Xp and Vista.

If you are running on Windows XP, Vista, or Windows Server 2003 or 2008 and are seeing any performance issues with the editor or IDE,  install the free UIA 3 update that can be downloaded from this page.  If you scroll down the page you’ll find direct links to versions for each OS.

Posted in SysAdmin | Tagged: , | Leave a Comment »