Solved

How to delete a shared windows DLL

Posted on 1998-10-04
9
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:inter
ID: 1341673
Yes, combine the info we supplied and windows automatically handles the rest.
0
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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