Editing INI Files through COM. With some server software it would be handy for an administrator to be able to modify .ini files on the file via a web browser. This demonstration shows you how to do just that via COM API calls. This is a very basic implementation as is intended to get you started on exposing windows API calls via COM.
Regarding security. Some of the API calls would be very dangerous to expose on the internet because the effect the server which the COM is actually registered on. Thus you are opening up that machine to the internet. Also, some of the actions which the COM needs to perform with the API may require the use of a more priveledged user, other than the IUSER_MACHINENAME (anonymous internet user). The easiest way to get aroundt this problem would be to create another account on the machine, and give it the proper permissions. Then use MMC to add the COM to component services on Windows 2000 or Microsoft Transaction Server in Windows NT, and then, in the package that you create, allow the object to use the credentials of the new user you created.
COMFirst lets take a look at the COM portion. If you need more help understanding COM please refer to our resource on COM. We we need to expose the ini API declarations. Here is the VB code. Rem *************************************** Rem *** Windows API/Global Declarations *** Rem ***************************************
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Now we will have to expose the API global declaration in the COM environment through Public worker routines. Rem *************************************** Rem *** Public Worker Routines *** Rem ***************************************
Public Function ReadIni(sSectHeader As String, sVarName As String, sFileName As String) As String Dim strReturn As String strReturn = String(255, Chr(0)) ReadIni = Left$(strReturn, GetPrivateProfileString(sSectHeader, ByVal sVarName, "", strReturn, Len(strReturn), sFileName)) End Function
Public Function WriteIni(sSectHeader As String, sVarName As String, sValue As String, sFileName As String) As Integer WriteIni = WritePrivateProfileString(sSectHeader, sVarName, sValue, sFileName) End Function
Thats it for the object itself. Notice all we are doing is providing public functions to directly use the API functions. Once you have compiled the VB code and registered the DLL on your machine (Using MMC, or regsvr32), you are ready to move on to the ASP portion.
ASPThis is where we will implement the web interface for the above declared object. Review the code within iniEditor.index.asp. Some of the key lines are: set oIniEditor = server.createobject("iniEditor.ini")
This creates an instance of the iniEditor object so that we can use its public methods. msg = "Read Return Value: " & oIniEditor.ReadIni(cstr(sect),cstr(var),cstr(filename))
A call to the COM's ReadIni exposed method. We pass in the FORM parameters, and get the return value, which is the value associated with that particular variable of the ini file.
ConclusionWith this simple demo I have shown you how you can enable full INI editing from with your ASP page. I have also shown you how to expose server sided API's on the net.
Hope this helps and if you have any questions feel free and contact me any time. Robert Chartier
|
|
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
| | | | Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
| | | | CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
| | | | Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
| | | | Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
| | | | Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity. FREE! Go There Now!
| | | | Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development. FREE! Go There Now!
| | | | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |