Solved

To  stop and start IIS in VB script

Posted on 2002-04-25
17
435 Views
Last Modified: 2011-10-03

 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
Comment
Question by:misha1
  • 7
  • 6
  • 3
  • +1
17 Comments
 
LVL 1

Expert Comment

by:procyn00
ID: 6969023
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6969357
procyn00,

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

Anthony
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6969371
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
 
LVL 1

Author Comment

by:misha1
ID: 6969709

 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
 
LVL 28

Expert Comment

by:AzraSound
ID: 6969718
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
 
LVL 1

Author Comment

by:misha1
ID: 6969755

 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
 
LVL 28

Accepted Solution

by:
AzraSound earned 75 total points
ID: 6969774
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
 
LVL 1

Author Comment

by:misha1
ID: 6969787

 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 28

Expert Comment

by:AzraSound
ID: 6969801
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
 
LVL 1

Author Comment

by:misha1
ID: 6969809

 Thanks,
 Will try it.
0
 
LVL 1

Author Comment

by:misha1
ID: 6969896

 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
 
LVL 28

Expert Comment

by:AzraSound
ID: 6969926
Try this:

Shell "cmd.exe /c Net stop iisadmin /y"
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6969998
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6970000
Oops, I think Azra just beat me to it.

Anthony
0
 
LVL 1

Author Comment

by:misha1
ID: 6971578

 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
 
LVL 28

Expert Comment

by:AzraSound
ID: 6971807
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
 
LVL 1

Author Comment

by:misha1
ID: 6977832

 
 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now