Solved

Start/Stop IIS 6 Services Programatically

Posted on 2004-03-24
6
2,407 Views
Last Modified: 2007-12-19
How to pragramatically start and stop IIS 6 (windows 2003) services in c++, especially the SMTP/NNTP services? Does the ADSI/WMI api have specific functions related to this?
0
Comment
Question by:bphanikumar
6 Comments
 
LVL 17

Expert Comment

by:Tacobell777
Comment Utility
NET STOP IISADMIN /Y

NET START IISADMIN

You can use NET STOP [service name] /Y for any service that is running, just replace [service name] with the name of the service, you find the name of the service by going to Services..
0
 

Author Comment

by:bphanikumar
Comment Utility
But I want to do that programatically using the ADSI/WMI APIs in c++. With IIS5 Microsoft delivers the scripts Startsrv.vbs and Stopsrv.vbs but in IIS6 these scripts are not delivered.

To be more specific, programatically find all the services available for IIS6, their current state and able to start & stop each service...
0
 
LVL 11

Expert Comment

by:Sven
Comment Utility
I am no C++ programmer, but in VB I programmed a tool which calls the Shell-API and does all work for me. Here are the important parts:

Option Explicit

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Private Sub ShellWait(ByVal CommandLine As String, Optional ByVal WindowStyle As VbAppWinStyle = vbHide)
   
    Dim hProcess As Long
    Dim RetVal As Long
   
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(CommandLine, WindowStyle))
   
    Do
        GetExitCodeProcess hProcess, RetVal
        DoEvents: Sleep 100
    Loop While RetVal = STILL_ACTIVE
   
End Sub

Private Sub Form_Load()

    ShellWait "NET STOP IISADMIN /Y"
    ShellWait "NET START IISADMIN"

End Sub
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Expert Comment

by:Ray
Comment Utility
0
 

Author Comment

by:bphanikumar
Comment Utility
Using WMI it's easy to configure IIS programmatically. WIM Studio gives extensive information about the classes to be used and other details.  But I can't use it for my application. Only ADSI to be used. Most of the sites explain using VBScript examples but rarely with C++/COM.  Like for the simple VBScript code shown below how do u write in C++,

        IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
        Set IIsObject = GetObject(IIsObjectPath)
        IIsObject.Stop

The code is picked from the adsutil.vbs file.
0
 
LVL 7

Accepted Solution

by:
Ray earned 25 total points
Comment Utility
0

Featured Post

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.

Join & Write a Comment

First of all, clustering IIS is something you should rarely consider doing. In almost all cases, Microsoft Network Load Balancing (NLB) (http://technet.microsoft.com/en-us/library/cc758834(WS.10).aspx) is a much better solution when you need to p…
Debug Tools to analyse IIS process: This article focus on taking memory dumps from IIS to determine which code is taking more time and to analyse which calls hangs/causes more CPU usage. To take dumps,download the following. Install1: To st…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

16 Experts available now in Live!

Get 1:1 Help Now