I recently spent hours looking for a solution to a strange problem I had in my custom user-drawn control when using the DrawImage method, and I thought I'd share my misery and hopefully keep you from wasting your time figuring this out as well. What was happening was that using images that were not 96 dpi were scaled wrong using the DrawImage method in C# (I also tried using the DrawImageUnscaled methods to no avail). I figured that the DrawImage method should account for the different screen resolutions and I wouln't have too, but it turns out that there is a SetResolution method on the Image (Bitmap object). So I delved further on how to get the system's resolution (or dots per inch, dpi) from .NET and I ran across this page:
How to: Handle Orientation and Resolution Changes that talks about the Microsoft .NET Compact framework, but there was a very interesting tidbit near the bottom of the page:
"If your application contains graphics that are drawn in the OnPaint method, they will not scale automatically. You will need to use the DpiX and DpiY properties of your Graphics objects to determine appropriate scaling."
That was all I needed, one line in my OnPaint method and my images are now scaled properly:
(g is my Graphics object)
this.myBitmap.SetResolution(g.DpiX, g.DpiY);
It's amazing how long it takes to find the answer to questions when you don't know how to ask google for them!
Sunday, July 30, 2006
Monday, July 24, 2006
Moving Local User Profiles to Domain and MSI Install/Uninstall Nightmares
We just got through moving most of our Windows XP computers here at work onto a new MS Exchange Server with Active Directory, Domain, etc...
One major headache was actually moving the user profiles over from a local user to a domain user.
Since you can't just change an existing local user to a domain user, you have to go through major hoops and cross your fingers everything will work with your new user (or just do a complete reinstall/reformat of windows which is not all that fun).
The first thing we did was move the computer onto the domain by using the System window available from the control panel or by rightclicking My Computer and clicking properties.
On the computer name tab, click "Change" and change from "Member of" workgroup to your new domain server.
Once you've switched over to the Domain, next comes the tricky part, actually making the new user, ensuring correct permissions are set, and copying the profile from the old local profile to the new domain profile.
To create the new Domain profile on your machine, all you need to do is log off from your local user and login to your Domain account using your username and password that is on the Domain Controller and selecting the domain from the login prompt.
After you've sucessfully logged in as your new domain user, log back out and login as the Administrator account for your system. Right click on My computer and click the Manage button to bring up the Computer Management window, click on Local Users and Groups, then the Groups subfolder, then right click on the Administrators group and you should make sure that both the old local user and the new domain users are in the Administrator group. Also ensure that the folders under C:\Documents and Settings\ and C:\Documents and Settings\ have full control for administrators (you may have to disable simple file sharing to modify these security settings in XP by clicking tools -> Folder options -> View Tab, then uncheck the last checkbox in the list labeled Advanced.
Once you've gotten all the security/permissions setup it's time to actually do the copy, I would recommend a full shutdown and reboot because you never know what files are still in use with windows, then sign in again as the Administrator once the system is back up.
Right click My Computer and click Properties to bring up the System window once again, click the Advanced tab, and then click the Settings button in the User Profile section to bring up the User Profile window, select the local profile you wish to copy from, click the Copy To button, and in the popup window select the new Domain user as the "Copy Profile to" profile, and I would also make sure the "Permitted to use" is set to Everyone.
If everything goes ok it will take a few minutes (depending on the size of the local profile) and your domain user will now have all the settings, desktop, registry entries, etc... that your old local profile had.
Sometimes this fails, especially if there are files in long pathnames under the C:\Documents and Settings\ directory, if it fails you have a couple of options, either remove those nasty long path files it errors on, or you can try a manual copy in windows explorer instead of using the "Copy Profile to" tools, but who knows what other registry settings, etc... you'd be missing if you do a manual copy in windows explorer so I'd recommend trying to use the Copy Profile tool if possible.
Even after this, the struggles with installed programs are not over, if you try to run a program that was installed just for the old local user instead of installed for all users with your new Domain User, you'll find the program will probably not run and windows will complain looking for the originally installed MSI file, which is a complete pain because who keeps the original MSI/Setup files they installed programs with? You'll also find trying to uninstall these programs will also fail through the Add/Remove Program files tool for the same reason. After lots of searching in the windows registry and trying to find the registry key that identifies the actual version installed so I could get the appropriate MSI file to correctly uninstall the corrupt program, I found that the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall key holds some interesting values such as UninstallString, however I couldn't figure out how that hash code related to the "Revision Number" in the Advanced Properties for the MSI file, or any other attribute. Finally, giving up, we found that if you try to uninstall from Add/Remove Programs, to remove it from the list (even if it fails) then reinstalling the program but selecting "All users" instead of "Just me" in the install options made the install go through sucessfully.
One major headache was actually moving the user profiles over from a local user to a domain user.
Since you can't just change an existing local user to a domain user, you have to go through major hoops and cross your fingers everything will work with your new user (or just do a complete reinstall/reformat of windows which is not all that fun).
The first thing we did was move the computer onto the domain by using the System window available from the control panel or by rightclicking My Computer and clicking properties.
On the computer name tab, click "Change" and change from "Member of" workgroup to your new domain server.
Once you've switched over to the Domain, next comes the tricky part, actually making the new user, ensuring correct permissions are set, and copying the profile from the old local profile to the new domain profile.
To create the new Domain profile on your machine, all you need to do is log off from your local user and login to your Domain account using your username and password that is on the Domain Controller and selecting the domain from the login prompt.
After you've sucessfully logged in as your new domain user, log back out and login as the Administrator account for your system. Right click on My computer and click the Manage button to bring up the Computer Management window, click on Local Users and Groups, then the Groups subfolder, then right click on the Administrators group and you should make sure that both the old local user and the new domain users are in the Administrator group. Also ensure that the folders under C:\Documents and Settings\
Once you've gotten all the security/permissions setup it's time to actually do the copy, I would recommend a full shutdown and reboot because you never know what files are still in use with windows, then sign in again as the Administrator once the system is back up.
Right click My Computer and click Properties to bring up the System window once again, click the Advanced tab, and then click the Settings button in the User Profile section to bring up the User Profile window, select the local profile you wish to copy from, click the Copy To button, and in the popup window select the new Domain user as the "Copy Profile to" profile, and I would also make sure the "Permitted to use" is set to Everyone.
If everything goes ok it will take a few minutes (depending on the size of the local profile) and your domain user will now have all the settings, desktop, registry entries, etc... that your old local profile had.
Sometimes this fails, especially if there are files in long pathnames under the C:\Documents and Settings\ directory, if it fails you have a couple of options, either remove those nasty long path files it errors on, or you can try a manual copy in windows explorer instead of using the "Copy Profile to" tools, but who knows what other registry settings, etc... you'd be missing if you do a manual copy in windows explorer so I'd recommend trying to use the Copy Profile tool if possible.
Even after this, the struggles with installed programs are not over, if you try to run a program that was installed just for the old local user instead of installed for all users with your new Domain User, you'll find the program will probably not run and windows will complain looking for the originally installed MSI file, which is a complete pain because who keeps the original MSI/Setup files they installed programs with? You'll also find trying to uninstall these programs will also fail through the Add/Remove Program files tool for the same reason. After lots of searching in the windows registry and trying to find the registry key that identifies the actual version installed so I could get the appropriate MSI file to correctly uninstall the corrupt program, I found that the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall key holds some interesting values such as UninstallString, however I couldn't figure out how that hash code related to the "Revision Number" in the Advanced Properties for the MSI file, or any other attribute. Finally, giving up, we found that if you try to uninstall from Add/Remove Programs, to remove it from the list (even if it fails) then reinstalling the program but selecting "All users" instead of "Just me" in the install options made the install go through sucessfully.
Subscribe to:
Posts (Atom)
