Using Microsoft.Web.Administration.dll in go

554 views
Skip to first unread message

Paul van Brouwershaven

unread,
Aug 24, 2013, 4:14:58 AM8/24/13
to golan...@googlegroups.com
For an application that is interacting with different webservers and platforms I now  need to interact with Microsoft IIS.

My goal is 'simple', retrieve a list of websites with a https binding, via golang.

After some googling it looks like I need to use the Microsoft.Web.Administration.dll that provides some classes that would allow me todo the job:

The Microsoft.Web.Administration namespace contains classes that a developer can use to administer IIS Manager. With the classes in this namespace, an administrator can read and write configuration information to ApplicationHost.config, Web.config, and Administration.config files.
 
The classes in the Microsoft.Web.Administration namespace contain a series of convenient top-level objects that allow the developer to perform administrative tasks. The different logical objects available include sites, applications, application pools, application domains, virtual directories, and worker processes. You can use the API to obtain and work with the configuration and state of these objects and to perform such actions as creating a site, starting or stopping a site, deleting an application pool, recycling an application pool, and even unloading application domains.

The namespace documentation on the msdn website:

And some (old) usage examples:

Now would it be a few minutes work to build something like this in the by Microsoft supported languages but I hope someone could help me started in golang as I can't find a lot of documentation or examples for this (besides w32 wrapper that looks really good!).

Loading the ddl is simple and completes successfully:
mwadmin = syscall.MustLoadDLL("c:\\Windows\\System32\\inetsrv\\Microsoft.Web.Administration.dll")

But then I need to find a procedure:
mwadminSite = mwadmin.MustFindProc("SiteCollection")

Which always results in an error like this:
panic: Failed to find Microsoft.Web.Administration procedure in c:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll: The specified procedure could not be found.

Now I think that I can't load a class as a procedure... but how can I use this .dll then as I can't find any other way to get started with a dll file by linking a procedure with MustFindProc, FindProc or Find in combination with the NewLazyDLL delayed loading.

My full example code :-)

package main

import (
"syscall"
)

var (
mwadmin       = syscall.MustLoadDLL("c:\\Windows\\System32\\inetsrv\\Microsoft.Web.Administration.dll")
mwadminSite   = mwadmin.MustFindProc("Microsoft.Web.Administration")
)

func main() {
}


Dave Cheney

unread,
Aug 24, 2013, 4:20:05 AM8/24/13
to Paul van Brouwershaven, golang-nuts
Silly question. Are you using a 64bit version of Go and trying to load
a 32bit dll ?
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Paul van Brouwershaven

unread,
Aug 24, 2013, 4:25:05 AM8/24/13
to golan...@googlegroups.com, Paul van Brouwershaven
On Saturday, 24 August 2013 10:20:05 UTC+2, Dave Cheney wrote:
Silly question. Are you using a 64bit version of Go and trying to load
a 32bit dll ?
 
Good comment!

In my example I have listed the 32 bit dll while I tested with both the 32bit and 64bit which are both giving me the same error message.

mwadmin   = syscall.MustLoadDLL("C:\\Windows\\SysWOW64\\inetsrv\\Microsoft.Web.Management.dll")
 

Rémy Oudompheng

unread,
Aug 24, 2013, 4:30:18 AM8/24/13
to Paul van Brouwershaven, golang-nuts
2013/8/24 Paul van Brouwershaven <pa...@vanbrouwershaven.com>:
I don't think you can expect C#/.NET libraries to have the same
interface as a usual C library. Do you know how to write a C program
using this ?

Rémy.

Paul van Brouwershaven

unread,
Aug 24, 2013, 4:35:31 AM8/24/13
to golan...@googlegroups.com
On Saturday, 24 August 2013 10:30:18 UTC+2, Rémy Oudompheng wrote:
I don't think you can expect C#/.NET libraries to have the same 
interface as a usual C library. Do you know how to write a C program
using this ?

I don't expect the same interface, my question is how I could get started to retrieve this information from this dll. It's normal that this would require more coding than with C#/.NET.

Shivakumar GN

unread,
Aug 24, 2013, 6:16:45 AM8/24/13
to Paul van Brouwershaven, golang-nuts
I have legacy C++ system having encode/decode & rpc code. To integrate new Go code into legacy system, I wrote C wrappers for existing C++ libraries. This I used within Go using cgo.
Similar approach should work for your case. Remy is likely suggesting this.

Rémy Oudompheng

unread,
Aug 24, 2013, 6:33:06 AM8/24/13
to Shivakumar GN, Paul van Brouwershaven, golang-nuts
2013/8/24 Shivakumar GN <shivak...@gmail.com>:
C++ libraries are native code, while .NET DLLs are bytecode that need
a CLR VM to be interpreted. Googling sems to indicate that you can
call into managed code from native code through a DllExport
annotation or via COM.

Rémy.
Reply all
Reply to author
Forward
0 new messages