Question

Batch Script to restart IIS remotely

Asked by: georgedschneider

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.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-04-03 at 16:24:51ID24294058
Topics

VB Script

,

Windows Batch Scripting

Participating Experts
4
Points
500
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. IIS crashes/hangs - IISRESET once a week
    We're running IIS5 and keep having problems that it either crashes or just hangs. We never get any errors in the event logs. The only indications are that the web site we're running is down, and our SMTP mail does not go anywhere. With SMTP, it appears incoming and outgoin...
  2. Remote IISRESET
    I need to establish a procedure that will allow our 24x7 computer operators restart IIS on one of our (internal) web servers if we have an issue. If they sat in front of WIN2K machinces, I would just put a shortcut on thier desktop that would call a program prompt for a pas...
  3. ISS - PHP: file upload problem
    Hi experts, I am using Windows 2003 and ISS 6.0 to host a forum board that runs on php. I have installed PHP on my server and it has been working without problem. Now i am getting an error message when trying to upload files to forum. my forum is at http://aggieaccess.tamu....
  4. iisreset permission
    Is there anyway to have a regular user restart IIS. There is a user that is allowed to log on locally and needs to run iisreset. I dont want to make him an admin, Thanks

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: knightEknightPosted on 2009-04-03 at 16:50:54ID: 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

 

by: Kentrix70Posted on 2009-04-03 at 16:53:49ID: 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.

 

by: Kentrix70Posted on 2009-04-03 at 16:55:56ID: 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"

 

by: oBdAPosted on 2009-04-04 at 06:02:23ID: 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.

 

by: georgedschneiderPosted on 2009-04-04 at 06:50:35ID: 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.

 

by: Kentrix70Posted on 2009-04-05 at 12:19:30ID: 24072620

What OS are you using for the remote iis reset?

 

by: qualchoice-itPosted on 2009-04-05 at 12:38:39ID: 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

 

by: georgedschneiderPosted on 2009-04-05 at 12:45:24ID: 24072700

windows 2003

 

by: qualchoice-itPosted on 2009-04-05 at 12:53:11ID: 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

 

by: oBdAPosted on 2009-04-05 at 14:58:09ID: 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.

 

by: georgedschneiderPosted on 2009-04-05 at 15:08:52ID: 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.

 

by: qualchoice-itPosted on 2009-04-05 at 15:26:56ID: 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

 

by: Kentrix70Posted on 2009-04-05 at 16:00:18ID: 24073353

What happens if you install asp.net on the server, you want to run iisreset from.
It looks like they are close connected.

 

by: oBdAPosted on 2009-04-06 at 00:26:43ID: 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?

 

by: georgedschneiderPosted on 2009-04-06 at 04:23:34ID: 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.

 

by: Kentrix70Posted on 2009-04-06 at 06:10:21ID: 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.

 

by: georgedschneiderPosted on 2009-04-06 at 12:24:43ID: 24080815

What about just installing the management tools for iis6 would this work as well?

 

by: Kentrix70Posted on 2009-04-07 at 02:12:11ID: 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.

 

by: georgedschneiderPosted on 2009-04-13 at 14:14:56ID: 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?

 

by: Kentrix70Posted on 2009-04-13 at 14:40:04ID: 24133148

 

by: Kentrix70Posted on 2009-04-13 at 14:43:01ID: 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

 

by: georgedschneiderPosted on 2009-04-14 at 11:56:18ID: 24141316

I don't think the IIS manager is included with the toolpack which is what i think is needed for iisreset to work.

 

by: Kentrix70Posted on 2009-04-14 at 12:25:38ID: 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.

 

by: Kentrix70Posted on 2009-04-14 at 12:30:39ID: 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.

 

by: georgedschneiderPosted on 2009-04-14 at 14:06:41ID: 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.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...