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

Sunday, December 14, 2008

replace notepad with notepad2

notepad2

replacenotepad2.bat
copy notepad2.exe C:\WINDOWS\notepad.exe
copy notepad2.exe C:\WINDOWS\system32\notepad.exe
copy notepad2.exe C:\WINDOWS\ServicePackFiles\i386\notepad.exe
copy notepad2.exe C:\WINDOWS\system32\dllcache\notepad.exe

Windows XP - how to turn off compressed folders

regsvr32 /u zipfldr.dll

Thursday, September 11, 2008

C++ : How to Launch a Background in Windows Program

In linux it is easy to launch a background process at the command line with ampersand.

./app_to_launch &

In windows there is no easy command line suffix which will launch your program in the background. However it is relatively easy to code one up. If you install Visual C++ Express 2005, and the Microsoft Platform SDK (see configuration below) just compile this application as BKLAUNCH.exe and you will soon be able launch apps in the background from batch files.

I created an empty win32 project named BKLAUNCH, no precompiled header, and compiled the following code.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <windows.h>
#include <shellapi.h>
#include <tchar.h>

int _tmain(int argc, _TCHAR* argv[])
{
if (argc!=2)
{
printf("Usage:\n");
printf(" BKLAUNCH.EXE [apptolaunch]\n");
printf(" BKLAUNCH.EXE notepad.exe\n");
exit(0);
}
ShellExecute(NULL, TEXT("open"), argv[1], NULL, NULL, SW_SHOW);
return 0;
}


Once BKLAUNCH has successfully compiled, place it in a folder that is in the PATH. Now, go to Start > Run > cmd.exe [OK], and enter the following:
BKLAUNCH notepad.exe

You will notice notepad.exe is launched in the background, perfect for batch files.

Troubleshooting
If you are like me and use default settings, look under
Project > Project Properties > Linker > Input > Additional Dependencies
it will will have only kernel32.lib. When you compile there will be linker errors.

Because of the #include <windows.h> and #include <shellapi.h>
you need to add the following to your Additional Dependencies
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib in order to resolve the linker errors.

Microsoft Platform SDK Config
In order to use the MS Platform SDK in Visual C++ Express 2005, you have make the platform SDK visible to the compiler.

Go to
Tools > Options > Projects and Solutions > VC++ Directories > Platform=Win32 > Show Directories for=include files
Add to the list,
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
(or wherever you installed the MS Platform SDK\Include)

Now, go to
Tools > Options > Projects and Solutions > VC++ Directories > Platform=Win32 > Show Directories for=library files
Add to the list,
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib
(or wherever you installed the MS Platform SDK\Lib)

Wednesday, August 01, 2007

C++: Set Registry Key Values

This piece of example code writes a key to the windows registry.

#include <windows.h>

int SetRegValue(char *key_name,char *key_word,char *b,int dwType,int s)
{
int j=0;

DWORD lpdwDisposition;
HKEY hKey;

j=RegCreateKeyEx(
HKEY_CURRENT_USER,
key_name,
0, /* reserved */
NULL, /* address of class string */
REG_OPTION_NON_VOLATILE, /* special options flag */
KEY_WRITE, /* desired security access */
NULL, /* address of key security structure */
&
hKey, /* address of buffer for opened handle */
&
lpdwDisposition /* address of disposition value buffer */
);

if (j==ERROR_SUCCESS)
{
RegSetValueEx(hKey, key_word, 0, dwType, (unsigned char *)b, s);
RegCloseKey(hKey);
}
return(j);
}

int main(int argc, char* argv[])
{
char val[100]="myusername";
SetRegValue("Software\\MySoft\\Settings","Username", val, REG_SZ, 100);
return 0;
}



source(s): http://msdn2.microsoft.com/en-us/library/ms724923.aspx
http://msdn2.microsoft.com/en-us/library/ms724875.aspx

Thursday, April 19, 2007

Windows: Nightly Defrag

It isn't that hard to set up a nightly defragmentation routine.

In Windows XP, go to Start Menu > Settings > Control Panel > Scheduled Tasks go through the wizard, selecting C:\Windows\System32\defrag.exe to run. At the end, in the advanced options make it run
C:\Windows\System32\defrag.exe c: -f
or D: or whatever your drive name is.

Microsoft provides documentation on the command line defrag:
defrag volume [-a] [-f][-v] [-?]
volume: The drive letter or a mount point of the volume to be defragmented
-a: Analyze only
-f: Forces defragmentation of the volume regardless of whether it needs to be defragmented or even if free space is low
-v: Verbose output
-?: Display the help text


source(s): http://support.microsoft.com/kb/283080

Tuesday, April 10, 2007

WINDOWS: Skip 'Open With Web Service' Window

When you try to open a file and you haven't set a handler for a file extension, a window pops up in XP saying:

"Windows cannot open this file:"
To open this file, Windows needs to know what program created it. Windows can go online to look it up automatically, or you can manually select from a list of programs on your computer.
What do you want to do?
- Use the Web service to find the appropriate program
- Select the program from a list


This is really irritating because no one would ever want to use 'the Web Service' anyway. BTW Microsoft, look up Web Service at wikipedia.

To skip that step, make a file with the following contents, and open it and the registry setting will be automatically imported into your system.

skipOpenWithWebService.reg
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
"InternetOpenWith"=dword:00000000


source(s): http://www.pctools.com/guides/registry/detail/1314/