[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Batch Script to restart IIS remotely

Posted on 2009-04-03
25
Medium Priority
?
7,005 Views
Last Modified: 2012-05-06
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
Comment
Question by:georgedschneider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 8
  • 3
  • +2
25 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 1000 total points
ID: 24065265
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
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24065286
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
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24065300
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 85

Expert Comment

by:oBdA
ID: 24067202
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
 

Author Comment

by:georgedschneider
ID: 24067349
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
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24072620
What OS are you using for the remote iis reset?
0
 
LVL 3

Expert Comment

by:qualchoice-it
ID: 24072671
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
 

Author Comment

by:georgedschneider
ID: 24072700
windows 2003
0
 
LVL 3

Expert Comment

by:qualchoice-it
ID: 24072730
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
 
LVL 85

Expert Comment

by:oBdA
ID: 24073147
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
 

Author Comment

by:georgedschneider
ID: 24073195
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
 
LVL 3

Expert Comment

by:qualchoice-it
ID: 24073250
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
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24073353
What happens if you install asp.net on the server, you want to run iisreset from.
It looks like they are close connected.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 24074978
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
 

Author Comment

by:georgedschneider
ID: 24076104
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
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24076931
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
 

Author Comment

by:georgedschneider
ID: 24080815
What about just installing the management tools for iis6 would this work as well?
0
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24085219
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
 

Author Comment

by:georgedschneider
ID: 24132990
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
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24133148
0
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24133173
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
 

Author Comment

by:georgedschneider
ID: 24141316
I don't think the IIS manager is included with the toolpack which is what i think is needed for iisreset to work.
0
 
LVL 6

Assisted Solution

by:Kentrix70
Kentrix70 earned 1000 total points
ID: 24141588
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
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24141640
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
 

Author Comment

by:georgedschneider
ID: 24142588
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question