-
파일 시스템 - Win32Platform/File(장치 IO) 2009. 2. 4. 17:36CreateFile()
DeleteFile()
CopyFile()
CreateHardLink()
MoveFile()
MoveFileEx()
MOVEFILE_COPY_ALLOWED
CreateDirectory()
RemoveDirectory()
SetCurrentDirectory()
GetCurrentDirectory()
FindfirstFile()
FtpFindFirstFile()
FindNextFile()
InternetFindNextFile()
FindClose()
GetFileInformationByHandle()
GetFileTime()
SetFileTime()
CompareFileTime()
FileTimeToSystemTime()
SystemTimeToFileTime()
FileTimeToLocalFileTime()
LocalFileTimeToFileTime()
GetFileType()
GetFileAttributes()
FILE_ATTRIBUTE_DIRECTORYSetFileAttributes()
GetFileSize()
LARGE_INTEGER FileSize;
FileSize.LowPart = GetFileSize(hInFile, &FileSize.HighPart);
if (FileSize.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) ReportError(_T(".."));
GetTempPath()
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
1. The path specified by the TMP environment variable.
2. The path specified by the TEMP environment variable.
3. The path specified by the USERPROFILE environment variable.
4. The Windows directory.
TCHAR lpTempPathBuffer[MAX_PATH];
DWORD dwRetVal = 0;
memset(lpTempPathBuffer, 0, sizeof lpTempPathBuffer);
dwRetVal = GetTempPath(MAX_PATH, // length of the buffer
lpTempPathBuffer); // buffer for path
if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
PrintError(TEXT("GetTempPath failed"));
return (2);
}
DeleteMountPoint()
GetVolumePathName()
GetVolumeNameForVolumeMountPoint()
GetLogicalDriveStrings()
GetSystemDirectory()
GetWindowsDirectory()
MakeSureDirectoryPathExists()
FindFirstChangeNotification()
FindCloseChangeNotification()
FindNextChangeNotification()
class CFaxWatchDlg : public CDialog
{
// {
static UINT ThreadFunc( LPVOID pParam );
void CreateMonitoringThread( void );
CEvent m_event;
CWinThread *m_pWinThread;
...
// }
// Construction
public:
CFaxWatchDlg(CWnd* pParent = NULL); // standard constructor
...
// Generated message map functions
//{{AFX_MSG(CFaxWatchDlg)
...
afx_msg void OnDestroy();
virtual void OnOK();
//}}AFX_MSG
// {
...
// }
DECLARE_MESSAGE_MAP()
};
class THREADINFO {
public:
CString strFolder;
HANDLE hEvent;
HWND hWnd;
BOOL bSubfolders;
const THREADINFO& operator=( const THREADINFO *pSrc ) {
strFolder = pSrc->strFolder;
hEvent = pSrc->hEvent;
hWnd = pSrc->hWnd;
bSubfolders = pSrc->bSubfolders;
return *this;
}
};
typedef THREADINFO *PTHREADINFO;
/* static */ UINT CFaxWatchDlg::ThreadFunc( LPVOID pParam )
{
THREADINFO ThreadInfo;
ThreadInfo = (PTHREADINFO) pParam;
delete (PTHREADINFO) pParam;
// get a handle to a file change notification object.
HANDLE hChange = FindFirstChangeNotification(ThreadInfo.strFolder,
ThreadInfo.bSubfolders,
FILE_NOTIFY_CHANGE_FILE_NAME);
if (INVALID_HANDLE_VALUE == hChange)
return 1;
HANDLE aHandles[2];
aHandles[0] = hChange;
aHandles[1] = ThreadInfo.hEvent;
// sleep until a file change notification wakes this thread or
// m_event becomes set indicating it's time for the thread to end.
BOOL bContinue = TRUE;
while (bContinue) {
if (WaitForMultipleObjects(2, aHandles, FALSE, INFINITE) - WAIT_OBJECT_0 == 0) {
...
FindNextChangeNotification(hChange);
} else // kill this thread (m_event became signaled).
bContinue = FALSE;
}
// close the file change notification handle
FindCloseChangeNotification(hChange);
return 0;
}
CFaxWatchDlg::CFaxWatchDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFaxWatchDlg::IDD, pParent)
{
...
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
// {
m_pWinThread = NULL;
...
// }
}
...
BEGIN_MESSAGE_MAP(CFaxWatchDlg, CDialog)
//{{AFX_MSG_MAP(CFaxWatchDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
...
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
BOOL CFaxWatchDlg::OnInitDialog()
{
...
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// {
m_pWinThread = NULL;
...
// }
return TRUE; // return TRUE unless you set the focus to a control
}
void CFaxWatchDlg::OnDestroy()
{
// {
if (m_pWinThread != NULL) {
// signal and wait for ThreadFunc() to end
m_event.SetEvent();
WaitForSingleObject(&m_event, INFINITE);
delete m_pWinThread;
}
...
// }
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void CFaxWatchDlg::OnOK()
{
// TODO: Add extra validation here
// {
...
CreateMonitoringThread();
// }
// CDialog::OnOK();
}
// }
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void CFaxWatchDlg::CreateMonitoringThread( void )
{
m_event.ResetEvent();
PTHREADINFO pThreadInfo = new THREADINFO;
pThreadInfo->hEvent = m_event.m_hObject;
pThreadInfo->hWnd = m_hWnd;
pThreadInfo->bSubfolders = (m_xbSubfolders.GetCheck() == BST_CHECKED);
m_ebFolder.GetWindowText(pThreadInfo->strFolder);
CWinThread* pWinThread = AfxBeginThread(ThreadFunc, pThreadInfo, THREAD_PRIORITY_IDLE);
pWinThread->m_bAutoDelete = FALSE;
m_pWinThread = pWinThread;
}
SHGetFolderPath()
SHGetSpecialFolderPath()
SHGetSpecialFolderLocation()
SHGetKnownFolderPath()
SHGetSpecialFolderLocation()
CSIDL_DESKTOP
#define CSIDL_DESKTOP 0x0000 // <desktop>
#define CSIDL_INTERNET 0x0001 // Internet Explorer (icon on desktop)
#define CSIDL_PROGRAMS 0x0002 // Start Menu\Programs
#define CSIDL_CONTROLS 0x0003 // My Computer\Control Panel
#define CSIDL_PRINTERS 0x0004 // My Computer\Printers
#define CSIDL_PERSONAL 0x0005 // My Documents
#define CSIDL_FAVORITES 0x0006 // <user name>\Favorites
#define CSIDL_STARTUP 0x0007 // Start Menu\Programs\Startup
#define CSIDL_RECENT 0x0008 // <user name>\Recent
#define CSIDL_SENDTO 0x0009 // <user name>\SendTo
#define CSIDL_BITBUCKET 0x000a // <desktop>\Recycle Bin
#define CSIDL_STARTMENU 0x000b // <user name>\Start Menu
#define CSIDL_MYDOCUMENTS CSIDL_PERSONAL // Personal was just a silly name for My Documents
#define CSIDL_MYMUSIC 0x000d // "My Music" folder
#define CSIDL_MYVIDEO 0x000e // "My Videos" folder
#define CSIDL_DESKTOPDIRECTORY 0x0010 // <user name>\Desktop
#define CSIDL_DRIVES 0x0011 // My Computer
#define CSIDL_NETWORK 0x0012 // Network Neighborhood (My Network Places)
#define CSIDL_NETHOOD 0x0013 // <user name>\nethood
#define CSIDL_FONTS 0x0014 // windows\fonts
#define CSIDL_TEMPLATES 0x0015
#define CSIDL_COMMON_STARTMENU 0x0016 // All Users\Start Menu
#define CSIDL_COMMON_PROGRAMS 0X0017 // All Users\Start Menu\Programs
#define CSIDL_COMMON_STARTUP 0x0018 // All Users\Startup
#define CSIDL_COMMON_DESKTOPDIRECTORY 0x0019 // All Users\Desktop
#define CSIDL_APPDATA 0x001a // <user name>\Application Data
#define CSIDL_PRINTHOOD 0x001b // <user name>\PrintHood
#ifndef CSIDL_LOCAL_APPDATA
#define CSIDL_LOCAL_APPDATA 0x001c // <user name>\Local Settings\Applicaiton Data (non roaming)
#endif // CSIDL_LOCAL_APPDATA
#define CSIDL_ALTSTARTUP 0x001d // non localized startup
#define CSIDL_COMMON_ALTSTARTUP 0x001e // non localized common startup
#define CSIDL_COMMON_FAVORITES 0x001f
#ifndef _SHFOLDER_H_
#define CSIDL_INTERNET_CACHE 0x0020
#define CSIDL_COOKIES 0x0021
#define CSIDL_HISTORY 0x0022
#define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data
#define CSIDL_WINDOWS 0x0024 // GetWindowsDirectory()
#define CSIDL_SYSTEM 0x0025 // GetSystemDirectory()
#define CSIDL_PROGRAM_FILES 0x0026 // C:\Program Files
#define CSIDL_MYPICTURES 0x0027 // C:\Program Files\My Pictures
#endif // _SHFOLDER_H_
#define CSIDL_PROFILE 0x0028 // USERPROFILE
#define CSIDL_SYSTEMX86 0x0029 // x86 system directory on RISC
#define CSIDL_PROGRAM_FILESX86 0x002a // x86 C:\Program Files on RISC
#ifndef _SHFOLDER_H_
#define CSIDL_PROGRAM_FILES_COMMON 0x002b // C:\Program Files\Common
#endif // _SHFOLDER_H_
#define CSIDL_PROGRAM_FILES_COMMONX86 0x002c // x86 Program Files\Common on RISC
#define CSIDL_COMMON_TEMPLATES 0x002d // All Users\Templates
#ifndef _SHFOLDER_H_
#define CSIDL_COMMON_DOCUMENTS 0x002e // All Users\Documents
#define CSIDL_COMMON_ADMINTOOLS 0x002f // All Users\Start Menu\Programs\Administrative Tools
#define CSIDL_ADMINTOOLS 0x0030 // <user name>\Start Menu\Programs\Administrative Tools
#endif // _SHFOLDER_H_
#define CSIDL_CONNECTIONS 0x0031 // Network and Dial-up Connections
#define CSIDL_COMMON_MUSIC 0x0035 // All Users\My Music
#define CSIDL_COMMON_PICTURES 0x0036 // All Users\My Pictures
#define CSIDL_COMMON_VIDEO 0x0037 // All Users\My Video
#define CSIDL_RESOURCES 0x0038 // Resource Direcotry
#ifndef _SHFOLDER_H_
#define CSIDL_RESOURCES_LOCALIZED 0x0039 // Localized Resource Direcotry
#endif // _SHFOLDER_H_
#define CSIDL_COMMON_OEM_LINKS 0x003a // Links to All Users OEM specific apps
#define CSIDL_CDBURN_AREA 0x003b // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
// unused 0x003c
#define CSIDL_COMPUTERSNEARME 0x003d // Computers Near Me (computered from Workgroup membership)
#ifndef _SHFOLDER_H_
#define CSIDL_FLAG_CREATE 0x8000 // combine with CSIDL_ value to force folder creation in SHGetFolderPath()
#endif // _SHFOLDER_H_
#define CSIDL_FLAG_DONT_VERIFY 0x4000 // combine with CSIDL_ value to return an unverified folder path
#define CSIDL_FLAG_DONT_UNEXPAND 0x2000 // combine with CSIDL_ value to avoid unexpanding environment variables
#if (NTDDI_VERSION >= NTDDI_WINXP)
#define CSIDL_FLAG_NO_ALIAS 0x1000 // combine with CSIDL_ value to insure non-alias versions of the pidl
#define CSIDL_FLAG_PER_USER_INIT 0x0800 // combine with CSIDL_ value to indicate per-user init (eg. upgrade)
#endif // NTDDI_WINXP
#define CSIDL_FLAG_MASK 0xFF00 // mask for all possible flag valuesSHGetSpecialFolderPath()
CSIDL_MYMUSIC
CString GetSpecialFolderLocation(int nFolder)
{
CString Result;
LPITEMIDLIST pidl;
HRESULT hr = SHGetSpecialFolderLocation(NULL, nFolder, &pidl);
if (SUCCEEDED(hr))
{
// Convert the item ID list's binary
// representation into a file system path
char szPath[_MAX_PATH];
if (SHGetPathFromIDList(pidl, szPath))
Result = szPath;
else
ASSERT(FALSE);
}
else
ASSERT(FALSE);
return Result;
}
#include "shlwapi.h"
#pragma comment(lib, "shlwapi")
PathFileExists()
remove()
/* 삭제하기 전에 다시 물어보기 */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
main(int argc, char *argv[])
{
char str[80];
if(argc!=2) {
printf("usage: xerase <filename>\n");
exit(1);
}
printf("Erase %s? (Y/N): ", argv[1]);
gets(str);
if(toupper(*str)=='Y')
if(remove(argv[1])) {
printf("Cannot erase file.\n");
exit(1);
}
return 0; /* 운영체제로 성공적 반환 */
}_splitpath()
_makepath()
POSIX
_taccess() // _access
// pwd
#define DIRNAME_LEN MAX_PATH + 2
int _tmain (int argc, LPTSTR argv [])
{
/* Buffer to receive current directory allows for the CR,
LF at the end of the longest possible path. */
TCHAR pwdBuffer [DIRNAME_LEN];
DWORD LenCurDir;
LenCurDir = GetCurrentDirectory (DIRNAME_LEN, pwdBuffer);
if (LenCurDir == 0)
ReportError (_T ("Failure getting pathname."), 1, TRUE);
if (LenCurDir > DIRNAME_LEN)
ReportError (_T ("Pathname is too long."), 2, FALSE);
PrintMsg (GetStdHandle (STD_OUTPUT_HANDLE), pwdBuffer);
return 0;
}
BOOL TraverseDirectory (LPTSTR, DWORD, LPBOOL);
DWORD FileType (LPWIN32_FIND_DATA);
BOOL ProcessItem (LPWIN32_FIND_DATA, DWORD, LPBOOL);
int _tmain (int argc, LPTSTR argv [])
{
BOOL Flags [MAX_OPTIONS], ok = TRUE;
TCHAR PathName [MAX_PATH + 1], CurrPath [MAX_PATH + 1], TempPath [MAX_PATH + 1];
LPTSTR pSlash, pFileName;
int i, FileIndex;
FileIndex = Options (argc, argv, _T ("Rl"), &Flags [0], &Flags [1], NULL);
/* "Parse" the search pattern into two parts: the "parent"
and the file name or wild card expression. The file name
is the longest suffix not containing a slash.
The parent is the remaining prefix with the slash.
This is performed for all command line search patterns.
If no file is specified, use * as the search pattern. */
GetCurrentDirectory (MAX_PATH, CurrPath); /* Save. */
if (argc < FileIndex + 1)
ok = TraverseDirectory (_T ("*"), MAX_OPTIONS, Flags);
else for (i = FileIndex; i < argc; i++) {
_tcscpy (PathName, argv [i]);
/* Find the rightmost slash, if any.
Set the path and use the rest as the file name. */
pSlash = _tstrrchr (PathName, '\\');
pSlash = _tstrrchr (TempPath, '\\'); // added by SNW
if (pSlash != NULL) {
*pSlash = '\0';
_tcscat(TempPath, _T("\\"));
SetCurrentDirectory (TempPath); /* Now restore pathname. */
pSlash = _tstrrchr (PathName, '\\');
pFileName = pSlash + 1;
} else pFileName = PathName;
ok = TraverseDirectory (pFileName, MAX_OPTIONS, Flags) && ok;
SetCurrentDirectory (CurrPath); /* Restore working directory. */
}
return ok ? 0 : 1;
}
static BOOL TraverseDirectory (LPTSTR PathName, DWORD NumFlags, LPBOOL Flags)
/* Traverse a directory, carrying out an implementation specific "action" for every
name encountered. The action in this version is "list, with optional attributes". */
/* PathName: Relative or absolute pathname to traverse. */
{
HANDLE SearchHandle;
WIN32_FIND_DATA FindData;
BOOL Recursive = Flags [0];
DWORD FType, iPass;
TCHAR CurrPath [MAX_PATH + 1];
/* Open up the directory search handle and get the
first file name to satisfy the path name.
Make two passes. The first processes the files
and the second processes the directories. */
// added by SNW:
if ( _tcslen(PathName) == 0 )
{
_tprintf(_T("Usage: lsFP [options] [pathname]\n"));
_tprintf(_T(" where [pathname] must not end in '\\'\n"));
return FALSE;
}
// end of new stuff added by SNW
GetCurrentDirectory (MAX_PATH, CurrPath);
/* Open up the directory search handle and get the
first file name to satisfy the path name. Make two passes.
The first processes the files and the second processes the directories. */
for (iPass = 1; iPass <= 2; iPass++) {
// Added by SNW:
// if path is of the form "X:" or "X:\" change to "X:\*"
if (_istalpha(PathName[0]) && (PathName[1] == ':') && (_tcslen(PathName) <= 3))
{
TCHAR TempPath[5] = {'\0', '\0' };;
TempPath[0] = PathName[0];
_tcscat (TempPath, _T(":\\*"));
SearchHandle = FindFirstFile (TempPath, &FindData);
}
else
SearchHandle = FindFirstFile (PathName, &FindData);
SearchHandle = FindFirstFile (PathName, &FindData);
if (SearchHandle == INVALID_HANDLE_VALUE) {
ReportError (_T ("Error opening Search Handle."), 0, TRUE);
return FALSE;
}
/* Scan the directory and its subdirectories
for files satisfying the pattern. */
do {
/* For each file located, get the type. List everything on pass 1.
On pass 2, display the directory name and recursively process
the subdirectory contents, if the recursive option is set. */
FType = FileType (&FindData);
if (iPass == 1) /* ProcessItem is "print attributes". */
ProcessItem (&FindData, MAX_OPTIONS, Flags);
/* Traverse the subdirectory on the second pass. */
if (FType == TYPE_DIR && iPass == 2 && Recursive) {
_tprintf (_T ("\n%s\\%s:"), CurrPath, FindData.cFileName);
SetCurrentDirectory (FindData.cFileName);
TraverseDirectory (_T ("*"), NumFlags, Flags);
SetCurrentDirectory (_T (".."));
}
/* Get the next file or directory name. */
} while (FindNextFile (SearchHandle, &FindData));
FindClose (SearchHandle);
}
return TRUE;
}
static DWORD FileType (LPWIN32_FIND_DATA pFileData)
/* Return file type from the find data structure.
Types supported:
TYPE_FILE: If this is a file
TYPE_DIR: If this is a directory other than . or ..
TYPE_DOT: If this is . or .. directory */
{
BOOL IsDir;
DWORD FType;
FType = TYPE_FILE;
IsDir = (pFileData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
if (IsDir)
if (lstrcmp (pFileData->cFileName, _T (".")) == 0
|| lstrcmp (pFileData->cFileName, _T ("..")) == 0)
FType = TYPE_DOT;
else FType = TYPE_DIR;
return FType;
}
static BOOL ProcessItem (LPWIN32_FIND_DATA pFileData, DWORD NumFlags, LPBOOL Flags)
/* Function to process (list attributes, in this case)
the file or directory. This implementation only shows
the low order part of the file size. */
{
const TCHAR FileTypeChar [] = {' ', 'd'};
DWORD FType = FileType (pFileData);
BOOL Long = Flags [1];
SYSTEMTIME LastWrite;
if (FType != TYPE_FILE && FType != TYPE_DIR) return FALSE;
_tprintf (_T ("\n"));
if (Long) {
_tprintf (_T ("%c"), FileTypeChar [FType - 1]);
_tprintf (_T ("%10d"), pFileData->nFileSizeLow);
FileTimeToSystemTime (&(pFileData->ftLastWriteTime), &LastWrite);
_tprintf (_T (" %02d/%02d/%04d %02d:%02d:%02d"),
LastWrite.wMonth, LastWrite.wDay,
LastWrite.wYear, LastWrite.wHour,
LastWrite.wMinute, LastWrite.wSecond);
}
_tprintf (_T (" %s"), pFileData->cFileName);
return TRUE;
}
int _tmain (int argc, LPTSTR argv [])
{
SYSTEMTIME SysTime;
FILETIME NewFileTime;
LPFILETIME pAccessTime = NULL, pModifyTime = NULL;
HANDLE hFile;
BOOL Flags [MAX_OPTIONS];
BOOL SetAccessTime, SetModTime, CreateNew;
DWORD CreateFlag;
int i, FileIndex;
/* Determine the options. */
if (argc < 2) {
_tprintf (_T("Usage: touch [options] files"));
return 1;
}
FileIndex = Options (argc, argv, _T ("amc"),
&Flags [0], &Flags [1], &Flags [2], NULL);
SetAccessTime = !Flags [0];
SetModTime = !Flags [1];
CreateNew = !Flags [2];
CreateFlag = CreateNew ? OPEN_ALWAYS : OPEN_EXISTING;
for (i = FileIndex; i < argc; i++) {
hFile = CreateFile (argv [i], GENERIC_READ | GENERIC_WRITE, 0, NULL,
CreateFlag, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
ReportError (_T ("touch error: Cannot open file."), 1, TRUE);
/* Get current system time and convert to a file time.
Do not change the create time. */
GetSystemTime (&SysTime);
SystemTimeToFileTime (&SysTime, &NewFileTime);
if (SetAccessTime) pAccessTime = &NewFileTime;
if (SetModTime) pModifyTime = &NewFileTime;
if (!SetFileTime (hFile, NULL, pAccessTime, pModifyTime))
ReportError (_T ("Failure setting file times."), 2, TRUE);
CloseHandle (hFile);
}
return 0;
}파일이 존재
HANDLE hFile = CreateFile(strName, GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);if (hFile == INVALID_HANDLE_VALUE) {return;}...CloseHandle(hFile);
#define DELUNSETUPBAT __TEXT("\\DelUS.bat")
static void WINAPI DeleteSelf()
{
HANDLE hfile = CreateFile(DELUNSETUPBAT, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hfile != INVALID_HANDLE_VALUE) {
TCHAR szUnsetupPathname[_MAX_PATH];
TCHAR szUnsetupPath[_MAX_PATH];
// Get the full pathname of our executable file.
GetModuleFileName(NULL, szUnsetupPathname, _MAX_PATH);
// Get the path of the executable file (without the filename)
lstrcpy(szUnsetupPath, szUnsetupPathname);
*strrchr(szUnsetupPath, __TEXT('\\')) = 0; // Chop off the name
TCHAR szBatFile[1000];
// Construct the lines for the batch file.
wsprintf(szBatFile,
__TEXT(":Repeat\r\n")
__TEXT("del \"%s\"\r\n")
__TEXT("if exist \"%s\" goto Repeat\r\n")
__TEXT("del \"%s\"\r\n"),
szUnsetupPathname, szUnsetupPathname, DELUNSETUPBAT);
DWORD dwNumberOfBytesWritten;
// Write the batch file and close it.
WriteFile(hfile, szBatFile, lstrlen(szBatFile) * sizeof(TCHAR),
&dwNumberOfBytesWritten, NULL);
CloseHandle(hfile);
STARTUPINFO si;
PROCESS_INFORMATION pi;
// Get ready to spawn the batch file we just created.
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
// We want its console window to be invisible to the user.
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
// Spawn the batch file with low-priority and suspended.
if (CreateProcess(NULL, DELUNSETUPBAT, NULL, NULL, FALSE, CREATE_SUSPENDED | IDLE_PRIORITY_CLASS, NULL,
__TEXT("\\"), &si, &pi))
{
// Lower the batch file's priority even more.
SetThreadPriority(pi.hThread, THREAD_PRIORITY_IDLE);
// Raise our priority so that we terminate as quickly as possible.
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
// Allow the batch file to run and clean-up our handles.
CloseHandle(pi.hProcess);
ResumeThread(pi.hThread);
// We want to terminate right away now so that we can be deleted
CloseHandle(pi.hThread);
}
}
}
참조 사이트:
http://www.debuglab.com/knowledge/getspecialpath.html
http://blog.naver.com/boxcj?Redirect=Log&logNo=140013288189
http://msdn.microsoft.com/en-us/library/aa363875(VS.85,printer).aspx
http://crowback.tistory.com/entry/%EC%89%98-007-SHGetSpecialFolderPath-VS-SHGetSpecialFolderLocati
http://www.codeguru.com/cpp/w-p/files/folderdirectorymaintenance/print.php/c4469/
http://www.codeproject.com/KB/install/EasyInstaller.aspx?display=Print
http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=50&MAEULNo=20&no=569480&ref=569471
http://sonbosun.tistory.com/21
http://blog.naver.com/aska2002/110029074729
http://november11.tistory.com/126
http://dcple.com/blog/tag/%EB%B2%84%EC%A0%84%EC%A0%95%EB%B3%B4
http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=51&MAEULNo=20&no=7739&ref=7739
http://www.codeproject.com/KB/system/FolderWatch.aspx?display=Print
http://www.codeproject.com/KB/files/directorychangewatcher.aspx?display=Print
http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=50&MAEULNo=20&no=403820&ref=403820
http://www.catch22.net/tuts/selfdel