Solved

Start/Stop IIS 6 Services Programatically

Posted on 2004-03-24
6
2,425 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
ID: 10674334
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
ID: 10674561
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
ID: 10675786
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 7

Expert Comment

by:Ray
ID: 10676951
0
 

Author Comment

by:bphanikumar
ID: 10687557
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
ID: 10688116
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Allow Local User to Log On FTP 8 66
Creating csr file for SSL 4 57
Reading the Web.Config using IIS 7.5? 4 52
Windows Server 2102 R2 - IIS 8.5 redirection assistance ? 7 37
Here are the symptoms: You start receiving calls from users that one of your legacy web apps isn't coming up, so you log into your IIS 5 server to check it out.  When you pull up the services, you notice that the WWW Publishing service isn't runn…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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