windows环境C语言修改系统时间-WinAPI总结

1.MSDN上有关时间设置API的详细介绍

①SYSTEMTIME结构体

typedef struct _SYSTEMTIME {
  WORD wYear;              /*年*/
  WORD wMonth;             /*月*/
  WORD wDayOfWeek;         /*星期  0-6  0-Sunday...*/
  WORD wDay;               /*日*/
  WORD wHour;              /*时*/
  WORD wMinute;            /*分*/
  WORD wSecond;            /*秒*/
  WORD wMilliseconds;      /*微妙*/
} SYSTEMTIME, *PSYSTEMTIME;

②GetLocalTime获取本地时间(北京时间)

void WINAPI GetLocalTime(
  _Out_  LPSYSTEMTIME lpSystemTime
);

③SetLocalTime设置本地时间(北京时间),

BOOL WINAPI SetLocalTime(
  _In_  const SYSTEMTIME *lpSystemTime
);

The calling process must have the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. Th

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Windows系统下,可以使用WinAPI函数来更改网卡IP地址。下面是一个简单的示例代码,可以更改指定网卡的IP地址和子网掩码。 ```c #include <stdio.h> #include <stdlib.h> #include <winsock2.h> #include <ws2tcpip.h> #include <iphlpapi.h> #include <netioapi.h> #pragma comment(lib, "iphlpapi.lib") #pragma comment(lib, "ws2_32.lib") int main() { WCHAR adapterName[] = L"本地连接"; // 要更改的网卡名称 WCHAR ipAddr[] = L"192.168.1.10"; // 新的IP地址 WCHAR subnetMask[] = L"255.255.255.0"; // 新的子网掩码 // 初始化Winsock WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { printf("WSAStartup failed: %d\n", WSAGetLastError()); return 1; } // 获取网卡信息 ULONG outBufLen = 0; GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &outBufLen); PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES) malloc(outBufLen); if (pAddresses == NULL) { printf("malloc failed\n"); return 1; } if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAddresses, &outBufLen) != NO_ERROR) { printf("GetAdaptersAddresses failed\n"); free(pAddresses); return 1; } // 遍历网卡信息,找到要更改的网卡 PIP_ADAPTER_ADDRESSES pAdapter = pAddresses; while (pAdapter) { if (wcscmp(pAdapter->FriendlyName, adapterName) == 0) { // 找到要更改的网卡,设置新的IP地址和子网掩码 PIP_ADAPTER_UNICAST_ADDRESS pUnicast = pAdapter->FirstUnicastAddress; while (pUnicast) { if (pUnicast->Address.lpSockaddr->sa_family == AF_INET) { PIP_ADAPTER_PREFIX pPrefix = pAdapter->FirstPrefix; while (pPrefix) { if (pPrefix->Address.lpSockaddr->sa_family == AF_INET) { ((SOCKADDR_IN *) pUnicast->Address.lpSockaddr)->sin_addr.S_un.S_addr = inet_addr(ipAddr); ((SOCKADDR_IN *) pPrefix->Prefix.lpSockaddr)->sin_addr.S_un.S_addr = inet_addr(subnetMask); break; } pPrefix = pPrefix->Next; } break; } pUnicast = pUnicast->Next; } break; } pAdapter = pAdapter->Next; } // 释放内存 free(pAddresses); // 卸载Winsock WSACleanup(); return 0; } ``` 注意:这个示例代码只能更改IPv4地址和子网掩码,如果需要更改其他信息,需要根据实际情况进行修改。另外,在实际使用时需要以管理员权限运行程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值