cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jason_mardell
Level 3

using static .Net functions

Please can someone advise me if, and if so, how to call a static .Net method from installscript?

I want to use Dns.GetHostName();

I presume the DotNetCoCreateObject does what is says and creates an object so wouldn't work in this case?

I'm guessing I'll have to wrap the call in one of my own .net objects

Thanks
Labels (1)
0 Kudos
2 Replies
SimonG
Level 5

Com does not allow static methods to be called so the method you call from InstallScript will need to be non-static.
http://msdn.microsoft.com/en-us/library/ms182198.aspx
0 Kudos
sdnelson
Level 5

First you compile your class as a DLL with COM visible.

If you are using a .NET class you should be able to use DotNetCoCreateObject to create an object within your installscript.

If it is C or C++ then you will need to load it with UseDLL(someFile.DLL), then call the method, and then UnUseDLL(someFile.DLL). You also need to prototype the methods in your script.

example:
prototype stdcall void ClassName.MethodName(BYREF WSTRING);



If all you want is to get the host name of the machine you can do this without any custom libraries.
There are a couple ways to do this from installscript:

1. Use the environment variable
GetEnvVar("COMPUTERNAME", szHost);


Or
2. Get the value from the registry
RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
szKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters";
RegDBGetKeyValueEx(szKey,"Hostname", nType, szHost, nSize);


If you need the fully qualified host.domain value you can also get the domain from the same key
RegDBGetKeyValueEx(szKey,"Domain", nType, szDomain, nSize);


Then append the domain to the host name only if it actually has a domain value:
if (szDomain != "") then
szFQDN = szHost + "." + szDomain;
else
szFQDN = szHost;
endif;
0 Kudos