ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

GetSystemDirectory获取系统目录

2020-02-03 21:04:42  阅读:439  来源: 互联网

标签:WINAPI GetSystemDirectory 获取 SystemParametersInfo UINT UNICODE BOOL 系统目录 define


GetSystemDirectory获取系统目录
windows说明

WINBASEAPI
UINT
WINAPI
GetSystemDirectoryA(
    LPSTR lpBuffer,  //缓冲区用于存放取得的系统目录
    UINT uSize        //缓冲区长度
    );
WINBASEAPI
UINT
WINAPI
GetSystemDirectoryW(
    LPWSTR lpBuffer,
    UINT uSize
    );
#ifdef UNICODE
#define GetSystemDirectory  GetSystemDirectoryW
#else
#define GetSystemDirectory  GetSystemDirectoryA
#endif // !UNICODE

GetWindowsDirectory 获取windows安装目录
windows定义

WINBASEAPI
UINT
WINAPI
GetWindowsDirectoryA(
    LPSTR lpBuffer,  //缓冲区
    UINT uSize        //缓冲区长度
    );
WINBASEAPI
UINT
WINAPI
GetWindowsDirectoryW(
    LPWSTR lpBuffer,
    UINT uSize
    );
#ifdef UNICODE
#define GetWindowsDirectory  GetWindowsDirectoryW
#else
#define GetWindowsDirectory  GetWindowsDirectoryA
#endif // !UNICODE

GetUserName 获取用户名
windows定义

WINADVAPI
BOOL
WINAPI
GetUserNameA (
    LPSTR lpBuffer,   //缓冲区
    LPDWORD nSize  //设置缓冲区长度
    );
WINADVAPI
BOOL
WINAPI
GetUserNameW (
    LPWSTR lpBuffer,
    LPDWORD nSize
    );
#ifdef UNICODE
#define GetUserName  GetUserNameW
#else
#define GetUserName  GetUserNameA
#endif // !UNICODE

GetComputerName 获取主机名
系统定义

WINBASEAPI
BOOL
WINAPI
SetComputerNameA (
    LPCSTR lpComputerName
    );
WINBASEAPI
BOOL
WINAPI
SetComputerNameW (
    LPCWSTR lpComputerName
    );
#ifdef UNICODE
#define SetComputerName  SetComputerNameW
#else
#define SetComputerName  SetComputerNameA
#endif // !UNICODE

SystemParametersInfo 获取和设置外设信息
系统定义

WINUSERAPI
BOOL
WINAPI
SystemParametersInfoA(
    UINT uiAction,
    UINT uiParam,
    PVOID pvParam,
    UINT fWinIni);
WINUSERAPI
BOOL
WINAPI
SystemParametersInfoW(
    UINT uiAction,
    UINT uiParam,
    PVOID pvParam,
    UINT fWinIni);
#ifdef UNICODE
#define SystemParametersInfo  SystemParametersInfoW
#else
#define SystemParametersInfo  SystemParametersInfoA
#endif // !UNICODE

设置系统参数函数
BOOL SystemParametersInfo(UINT uiAction,UINT uiParam,PVOID pvParam,UINT fWinlni);
SystemParametersInfo函数查询或设置系统级参数。函数原型是BOOL SystemParametersInfo。该函数也可以在设置参数中更新用户配置文件,这个函数还有很多其它功能,比如获取桌面工作区的大小。

#include <Windows.h>
#include <stdio.h>
//#include <stdafx.h>

int main()
{
	TCHAR szStr[MAX_PATH];
	TCHAR szWindowspath[MAX_PATH];
	TCHAR szComputerName[20+1];
	DWORD dwComputerNameLength = 20+1;
	TCHAR szUserName[32];
	DWORD nUserNameLength = 32;
	if(GetSystemDirectory(szStr,strlen(szStr)) <= 0)
	{
		printf("Getsystemdirectory error,Error No:%d\n",GetLastError());
		return 1;
	}

	printf("System path:%s\n",szStr);

	GetWindowsDirectory(szWindowspath,MAX_PATH);
	printf("Windows path:%s\n",szWindowspath);
	GetComputerName(szComputerName,&dwComputerNameLength);
	printf("computer name:%s\n",szComputerName);

	GetUserName(szUserName,&nUserNameLength);
	printf("User name:%s\n",szUserName);

	BOOL fResult = false;
	int aMouseInfo[3];
	fResult = SystemParametersInfo(SPI_GETMOUSE,0,&aMouseInfo,0);
	if(fResult)
	{
		aMouseInfo[2] *= 2;
		SystemParametersInfo(SPI_SETMOUSE,0,aMouseInfo,SPIF_SENDCHANGE);
	}

	SERIALKEYS keys;
	SystemParametersInfo(SPI_GETPOWEROFFACTIVE,1,&keys,sizeof(keys));


	printf("mouse chaned ok!\n");
	return 0;
}
单于大爷 发布了25 篇原创文章 · 获赞 1 · 访问量 6321 私信 关注

标签:WINAPI,GetSystemDirectory,获取,SystemParametersInfo,UINT,UNICODE,BOOL,系统目录,define
来源: https://blog.csdn.net/weixin_43069562/article/details/104161729

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有