Solved

How to delete a shared windows DLL

Posted on 1998-10-04
9
175 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 207
delphi custom sort exception 6 136
Delphi XE2 application frozen on Windows 10 10 277
Base1 Encode/Decode 3 68
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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

19 Experts available now in Live!

Get 1:1 Help Now