PDA

View Full Version : Plugin: LuaCOM


Brett
01-31-2005, 09:55 PM
I have recently updated the LuaCOM plugin which works for Setup Factory 7.0 as well as AutoPlay Media Studio 5.0 and TrueUpdate 2.0.

LuaCOM is an add-on library to the Lua language that allows Lua programs to use and implement objects that follow Microsoft's Component Object Model (COM) specification and use the ActiveX technology for property access and method calls.

Basically, LuaCOM allows you to access COM (a.k.a. ActiveX objects) objects from your projects. It also allows you to expose COM interfaces from your applications. This means that you can do things like creating and manipulating Microsoft Word documents and many other programs and technologies that expose COM interfaces.

LuaCOM Plugin Homepage (http://www.icynorth.com/luacom/index.html)

aniketb78
08-04-2005, 10:18 AM
I couldn't find any good examples of the usage of this plugin for SF7 and so after some trial and error and reading of documentation, here is what I came up with. The Code below checks to see of the SQL Server Service is installed and running and uses the SQLDMO COM Object to do this. Hope this helps someone looking for an example.

local liServerRunning = Service.Query("MSSQLSERVER","");
local llInstalledSQLServer = false;
if liServerRunning == 0 then
-- Install service or exit
local lcParameters = "SAPWD=" .. SessionVar.Expand("%SAPwd%") .. "/settings=" .. String.Char(34) .. "setup.ini" .. String.Char(34);
File.Run(SessionVar.Expand("%SourceFolder%\\MSDE\\setup.exe"), lcParameters, SessionVar.Expand("%SourceFolder%\\MSDE"), SW_SHOWNORMAL, true);
llInstalledSQLServer = true;
end

local liServerRunning = Service.Query("MSSQLSERVER","");
if liServerRunning == 1 then
-- SQL Server Service Stopped (need to restart)
Service.Start("MSSQLSERVER", "", nil);
if Application.GetLastError() > 0 then
Application.Exit(-1);
end
elseif liServerRunning ~= 4 then
Debug.Print("Error\r\n");
Debug.Print(liServerRunning);
if Dialog.Message("Error", "Please Ensure That The MSSQLSERVER Service Is Running.", MB_RETRYCANCEL, MB_ICONEXCLAMATION) == 2 then
Application.Exit(-1);
else
liServerRunning = Service.Query("MSSQLSERVER","");
if liServerRunning ~= 4 then
Application.Exit(-1);
end
end
end


sqlserver = luacom.CreateObject("SQLDMO.SQLServer");
assert(sqlserver);
sqlserver.LoginSecure = true;
sqlserver:Connect();
local llChangedAuthMode = false;
if llInstalledSQLServer then
sqlserver.IntegratedSecurity.SecurityMode = 2;
llChangedAuthMode = true;
else
local lnSecurityMode = sqlserver.IntegratedSecurity.SecurityMode;
if lnSecurityMode ~= 2 then
if Dialog.Message("Server Error", "Would you like to switch SQL Server to use Mixed Mode Authentication?", MB_YESNO, MB_ICONEXCLAMATION) == 6 then
sqlserver.IntegratedSecurity.SecurityMode = 2;
llChangedAuthMode = true;
else
Application.Exit(-1);
end
end
end

sqlserver:Close();
sqlserver = nil;
collectgarbage();

if Application.GetLastError() > 0 then
Application.Exit(-1);
end