You must have same rights on the machine you are running this from
shutdown /r /m \\severname
Showing posts with label cmd. Show all posts
Showing posts with label cmd. Show all posts
Tuesday, November 29, 2011
Wednesday, December 22, 2010
Create Batch File to Start or End Window Services
www.tech-recipes.com
The important commands are the following:
NET START – starts the service
NET STOP – ends the service
For example:
NET STOP "Error Reporting Service"
Output: The Error Reporting Service service was stopped successfully.
Knowing the commands, one can now easily create batch files called something like beforegame.bat and aftergame.bat.
Before.bat would contain all the NET STOP commands to end the nonessential services.
After.bat would be exactly the same except all the NET STOP commands would be replaced with NET START commands to restart all the common services.
A sample of the before.bat file might look something like this:
NET STOP "Error Reporting Service"
NET STOP "FTP Publishing Service"
SET STOP "IIS Admin"
NET STOP "Messenger"
Likewise, the after.bat file might look something like this:
NET START "Error Reporting Service"
NET START "FTP Publishing Service"
SET START "IIS Admin"
NET START "Messenger"
The important commands are the following:
NET START – starts the service
NET STOP – ends the service
For example:
NET STOP "Error Reporting Service"
Output: The Error Reporting Service service was stopped successfully.
Knowing the commands, one can now easily create batch files called something like beforegame.bat and aftergame.bat.
Before.bat would contain all the NET STOP commands to end the nonessential services.
After.bat would be exactly the same except all the NET STOP commands would be replaced with NET START commands to restart all the common services.
A sample of the before.bat file might look something like this:
NET STOP "Error Reporting Service"
NET STOP "FTP Publishing Service"
SET STOP "IIS Admin"
NET STOP "Messenger"
Likewise, the after.bat file might look something like this:
NET START "Error Reporting Service"
NET START "FTP Publishing Service"
SET START "IIS Admin"
NET START "Messenger"
STOP SERVICES and FOR LOOPS in Batch files
www.tech-recipes.com
The key is to use delimaters...well, sorta. You want to trick the FOR loop into looking for delimiters.
~~ SERVICES.TXT ~~
; be sure to surround your values by QUOTES (")
"Apache Tomcat 4.1.31"
"Apache Tomcat 5.0.27"
"MySQL41"
; and with the EOL switch, lines beginning in ";" are ignored
~~ START.EM.UP.BAT ~~
FOR /F "eol=; tokens=1,2,3,4,5,6,7* delims= " %%a IN (SERVICES.TXT) DO NET STOP %%a %%b %%c %%d %%e %%f %%g
also notice a few things
lastly, the resulting output:NET STOP "Apache Tomcat 4.1.31"
NET STOP "Apache Tomcat 5.0.27"
NET STOP "MySQL41"
The key is to use delimaters...well, sorta. You want to trick the FOR loop into looking for delimiters.
~~ SERVICES.TXT ~~
; be sure to surround your values by QUOTES (")
"Apache Tomcat 4.1.31"
"Apache Tomcat 5.0.27"
"MySQL41"
; and with the EOL switch, lines beginning in ";" are ignored
~~ START.EM.UP.BAT ~~
FOR /F "eol=; tokens=1,2,3,4,5,6,7* delims= " %%a IN (SERVICES.TXT) DO NET STOP %%a %%b %%c %%d %%e %%f %%g
also notice a few things
- 1. no quotes around filename
- 2. the "%%x" variables have two % symbols (this is because i'm running inside of a BAT already.
- 3. there are just as many "tokens" as there are "%%x" variables
- 4. there is only a space after the delims= declaration
lastly, the resulting output:NET STOP "Apache Tomcat 4.1.31"
NET STOP "Apache Tomcat 5.0.27"
NET STOP "MySQL41"
Friday, August 20, 2010
Start or stop Windows service from command line
REF: http://www.windows-commandline.com/2010/08/start-stop-service-command-line.html
We normally use Services.msc to start or stop or disable or enable any service. We can do the same from command line also using net and sc utilities. Below are commands for controlling the operation of a service.
To stop a service from command prompt:
net stop servicename
To start a service from command prompt:
net start servicename
To disable a service from command prompt:
sc config servicename start= disabled
To reenable a service from command prompt:
sc config servicename start= demand
To make a service automatic from command prompt:
sc config servicename start= auto
Note: Space is mandatory after '=' in the above sc commands
We normally use Services.msc to start or stop or disable or enable any service. We can do the same from command line also using net and sc utilities. Below are commands for controlling the operation of a service.
To stop a service from command prompt:
net stop servicename
To start a service from command prompt:
net start servicename
To disable a service from command prompt:
sc config servicename start= disabled
To reenable a service from command prompt:
sc config servicename start= demand
To make a service automatic from command prompt:
sc config servicename start= auto
Note: Space is mandatory after '=' in the above sc commands
Add user to group from command line
We can add users to a group from command line too. We can use net localgroup command for this.
For example to add user John to administrators group we can run the below command.
net localgroup administrators John /add
REF:http://www.windows-commandline.com
For example to add user John to administrators group we can run the below command.
net localgroup administrators John /add
REF:http://www.windows-commandline.com
Tuesday, July 6, 2010
PSEXEC - Remote control another server with your admin account
psexec \\computer -u domain\admin -p mypass -e cmd.exe
Managing Terminal Services Sessions Remotely
REF: http://weblogs.asp.net/owscott/archive/2003/12/30/Managing-Terminal-Services-Sessions-Remotely.aspx
Look:
qwinsta /server:12.12.12.12
Remove:
rwinsta/server:12.12.12.12 3
For example, let's say that I can't gain access to a server using Terminal Services because both sessions are used up. I can use another server to check the status of the first one. As long as the logged in user has administrative rights on the non-accessible machine I would run this:
qwinsta /server:12.12.12.12
Where 12.12.12.12 is the IP address or name of the non-accessible machine.
This will display something like this:
> qwinsta /server:12.12.12.12
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console 0 Conn wdcon
rdp-tcp 65536 Listen rdpwd
rdp-tcp#470 Bob 1 Active rdpwd
rdp-tcp#471 Jane 3 Active rdpwd
Now I know that Bob and Jane are the two that are logged in. Since Jane left the office 20 minutes ago I know that she forgot to log off. I don't know where Bob is but I only need one session so I'll ignore him for now.
To disconnect Jane's session I would type this:
rwinsta /server:12.12.12.12 3
Notice the 3 which is the session ID I found from using qwinsta above.
Yet another option with W2K3 is a new feature that lets you connect to the desktop directly and gain a 3rd session.
If you're like me, you probably noticed that rwinsta and qwinsta seems like strange names. This came from the Citrix Metaframe days which Terminal Services has descended from. It stands for:
qwinsta = Query WINdows STAtion
rwinsta = Reset WINdows STAtion
One final comment. Microsoft has replaced these two tools with Query but since qwinsta and rwinsta is fully compatible with W2K WinXP and W2K3 I choose to use it instead.
Look:
qwinsta /server:12.12.12.12
Remove:
rwinsta/server:12.12.12.12 3
For example, let's say that I can't gain access to a server using Terminal Services because both sessions are used up. I can use another server to check the status of the first one. As long as the logged in user has administrative rights on the non-accessible machine I would run this:
qwinsta /server:12.12.12.12
Where 12.12.12.12 is the IP address or name of the non-accessible machine.
This will display something like this:
> qwinsta /server:12.12.12.12
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console 0 Conn wdcon
rdp-tcp 65536 Listen rdpwd
rdp-tcp#470 Bob 1 Active rdpwd
rdp-tcp#471 Jane 3 Active rdpwd
Now I know that Bob and Jane are the two that are logged in. Since Jane left the office 20 minutes ago I know that she forgot to log off. I don't know where Bob is but I only need one session so I'll ignore him for now.
To disconnect Jane's session I would type this:
rwinsta /server:12.12.12.12 3
Notice the 3 which is the session ID I found from using qwinsta above.
Yet another option with W2K3 is a new feature that lets you connect to the desktop directly and gain a 3rd session.
If you're like me, you probably noticed that rwinsta and qwinsta seems like strange names. This came from the Citrix Metaframe days which Terminal Services has descended from. It stands for:
qwinsta = Query WINdows STAtion
rwinsta = Reset WINdows STAtion
One final comment. Microsoft has replaced these two tools with Query but since qwinsta and rwinsta is fully compatible with W2K WinXP and W2K3 I choose to use it instead.
Subscribe to:
Posts (Atom)