By Ken Huysmans on
2005-02-18T11:27:59
One day you might encounter a user who has done some cleaning (thouroughly) on his PC. Your program crashes because it can't find some necessary files...
A reinstall will do the trick, but there's a more user-friendly way to cope with 'deleters'.
I'm going to use images in my example, but you could do this with every file you want (since you'll be getting a Stream).
Add an image to your project and make sure to put the Build Action to Embedded Resource.
Now here's some code to retrieve the image, the function GetEmbeddedImagePath() will return the filename, the function GetEmbeddedImage() will return an Image object. They both need 1 parameter, the name of the image you want to retrieve.
Public Shared Function GetEmbeddedImagePath(ByVal imageName As String) As String
Dim f, fn As String
f = Application.StartupPath
If Not f.EndsWith("\") Then f &= "\"
f &= "Images\"
fn = f & imageName
If File.Exists(fn) Then
Return fn
Else
If Not Directory.Exists(f) Then
Directory.CreateDirectory(f)
End If...
Read More »
|
By Ken Huysmans on
2004-11-28T13:51:37
This is a question I received a while ago. After an upgrade to Windows XP SP2 the 'My Documents' folder always opened when Windows was started.
I ran msconfig, but couldn't find anything suspicious... After a while I found out there was something wrong with the 'userinit'-key in the registry.
The value of this key (HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\UserInit) was C:\WINDOWS\system32\userinit.exe,C:\WINDOWS\system32\userinit.exe.
Changing this key to only C:\WINDOWS\system32\userinit.exe solved the problem.
|
By Ken Huysmans on
2004-11-25T11:02:00
If you have a picture as background of your MDI, that picture is not resized when you resize your form. There seems no easy way (like a property) to accomplish this.
So I wrote a little piece of code that will create a new image starting from the original background image, but with the dimensions of the main form.
Declare a global variable for your form:
Private myBackground As Image
Add this code to the Resize-event of your form:
If myBackground Is Nothing Then
myBackground = Me.BackgroundImage
End If
If Me.ClientSize.Width = 0 Then Exit Sub 'Remark1
Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, Imaging.PixelFormat.Format24bppRgb) 'Remark2
Dim gr As Graphics = Graphics.FromImage(bmp)
gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
gr.DrawImage(myBackground, 0, 0, bmp.Width, bmp.Height)
Me.BackgroundImage = bmp
If you have a statusbar (called myStatus in this example) on the bottom of your form, alter the line marked with 'Remark1...
Read More »
|
By Ken Huysmans on
2004-09-28T10:52:16
If you want to delete an assembly in the GAC that's still in use, you'll get the message:
Assembly 'XXXXXXXXXXX' could not be uninstalled because it is required by other applications.
If you have stopped all services and still don't succeed in removing it, try this little trick.
- Go to Start > Run
- Type regsvr32 -u "C:\Windows\Microsoft.NET\Framework\v1.1.4322\shfusion.dll"
- Browse to C:\Windows\Assembly, the 'GAC-view' has gone
- Open the GAC-folder
- Delete the folder with the name of the assembly you want to remove
- Go to Start > Run
- Type regsvr32 "C:\Windows\Microsoft.NET\Framework\v1.1.4322\shfusion.dll"
Warning: I take no responsability at all, try it at your own risk!
...
Read More »
|
By Ken Huysmans on
2004-08-27T08:35:26
If you want to close the main browser window, Internet Explorer will popup this messagebox:
"The Web page you are viewing is trying to close the window.
Do you want to close this window?"
Internet Explorer is checking the window.opener object to see if the current window has been opened by another window. If not, it will display this question.
So, the little trick is to make sure that the window.opener object differs from undefined ;-)
<script language="javascript">
function CloseWindow() {
window.opener = 'http://kHSw.blogspot.com';
window.close();
}
</script>
|
By Ken Huysmans on
2004-08-21T10:50:50
Don't you hate it when a program just reboots Windows without asking after an installation? I do.
Today I found a little program on the web that will prevent this shutdown. It's called Anti-Shutdown by xCAT-Industries. The program itself can be downloaded from http://www.xcat-industries.nl/softwareinfo.php?software=37.
|
By Ken Huysmans on
2004-08-05T07:49:50
When a customer gets a messagebox (for example an errormessage), they mostly take a printscreen, copy this bitmap in a Word-document and send it to my already overloaded mailbox.
Those customers who do think about my mailbox size, are manually typing the text from the messagebox in an email.
It's much easier to just copy the text of the messagebox to the clipboard by pressing <Ctrl>-<C>.
You'll get something like this (an example coming from the Database Configuration Application of Microsoft Content Management Server):
---------------------------Stop service?---------------------------In order to continue, the IIS service and all dependent services must be stopped. Do you want to stop IIS now? Answering No will exit this program.---------------------------Yes No ---------------------------
|
By Ken Huysmans on
2004-08-04T17:50:08
This is one of the Stored Procedures I use frequently:
CREATE PROCEDURE sp_kill_database_users @arg_dbname sysname with recompile
AS
-- kills all the users in a particular database
-- dlhatheway/3M, 11-Jun-2000
declare @a_spid smallint
declare @msg varchar(255)
declare @a_dbid int
select @a_dbid = sdb.dbid
from master..sysdatabases sdb
where sdb.name = @arg_dbname
declare db_users insensitive cursor for
select
sp.spid
from master..sysprocesses sp
where sp.dbid = @a_dbid
open db_users
fetch next from db_users into @a_spid
while @@fetch_status = 0
begin
select @msg = 'kill '+convert(char(5),@a_spid)
print @msg
execute (@msg)
fetch next from db_users into @a_spid
end
close db_users
deallocate db_users
GO
...
Read More »
|