• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7137
  • Last Modified:

Batch Script to restart IIS remotely

I'm looking for a way to write a batch or vbscript to restart iis remotely.  This script is inserted into my backup command script that runs batch or vbscript type commands.  The problem this computer doesn't have iis installed on it so I can't jsut run iisrest/timeout:300 computername.  Is there a way to have a script that connnects to this server and runs the iisreset command?  Currently I runnign a batch script natievly on the server with iis but would like to include this after my backup command since thi sis a requirement after I shutdown the db it runs on for the backup.  When the db comes back online iss needs to be reset.  Including this in the backup script with make managing things easier.
0
georgedschneider
Asked:
georgedschneider
  • 10
  • 8
  • 3
  • +2
2 Solutions
 
knightEknightCommented:
First, create a scheduled task on the server that runs your batch file.  Disable the task so that it doesn't run automatically.

Then you can manually run the task from your remote host by doing this:

schtasks.exe  /run  /s yourServerName  /tn nameOfTheTask
0
 
Kentrix70Commented:
Hi there.

I have just typed another suggestion, close to the first.

You could schedule a task on the iisserver that runs iisreset.exe.
I have had problems by calling iisreset in a script, so I would recommend
to just call the iisreset.exe directly in the task.
You could call the task "Iisreset" :-)

Then afterwards, you download psexec.exe from

www.sysinternals.com,

put it in the system32 folder on the machine or server you want to
use for initiating the iisreset on your webserver.

You then call this in a script:

start psexec \\ddkcx01 schtasks /run /TN "Iisreset"

and the local scheduled task is being run.

The good thing about this solution is, that you should not worry much about
your rights to do stuff through the network.
You initiate a local job, that is run with an account belonging to the machines "administrators" account,
and you have all the necessary rights.

If you ever is starting the job, and it won't stop or has some problems,
you can stop the job by creating a script with:

start psexec \\ddkcx01 schtasks /end /TN "Iisreset"

But that should not be necessary under normal circumstances.
0
 
Kentrix70Commented:
Sorry about 2 of the lines

I by mistake included a local servername from one of my own scripts.

start psexec \\webserver schtasks /run /TN "Iisreset"

start psexec \\webserver schtasks /end /TN "Iisreset"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
oBdACommented:
You can simply copy iisreset.exe from the webserver to your backup server; it's a stand-alone utility, it doesn't require IIS on the local machine to restart IIS remotely on another machine.
0
 
georgedschneiderAuthor Commented:
I tried that but I get an interface not registered.  How do I register the interface or what do I need to do to get it work?  I copied it to the sytsem32 directory in the exact same location as it is on a working server with iis installed.
0
 
Kentrix70Commented:
What OS are you using for the remote iis reset?
0
 
qualchoice-itCommented:
Use the SC.exe command, built into XP, W2k3, or installed from the W2k reskit.

C:\>sc
DESCRIPTION:
        SC is a command line program used for communicating with the
        NT Service Controller and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...

        The option <server> has the form "\\ServerName"
        Further help on commands can be obtained by typing: "sc [command]"
        Commands:
          query-----------Queries the status for a service, or
                          enumerates the status for types of services.
          queryex---------Queries the extended status for a service, or
                          enumerates the status for types of services.
          start-----------Starts a service.
          pause-----------Sends a PAUSE control request to a service.
          interrogate-----Sends an INTERROGATE control request to a service.
          continue--------Sends a CONTINUE control request to a service.
          stop------------Sends a STOP request to a service.
          config----------Changes the configuration of a service (persistant).
          description-----Changes the description of a service.
          failure---------Changes the actions taken by a service upon failure.
          qc--------------Queries the configuration information for a service.
          qdescription----Queries the description for a service.
          qfailure--------Queries the actions taken by a service upon failure.
          delete----------Deletes a service (from the registry).
          create----------Creates a service. (adds it to the registry).
          control---------Sends a control to a service.
          sdshow----------Displays a service's security descriptor.
          sdset-----------Sets a service's security descriptor.
          GetDisplayName--Gets the DisplayName for a service.
          GetKeyName------Gets the ServiceKeyName for a service.
          EnumDepend------Enumerates Service Dependencies.

        The following commands don't require a service name:
        sc <server> <command> <option>
          boot------------(ok | bad) Indicates whether the last boot should
                          be saved as the last-known-good boot configuration
          Lock------------Locks the Service Database
          QueryLock-------Queries the LockStatus for the SCManager Database
0
 
georgedschneiderAuthor Commented:
windows 2003
0
 
qualchoice-itCommented:
Remeber to include the stop of the dependencies as well

1 WorldWide Web Publishing Service
2 FTP Publishing Services (If you have ftp installed)

So if I wanted to scipt this out to stop IIS it would look like this, make sure you do this under an admin account

@echo on
sc \\"servername" stop W3SVC
sc \\"servername" stop MSFTpsvc
sc \\"servername" stop IISadmin

0
 
oBdACommented:
What OS is running on the webserver, and what is the *exact* error message you're getting on the machine you're running iisreset.exe from? Do you have a firewall running on the webserver?

qualchoice-it,
it's not that easy with sc.exe. sc sends the command and returns *immediately*; it does NOT wait for a successful finish.
0
 
georgedschneiderAuthor Commented:
the web server is running windows 2003.  Te machine I'm runnign iisreset form is also a windows 2003.  All i did is copy iisreset from a web server running iss that I can run iisreset form to this server.  Is there something else i need to do such as copy a dll or register a dll to get it ot work?  

The error message is interface not registered.
0
 
qualchoice-itCommented:
then add a SLEEP 60 between each one, and put some logging in it

@echo on
sc \\"servername" stop W3SVC
SLEEP 60
echo stop service >> \\"servername"\"folder"\%computername%\logfile.txt
sc \\"servername" stop MSFTpsvc
SLEEP 60
echo stop service >> \\"servername"\"folder"\%computername%\logfile.txt
sc \\"servername" stop IISadmin
SLEEP 60
echo stop service >> \\"servername"\"folder"\%computername%\logfile.txt
0
 
Kentrix70Commented:
What happens if you install asp.net on the server, you want to run iisreset from.
It looks like they are close connected.
0
 
oBdACommented:
What happens if you just run
%systemroot%\system32\iisreset.exe /?
*exactly* like this, do not leave out the ".exe"?
Is "interface not registered" the *exact*, literal, and only information you get?
Do you get this error as popup or in the console?
Again: is there a firewall running on the webserver blocking traffic from the "backup" machine?
What is the file version of iisreset.exe?
0
 
georgedschneiderAuthor Commented:
When  run the following coammnd %systemroot%\system32\iisreset.exe /? I get the help mneu as expected.

I tried running the whole command like this and still get the interface not registered which is the only message I get.  

I have no firewalls running between machines either.
0
 
Kentrix70Commented:
You need to install iis on the Windows 2003 server, that you want to use for remote restart.
Then you can just stop the www service and disable it.

I tried that on a Windows XP - I think it is the only way.

Then the iisreset is available to you.
0
 
georgedschneiderAuthor Commented:
What about just installing the management tools for iis6 would this work as well?
0
 
Kentrix70Commented:
I think it is worth a try to install that. It wouldn't do any harm,
and the chances are pretty good, that this would work.
If it doesn't you could try my suggestion about installing IIS.
0
 
georgedschneiderAuthor Commented:
Are there management tools for IIS for Windows 2003 outside of installing full fledge IIS?  The management tools I can find seem to be only for XP based computers?
0
 
Kentrix70Commented:
0
 
Kentrix70Commented:
Or you could try the new version.
I don't know if it supports iis 6 too,
but I think the chances are pretty fair.

http://www.microsoft.com/downloads/details.aspx?familyid=32C54C37-7530-4FC0-BD20-177A3E5330B7&displaylang=en
0
 
georgedschneiderAuthor Commented:
I don't think the IIS manager is included with the toolpack which is what i think is needed for iisreset to work.
0
 
Kentrix70Commented:
I have found a solution.

On the 2003 server you want to use for remote restart.

Click Add or Remove programs

click add/remove windows components
doubleclick Application Server
doubleclick Internet Infromation Services (IIS)
Choose Internet Information Services Manager (common files will also be selected).

click ok a couple of times.

The iisreset command is available to you,
but if you look under Internet Information Services (IIS) Manager,
there is no websites there.
0
 
Kentrix70Commented:
I just checked, and there is no WWW service, on the server, I tried this test on.

So this setup should work for you.
0
 
georgedschneiderAuthor Commented:
That worked perfectly.  I did however remember that windows taks scheduleder can have multiple schedules set up so I was able to create a batch script to run iisrest and scheduled it to run weekly at 7:00 AM after the backup and on the first of the month which is when the backup runs.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 8
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now