5

I have the following in a vbs file that i am trying to run from the command line:

strServerName = "ServerName"
strAppPoolName = "DefaultAppPool"
set objAppPools = GetObject("IIS://" & strServerName 
                                  & "/w3svc/AppPools/" & strAppPoolName & "")
objAppPools.Recycle()

And yet when I run the vbs from cmd line i get the following error:

Microsoft VBScript runtime error: ActiveX component can't create object: 'Get Object'_

I am running XP on my local machine, and the remote machine has IIS 7.

How can I get this to work?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Will I Am
  • 83
  • 1
  • 1
  • 6

8 Answers8

7

I am not sure regarding the particular vb script but I would recommend using "appcmd" (http://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe)

  1. Add %windir%\system32\inetsrv to your path if it is not already
  2. in a command prompt type: appcmd recycle apppool "apppool_name"
Dan
  • 1,396
  • 1
  • 10
  • 21
3

Use powershell command to run it. Example:

Invoke-WMIMethod Recycle -Path "IIsApplicationPool.Name='W3SVC/APPPOOLS/apppoolname'" -Computer "WIN-Computername" -Namespace root\MicrosoftIISv2 -Authentication PacketPrivacy

Where apppoolname is your application pool name.

Where WIN-Computername is your remote/local server name

jaxxbo
  • 7,314
  • 4
  • 35
  • 48
3

While not a vbs file command you could get vbs to execute this command line;

appcmd recycle apppool /apppool.name:string

The variable string is the name of the application pool that you want to recycle. For example, to recycle an application pool named Marketing, type the following at the command prompt, and then press ENTER:

appcmd recycle apppool /apppool.name:Marketing

Taken from technet

If it's too far away from what you want then my apologies.

Mike Mengell
  • 2,310
  • 2
  • 21
  • 35
  • Didn't see the remote server requirement. fair enough, prob not right. Powershell scripts will probably be the best way to go. – Mike Mengell Mar 23 '11 at 13:40
  • sorry noob here, powershell?? – Will I Am Mar 23 '11 at 13:41
  • 1
    Powershell is the new(ish) scripting language which is like vbs(x infinity) basics can be found here; http://msdn.microsoft.com/en-us/library/aa973757(v=vs.85).aspx. You probably also want something like this; http://www.windowsitpro.com/article/windows-management-instrumentation-wmi/use-powershell-to-execute-commands-on-remote-machines.aspx – Mike Mengell Mar 23 '11 at 13:43
2

Use powershell to execute command remotely on the server:

Invoke-Command -ComputerName <YOUR_IIS_SERVER_NAME> -ScriptBlock { Restart-WebAppPool -Name <YOUR_APP_POOL_NAME> }
Michael
  • 791
  • 9
  • 9
1

Have you got the IIS7 WMI Provider installed and enabled on the remote machine?

I think this doc covers most of what you need.

this covers pre req and how to browse the available management options...sure you'll be able to reset the app pool with a few tweaks...

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Mesh
  • 6,262
  • 5
  • 34
  • 53
1

I just tried it from a Windows XP machine to Windows 2008R2 machine. It worked. So you are definitely on the right track.

If you are looking for an alternative way, try this from a command prompt. At least the error message will be a little more specific, when it doesn't work.

wmic /namespace:"\\root\MicrosoftIISv2" /node:"**serverName**" path IISApplicationPool where (name like '%**DefaultAppPool**%') call recycle
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Naraen
  • 3,240
  • 2
  • 22
  • 20
0

I just stumbled upon this problem, and here's the fix: There is a small windows tool called PsExec, which basically gives you command line remote access, and from there you can use apppool. You can just run this command from C#

psexec \\192.168.xx.xx %windir%\system32\inetsrv\appcmd recycle apppool /apppool.name:yourapppool

here's the tool: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

Dragos Bobolea
  • 772
  • 7
  • 16
  • PsExec may be considered a security vulnerability by some company system administrators. Get permission before running it on company equipment. – ErikE Oct 10 '14 at 08:55
0

Following commands worked for me after trying everything !

cd %windir%\system32\inetsrv

appcmd.exe stop site /site.name:"test1.com"

appcmd.exe start site /site.name:"test1.com"

Obviously before these, you will run some ssh remote command as well