// FileView.cpp : implementation of the CFileView class
//
#include "stdafx.h"
#include "File.h"
#include "FileDoc.h"
#include "FileView.h"
//#include <fstream>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileView
IMPLEMENT_DYNCREATE(CFileView, CView)
BEGIN_MESSAGE_MAP(CFileView, CView)
//{{AFX_MSG_MAP(CFileView)
ON_COMMAND(IDM_FILE_WRITE, OnFileWrite)
ON_COMMAND(IDM_FILE_READ, OnFileRead)
ON_COMMAND(IDM_REG_WRITE, OnRegWrite)
ON_COMMAND(IDM_REG_READ, OnRegRead)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileView construction/destruction
CFileView::CFileView()
{
// TODO: add construction code here
}
CFileView::~CFileView()
{
}
BOOL CFileView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFileView drawing
void CFileView::OnDraw(CDC* pDC)
{
CFileDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CFileView printing
BOOL CFileView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFileView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFileView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CFileView diagnostics
#ifdef _DEBUG
void CFileView::AssertValid() const
{
CView::AssertValid();
}
void CFileView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFileDoc* CFileView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFileDoc)));
return (CFileDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFileView message handlers
void CFileView::OnFileWrite()
{
// TODO: Add your command handler code here
if(1==1)
{
FILE *pFile=fopen("1.txt","w");
fwrite("filetest",1,strlen("filetest"),pFile);
fseek(pFile,0,SEEK_SET);
fwrite("ftp:",1,strlen("ftp:"),pFile);
fwrite("filetest",1,strlen("filetest"),pFile);
fclose(pFile);
fflush(pFile);
}
if(1==1)
{
FILE *pFile=fopen("2.txt","w");
char ch[3];
ch[0]='a';
ch[1]=10;
ch[2]='b';
fwrite(ch,1,3,pFile);
fclose(pFile);
}
if(1==1)
{
FILE *pFile=fopen("3.txt","w");
int i=98341;
char ch[5];
ch[0]=9+48;
ch[1]=8+48;
ch[2]=3+48;
ch[3]=4+48;
ch[4]=1+48;
itoa(i,ch,10);
fwrite(&i,4,1,pFile);
fwrite(ch,1,5,pFile);
fclose(pFile);
//ofstream ofs("4.txt");
//ofs.write("filetest",strlen("filetest"));
//ofs.close();
HANDLE hFile;
hFile=CreateFile("5.txt",GENERIC_WRITE,0,NULL,CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,NULL);
DWORD dwWrites;
WriteFile(hFile,"filetest",strlen("filetest"),
&dwWrites,NULL);
CloseHandle(hFile);
CFile file("6.txt",CFile::modeCreate | CFile::modeWrite);
file.Write("filetest",strlen("filetest"));
file.Close();
CFileDialog fileDlg(FALSE);
fileDlg.m_ofn.lpstrTitle="文件";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt="txt";
if(IDOK==fileDlg.DoModal())
{
CFile file(fileDlg.GetFileName(),CFile::modeCreate | CFile::modeWrite);
file.Write("filetest",strlen("filetest"));
file.Close();
}
}
}
void CFileView::OnFileRead()
{
// TODO: Add your command handler code here
FILE *pFile=fopen("1.txt","r");
char ch[100];
memset(ch,0,100);
fread(ch,1,100,pFile);
MessageBox(ch);
char *pBuf;
fseek(pFile,0,SEEK_END);
int len=ftell(pFile);
pBuf=new char[len+1];
rewind(pFile);
fread(pBuf,1,len,pFile);
pBuf[len]=0;
MessageBox(pBuf);
fclose(pFile);
if(1==1)
{
FILE *pFile=fopen("2.txt","r");
char ch[100];
fread(ch,1,3,pFile);
ch[3]=0;
MessageBox(ch);
fclose(pFile);
/*ifstream ifs("4.txt");
char ch[100];
memset(ch,0,100);
ifs.read(ch,100);
ifs.close();
MessageBox(ch);*/
if(1==1)
{
HANDLE hFile;
hFile=CreateFile("5.txt",GENERIC_READ,0,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
char ch[100];
DWORD dwReads;
ReadFile(hFile,ch,100,&dwReads,NULL);
ch[dwReads]=0;
CloseHandle(hFile);
MessageBox(ch);
}
CFile file("6.txt",CFile::modeRead);
char *pBuf;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuf=new char[dwFileLen+1];
pBuf[dwFileLen]=0;
file.Read(pBuf,dwFileLen);
file.Close();
MessageBox(pBuf);
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle="文件";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
if(IDOK==fileDlg.DoModal())
{
CFile file(fileDlg.GetFileName(),CFile::modeRead);
char *pBuf;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuf=new char[dwFileLen+1];
pBuf[dwFileLen]=0;
file.Read(pBuf,dwFileLen);
file.Close();
MessageBox(pBuf);
}
}
}
void CFileView::OnRegWrite()
{
// TODO: Add your command handler code here
HKEY hKey;
DWORD dwAge=30;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\filetest\\admin",&hKey);
RegSetValue(hKey,NULL,REG_SZ,"zhangsan",strlen("zhangsan"));
RegSetValueEx(hKey,"age",0,REG_DWORD,(CONST BYTE*)&dwAge,4);
RegCloseKey(hKey);
MessageBox("注册表写入成功","注册表操作",NULL);
}
void CFileView::OnRegRead()
{
// TODO: Add your command handler code here
/* LONG lValue;
RegQueryValue(HKEY_LOCAL_MACHINE,"Software\\filetest\\admin",
NULL,&lValue);
char *pBuf=new char[lValue];
RegQueryValue(HKEY_LOCAL_MACHINE,"Software\\filetest\\admin",
pBuf,&lValue);
MessageBox(pBuf);*/
HKEY hKey;
RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\filetest\\admin",&hKey);
DWORD dwType;
DWORD dwValue;
DWORD dwAge;
RegQueryValueEx(hKey,"age",0,&dwType,(LPBYTE)&dwAge,&dwValue);
CString str;
str.Format("age=%d",dwAge);
MessageBox(str);
}
没有合适的资源?快使用搜索试试~ 我知道了~
提升操作注册表的特权限
共27个文件
h:6个
cpp:5个
ico:2个
3星 · 超过75%的资源 需积分: 50 41 下载量 3 浏览量
2011-07-21
08:59:39
上传
评论
收藏 59KB RAR 举报
温馨提示
为什么要提升操作注册表的特权限? 要对一个任意进程(包括系统安全进程和服务进程)进行指定了写相关的访问权的OpenProcess操作,只要当前进程具有SeDeDebug权限就 可以了。要是一个用户是Administrator或是被给予了相应的权限,就可以具有该权限。可是,就算我们用Administrator帐号对一个系 统安全进程执行OpenProcess(PROCESS_ALL_ACCESS,FALSE, dwProcessID)还是会遇到“访问拒绝”的错误。什么原因呢?原来在默认的情况下进程的一些访问权限是没有被使能(Enabled)的,所以我们 要做的首先是使能这些权限。与此相关的一些API函数有OpenProcessToken、LookupPrivilegevalue、 AdjustTokenPrivileges。
资源推荐
资源详情
资源评论
收起资源包目录
文件和注册表操作.rar (27个子文件)
文件和注册表操作
File
File.suo 11KB
StdAfx.cpp 206B
resource.h 779B
FileDoc.h 1KB
File.rc 11KB
File.cpp 4KB
FileDoc.cpp 2KB
MainFrm.h 2KB
File.dsw 531B
File.clw 2KB
File.opt 54KB
File.plg 551B
FileView.h 2KB
StdAfx.h 1KB
File.sln 897B
MainFrm.cpp 2KB
File.dsp 4KB
File.aps 45KB
File.ncb 83KB
res
FileDoc.ico 1KB
File.ico 1KB
Toolbar.bmp 1KB
File.rc2 396B
File.h 1KB
File.vcproj 7KB
FileView.cpp 7KB
文件和注册表操作.ppt 91KB
共 27 条
- 1
Tinna_zhang
- 粉丝: 22
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页