Solved

How to delete a shared windows DLL

Posted on 1998-10-04
9
174 Views
Last Modified: 2010-04-06
I want to replace an older DLL ( comctl32.dll ) with a new version with my own setup program. When I try to replace this file an error occured : Sharing violation. Is there any solution to erase shared DLL or even make it non-shared ?

Motaz from Sudan.
motaz1@yahoo.com
0
Comment
Question by:Motaz
  • 4
  • 3
  • 2
9 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 20 total points
ID: 1341670
I think this DLL is in use by another (or by some other) process(es). So you just can't delete or replace this file on the fly. You cannot change the share mode, either. What you can do is what every setup program does: Restart Windows and make Windows replace this DLL right after the restart.

Win95:
Create/Edit the file "c:\windows\wininit.ini". Add this:
   [Rename]
   c:\windows\comctl32.dll=c:\windows\comctl32.$$$

WinNT:
MoveFileEx('c:\windows\comctl32.dll','c:\windows\commctl32.$$$',MOVEFILE_DELAY_UNTIL_REBOOT or MOVEFILE_REPLACE_EXISTING);

Win95/WinNT:
Now copy the new DLL version to "c:\windows\comctl32.$$$" and restart Windows (using ExitWindowsEx).

Regards, Madshi.
0
 
LVL 5

Expert Comment

by:inter
ID: 1341671
You are faster man ;-) here is my contribution

Yes you can,
however you should restart the windows in order your DLL be copied succesfully. Because every body uses comctl32(even windows shell) it is not advisable to kill those processes and copy comctl32. So it can be done with the following API but different for Win95 and NT

FOR NT:
-------------

 MoveFileEx('c:\temp\myinstall\comctl32.dll','c:\winnt\system32\comctl32.dll',
    LPCTSTR lpNewFileName,      // address of new name for the file
    MOVEFILE_DELAY_UNTIL_REBOOT );

FOR 95+
---------------

procedure MoveFileEx95(src, dest : string);
var
  inif : array[0..255] of char;
  inif : array[0..255] of char;
begin
  GetWindowsDirectory(szWinInitFile, uSize);
  StrCat(inif, '\WININIT.INI');
  WritePrivateProfileString('Rename', 'NUL', PChar(dest), inif);
  WritePrivateProfileString('Rename', dest, src, inif);
end;
//do not forgetto reboot! You can do this with the following API call

ExitWindowsEx(EWX_REBOOT, 0);

regards, igor
0
 
LVL 7

Author Comment

by:Motaz
ID: 1341672
Thanks all of you. A very nice solution... but need some clearifications :

-[Rename] not exist in Win.ini.. Must I add it ?.. and what happend if it is already exist?
- Is it posible to append win.ini.. no error will occure if I try to do so ?..
- After that did the windows remove this lines from win.ini after finishing this task ?

Thanks for your help.
Motaz
0
 
LVL 5

Expert Comment

by:inter
ID: 1341673
Yes, combine the info we supplied and windows automatically handles the rest.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Author Comment

by:Motaz
ID: 1341674
Inter, you don't mention the file name which I must replace ?
0
 
LVL 5

Expert Comment

by:inter
ID: 1341675
You are right,
for WinNT do exactly what Madshi wrote, for Win95 call my proc

MoveFileEx95('source file name','dest file name'); and reboot.

I strongly recomend you to test those on a dummy file. For example create a file called x.dat on c:\ and replace it with the above method. Once succesful you try the actual replacement. In addition if in MoveFileEx95 proc NUL does not work try NULL instead.
regards, igor
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1341676
Hi Igor. I thought you wanted to call me "madshi" instead of "Madshi"!?  :-)

Motaz, ATTENTION!!!!!! It is NOT "Win.ini", but "WinInit.ini"!!!
The file "WinInit.ini" is handled from Windows at startup and then renamed to "WinInit.bak".

BTW, I think you don't need to delete the old file before replacing it. At least I don't do this in my programs...
Also you don't need to give in the windows path to WritePrivateProfileString. So I think you can shorten igor's nice procedure like the following:

procedure MoveFileEx95(src, dest: string);
begin
  WritePrivateProfileString('Rename', pchar(dest), pchar(src), 'WinInit.Ini');
end;

Regards, Madshi.
0
 
LVL 7

Author Comment

by:Motaz
ID: 1341677
Thanks Igor and Madshi... it did work.

Motaz
0
 
LVL 7

Author Comment

by:Motaz
ID: 1341678
Sorry I mean Inter and Madshi
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now