Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Monday, January 13, 2014

Installing Windows 8 and customization

1. Use Windows 7 USB/DVD download tool to create a Windows bootable USB drive

2. If you want to create a Windows x64 bootable image, you need to run the Windows 7 USB/DVD download tool from a x64 Windows computer.

3. During the Windows 8 installation if you encounter error while installing \ copying files, and it’s at the same point (same percent), then the USB image is corrupted.

4. If doing Android dev. with Intel x86 Emulator Accelerator (HAXM), you must disable Hyper V in Windows.
disable: bcdedit /set hypervisorlaunchtype off
re-enable (restart): bcdedit /set hypervisorlaunchtype auto
5. For Samsung 840 Pro SSD: Install Samsung Magician
     http://www.samsung.com/global/business/semiconductor/samsungssd/downloads.html
It will start on each Windows start but it’s annoying it shows UAC. One solution is to remove it from startup

C:\users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
6. There are a number of SSD optimizations to be done
http://www.thessdreview.com/ssd-guides/optimization-guides/the-ssd-optimization-guide-ultimate-windows-8-edition/

7. Disable Windows Narrator. it’s annoying it starts anytime Windows Key + Enter are pressed.
http://enginecore.blogspot.ro/2013/09/disable-windows-narator.html
8. Make Word to minimize to tray: right click on tray icon and choose “Hide when minimized
9. Automatically user login
1. run netplwiz 
2. uncheck the “Users must enter a user name and password to use this computer”, click Apply
3. enter username and password
http://www.howtogeek.com/112919/how-to-make-your-windows-8-computer-logon-automatically/
10. Force Visual Studio always run as admin
http://stackoverflow.com/questions/12257110/can-you-force-visual-studio-to-always-run-as-an-administrator-in-windows-8

In Windows 8, you have to right-click devenv.exe and select "Troubleshoot compatibility".
  1. select "Troubleshoot program"
  2. check "The program requires additional permissions"
  3. click "Next", click "Test the program..."
  4. wait for the program to launch
  5. click "Next"
  6. select "Yes, save these settings for this program"
  7. click "Close"
11. On Windows 8, make sure you get the latest Intel x86 Emulator Accelerator (HAXM), At this moment, the one from Android SDK manager is buggy on Windows 8. 
http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager/
 

Monday, October 08, 2007

smallest EXEcutable

This is an interesting page discussing techniques to achieve the smallest EXE possible.

http://www.phreedom.org/solar/code/tinype/

More, it says that if you add an UNC path as a name of an imported DLL in an executable, Windows will download and execute that file !
the server needs to be a WebDAV server.

Sunday, July 15, 2007

Opening CHM Help files from Network or Internet

Due to a security patch Windows has restricted access to a CHM. More info here: http://support.microsoft.com/kb/896358.

The attached reg script fixes one of the 4 problems described in the KB. It works for most of the CHM files. Here is the file.


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
"MaxAllowedZone"=dword:00000004

Friday, May 19, 2006

registry tweaks

every now and then I need some Windows tweaks.
i''ll put here all the things i need.

here's the first ones:

make OutlookExpress independent from Messenger (restart: no)
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Outlook Express]
"Hide Messenger"=dword:00000002


Add 'Explore from here' to Windows folders(restart: no)
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Command]
@="CommandPrompt"
[HKEY_CLASSES_ROOT\Directory\shell\Command\command]
@="cmd.exe /k cd \"%1\""


matching file names each time you press TAB in cmd. works in XP but doesnt by default on Win2000
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command processor]
"CompletionChar"=dword:00000009

Monday, May 15, 2006

windows install date

useful when u need something unique from the PC and easy to get

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

installdate value

InstallDate
REG_DWORD
Time (in seconds) since 12:00 A.M, January 1, 1970

here's a VBS script which displays the info:

Dim WshShell, TimeStampSet WshShell = WScript.CreateObject("WScript.Shell")TimeStamp = WshShell.RegRead(_"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\installdate")WScript.Echo "Install date :" & _DateAdd("s", TimeStamp, DateSerial(1970, 1, 1))

Wednesday, March 01, 2006

process termination

Ive just looked to an interesting blog article talking about when a process terminates.
http://blog.kalmbachnet.de/?postid=65

It seem that there is a subtle difference between how a console application (the main() CRT function) and a Win32 application (WinMain) is handling the process termination.

if you have this:

DWORD WINAPI MyThread2(LPVOID)
{
while(true) { }
return 0;
}

#pragma comment(linker, "/entry:myMain")
int WINAPI myMain()
{
DWORD dwThreadId;
CloseHandle(CreateThread(NULL, 0, MyThread2, NULL, 0, &dwThreadId));
return 0;
}

the application is a windows application (using myMain entrypoint) and it run infinitely.

but a similar console application:

int t_main()
{
DWORD dwThreadId;
CloseHandle(CreateThread(NULL, 0, MyThread2, NULL, 0, &dwThreadId));
return 0;
}

will return immediately after the 'return 0;'

the difference is this one:

the console application uses CRT which, after the user code return from main, it calls ExitProcess which terminates the application.

it seems that when a thread terminates, Win OS internally calls EndThread. The EndThread internally looks if there is any other thread running in the process and calls TerminateThread(if there are any) or ExitProcess (if there isnt any).

hence, in a Win32 application, if any thread returns, internally EndThread is called and this in turn, if no other threads are still running, will call ExitProcess.

in a CRT app, when the main thread returns, ExitProcess is called directly.

Saturday, December 03, 2005

SuspendThread

as the msdn says SuspendThread is for debugging purposes and should not be used.
it may be tempting to use it to pause a worker thread for example but it might not be ok.
the worker thread can be in the middle of executing a CRT function which is thread safe, using sychronization.
if the worker thread is paused after the lock is done, trying to execute from another thread a CRT function, which uses the same syncronization access, might get to a deadlock.

Thursday, November 10, 2005

stuff to do on DLL_PROCESS_ATTACH

it is guaranteed you can call any Kernel32.dll function on the DLL_PROCESS_ATTACH.
Calling any other function from other library is not ok, as the DLLs may not be loaded at that time (although your code links with those libs).
more info can be found in the J. Richter book. and J.Robbins say some problem he had in the past with some thread work in DLL_PROCESS_ATTACH.

oversee CloseHandle

there are many WinAPI functions which create and return a HANDLE object, like CreateThread, CreateFile.
in windows header file, a HANDLE is defined like this
typedef void* HANDLE

doing a 'CloseHandle' more than it is needed on the same HANDLE value is as bad as doing 'delete' on the same pointer.
the docs say:
"CloseHandle invalidates the specified object handle, decrements the object's handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system."
so as long as the handle count is not zero, its logic of course to call CloseHandle.

there are few considerations with the HANDLE objects:
- some functions are not requiring to do CloseHandle on the their returned HANDLE object; so always, always read the docs; dont rely on the fact you are an experienced WinAPI programmer; the behaviour might be (it is !) different between functions (in fact you can find an example in the John Robbins book, Debugging Windows);
- doing a CloseHandle on an object which is invalid it may be disastrous;
Once, my CloseHandle hit a memory location where a CString was living;

Monday, November 07, 2005

multithreading issue

ok, here is my task:
i have a dialog (main thread) and i have a worker thread running which updates a progressbar on the GUI.
when i press the close button i want the main thread and the worker thread to end cleanly (i want tthe threads to be closed nicely, without any TerminateThread or anything)

now, the problem stay in the fact that when i signal (using an event or something) the worker thread to end and then wait for it to end (using WaitForSingleObject for example) it is possible that in this time the worker thread to send a message to the GUI to update the progressbar(using SendMessage). Now, some may say why that SendMessage is a mistake but maybe not.

I want to be sure that the GUI and worker are synchronized perfectly (i dont want to use PostMessage; in some situations, for example when a buffer is needed to be sent, PostMessage only will not work (the buffer needs to be available when the message arrive to the receiver queue), hence, for PostMessage, some queue mechanism might be needed, if a text buffer for example is sent.

I came across a simple solution:
AtlWaitWithMessageLoop
its a function which use MsgWaitForMultipleObjects and does the job (in fact you can use your own implementation instead)

the idea is that, the main thread needs to be still getting messages for processing but in the same time, it will wait till the given synchronization object becomes invalid (beacause we may have 2 statements which can wait to eachother, a deadlock may appear; we can have the WaitForSingleObject(hWorkerThread); from main thread and the SendMessage from the workerthread)


//
//Stop the 'LoadLogs' thread, if its runnning
//
void CLogPage::StopLoadLogsThread()
{

if(m_hThreadLoadLogs)
{
//thread is accessing the log-file using CFile and it must be stopped before deleting the log-file
//stop the thread and wait till thread is stopped
InterlockedExchange(&m_snRunThread, 0);
AtlWaitWithMessageLoop(m_hThreadLoadLogs);
}

}

shell api power

i've discovered some months ago that the shell libary shlwapi.dll has, beside some well known functions like SHBrowseForFolder also some tiny functions but very useful.
instead of writing your own functions why dont use those which already exist, especially if come from OS DLL's ?
u are sure they are working OK and also it may be faster then yours (applicatinos like Windows Explorer use the DLL already, hence the functions might already be loaded in the memory pages)

those functions stay mostly in so called "Shell Lightweight Utility Functions", and they are grouped in
String Functions,
Path Functions
Registry Functions
Color Palette Functions,
Miscellaneous

For example, i needed a function which gives a text formatted to display the size of a file like this:
100 MB
123 KB
...

this function already exists in shell lib, StrFormatByteSizeW Function or StrFormatByteSizeA Function

so I will always check out the shell functions whenever i have this kind of small tasks to do