Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

To stop and start IIS in VB script


 Hello guys and gals.
 I have a little simple script from MSDN
 to stop and start IIS (Internet Info Service).
 ------------------------------------------
 Net stop iisadmin /y
 Net start iisadmin
 -------------------------------------------

 Now I need to wrap it in VB script code, so
 to put on HTML page.
 
 Thanks.
 
0
misha1
Asked:
misha1
  • 7
  • 6
  • 3
  • +1
1 Solution
 
procyn00Commented:
Ok.... heres a dumb question.

How are you going to execute a VB script code on a page if the page can't be served cause the servers stopped.
0
 
Anthony PerkinsCommented:
procyn00,

I think the questioner is asking about vbs not ASP.  You can run vbs files without IIS.

Anthony
0
 
AzraSoundCommented:
This is just a command line call, yes?  You should be able to execute it using the WScript.Shell class' Run method:

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/wsh/htm/wsMthRun.asp
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
misha1Author Commented:

 So, as I understand,
 I would not embbed this in VB Script but
 would run an notepad with this code.
 
 Is there a way to embed this in code itself?
 
 
0
 
AzraSoundCommented:
If you mean you want to run this from a regular VB program, then you should look into just using the Shell function to run that command line call.
0
 
misha1Author Commented:

 As I understand Shell runs only executables
 and can't run command lines,
 from MSDN:
 
 "Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero"
 
 I have few line commands that I have to execute.

0
 
AzraSoundCommented:
Well, the program that you would run is the command prompt (command.exe) and pass it the command line you wish to run.  So it could look like this, for example:

Shell "cmd.exe Net stop iisadmin /y"
Shell "cmd.exe Net start iisadmin"
0
 
misha1Author Commented:

 Thanks,
 That's more in line with what I want.
 Now, do you know what command prompt (cmd.exe)
 I would use for this IIS? This cmd.exe or the like
 has to exist there.
 
 Can you give me the exact code to run in this instance?
 
 
 
 
 
0
 
AzraSoundCommented:
I'm not on my IIS machine right now, but what I posted above should work (at least it looks right to me).  I know for Win2k you will use cmd.exe and then the command line string to pass to it.  If you get an error like "File Not Found", it is probably not finding cmd.exe...it may be command.exe for that machine.  Or, you may need to put the fully qualified path (e.g., C:\WINNT\System32\cmd.exe) but I dont think you should have to.
0
 
misha1Author Commented:

 Thanks,
 Will try it.
0
 
misha1Author Commented:

 Tried it out.
 The code runs good, finds cmd.exe, but
 IIS was not stoped, tried just the "stop" command.
 
 Can you try this code on your IIS when you have a chance.
 Will increase points to 75.
 
 Thanks.
0
 
AzraSoundCommented:
Try this:

Shell "cmd.exe /c Net stop iisadmin /y"
0
 
Anthony PerkinsCommented:
There are better ways of skinning this cat, but just to show you one way:

Create a text file in the root of C:\ with the following line:
MsgBox "You got it!"

and name the file: virus.vbs

Then add the following line:

Shell "cmd /c c:\virus.vbs"

Of course you will have to use Command instead oc Cmd if this is Windows 9.x, but you get the picture.

Anthony




0
 
Anthony PerkinsCommented:
Oops, I think Azra just beat me to it.

Anthony
0
 
misha1Author Commented:

 Thanks guys,
 Stopping IIS worked fine,
 but when I added 'start' line, it didn't work.
 
 I've added:
 Shell "cmd.exe /c Net start iisadmin"

 Looks good, but didn't start IIS, it remained stopped.
 Also noticed that IIS stops for about 5 to 10 seconds.
 So maybe code is too fast for it?
 
 Misha1.
 
 
0
 
AzraSoundCommented:
That is possible...you can use some more complex code to determine when a Shelled application finishes, so then you could call your next line.  Here are a couple of samples:


"Determining the End of a Shelled Application Using GetExitCodeProcess"
http://www.mvps.org/vbnet/index.html?http://www.mvps.org/vbnet/faq/main/getexitcprocess.htm

"Determining the End of a Shelled Application Using WaitForSingleObject"
http://www.mvps.org/vbnet/index.html?http://www.mvps.org/vbnet/faq/main/waitforsingleobject2.htm
0
 
misha1Author Commented:

 
 We are making lots of progress.
 Tried event handling code from the links, works fine.
 Now Start command line waits for Stop command line to finish.
 But when Start command line starts, it opens Command
 Progress Window, displays "Starting IIS", but then
 closes everything and IIS remains stopped.
 So, in other words, it starts "Start" process and then
 aborts it.
 
 Can you try it on your IIS.
 
 Thanks.
 
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!

  • 7
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now