VC++ 修改计算机名称 SetComputerName

C#实现修改计算机名称 (附完整源代码) 阅读详情

转载请标明出处,原文地址:http://blog.youkuaiyun.com/morewindows/article/details/8659430

欢迎关注微博:http://weibo.com/MoreWindows

 

上一篇《VC++得到计算机名和用户名》讲解了如何使用GetComputerName和GetUserName来获取计算机名称及用户名。本篇来讲解用SetComputerName来修改计算机名称。

函数原型:

//By MoreWindows-(http://blog.youkuaiyun.com/MoreWindows)

BOOLWINAPISetComputerName(

    __in          LPCTSTRlpComputerName

);

对于计算机名称有一定的要求,MSDN的解释如下:

The computer name that will take effect the next time the computer is started. The name must not be longer than MAX_COMPUTERNAME_LENGTH characters.

The standard character set includes letters, numbers, and the following symbols: ! @ # $ % ^ & ' ) ( . - _ { } ~ . If this parameter contains one or more characters that are outside the standard character set, SetComputerName returns ERROR_INVALID_PARAMETER.

// VC++修改计算机名称  
// http://blog.youkuaiyun.com/morewindows/article/details/8659430
//By MoreWindows-(http://blog.youkuaiyun.com/MoreWindows)  
#include <windows.h>
#include <stdio.h>
#include <conio.h>
int main()
{	
	printf("    VC++修改计算机名称 \n");        
	printf(" -- By MoreWindows( http://blog.youkuaiyun.com/MoreWindows ) --\n\n"); 
	const int MAX_BUFFER_LEN = 500;
	char  szBuffer[MAX_BUFFER_LEN];
	DWORD dwNameLen;
	
	dwNameLen = MAX_BUFFER_LEN;
	if (!GetComputerName(szBuffer, &dwNameLen)) 
	{
		printf("Error  %d\n", GetLastError());
		return -1;
	}
	printf("当前计算机名为: %s\n", szBuffer);
	printf("要改名吗?(y/n)\n");
	int ch = getch();
	ch = toupper(ch);
	if (ch == 'Y')
	{
		printf("请输入新名称:");
		gets(szBuffer);
		if (strlen(szBuffer) != 0)
		{
			if (SetComputerName(szBuffer))
				printf("恭喜!改名成功,重启后生效\n");
			else
				printf("Error  %d\n", GetLastError());
		}
	}
	return 0;
}

先修改下

 

重启后可以发现计算机的名称已经被修改了。

 

转载请标明出处,原文地址:http://blog.youkuaiyun.com/morewindows/article/details/8659430

欢迎关注微博:http://weibo.com/MoreWindows

 

VC获得和设置NetBIOS计算机名 VC++获得和设置NetBIOS计算机名,并可修改计算机名称,一般不要修改计算机名称,以免造成冲突而导致网络无法使用. 立即下载

相关推荐

MFC/VC 获取本机电脑名,本地IP地址

一个简单的VC++程序,可以获取本机电脑名,以及本地IP地址

C++修改电脑主机名、IP地址、掩码地址

因工作需要,部署一些环境经常要改主机名、IP地址。也算是一个运维工具。 目前就包括3个功能 修改电脑主机名 修改IP 修改掩码 // tool.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <windows.h> #include <iostream> #include <string> #i...

wangtong的博客 1494

通过代码修改计算机名称

如何通过代码修改计算机名称,代码中用C++实现。 如何通过代码修改计算机名称,代码中用C++实现。 如何通过代码修改计算机名称,代码中用C++实现。 如何通过代码修改计算机名称,代码中用C++实现。

SetComputerName改网络中计算机名

通过 Wiz 发布 转载于:https://www.cnblogs.com/xe2011/archive/2012/06/02/2531620.html

weixin_30868855的博客 222

数据分析:美团大赛的具体案例制作

在数据集中,存在三个变量的经纬度数据,分别是商家的经纬度数据('sender_lng', 'sender_lat'),顾客的经纬度数据('recipient_lng', 'recipient_lat')和骑手的经纬度数据('grab_lng', 'grab_lat')。根据结果可知,平台订单创建时间的中位数为2022-10-21 02:59:01,平台订单创建时间的众数为2022-10-19 03:29:41、2022-10-23 03:29:47,与直方图相符。接下来,我们对是否为预定订单变量进行分析。

m0_68269346的博客 2495

Tailscale 自建 DERP 中继服务器

Tailscale自建DERP中继服务器

Accompagner的博客 4328

计算机函数名功能,修改计算机名的 API 函数 SetComputerName

;~ 设置一个新的本地计算机的NetBIOS名称。这个名字是存储在注册表和更改名称生效在下次用户重新启动计算机。;~ 如果本地计算机是在一个群集节点,SetComputerName设置本地计算机的NetBIOS名称,而不是群集的虚拟服务器。;~ 要设置DNS主机名称或DNS域名,调用SetComputerNameEx功能;~ BOOL WINAPI SetComputerName(;~ __i...

weixin_30093159的博客 982

RV1126 ISP开发实战:从Tuner调试到IQ文件解析

本文详细介绍了RV1126 ISP开发的完整流程,从Tuner调试到IQ文件解析,涵盖了环境搭建、工具使用、参数配置及性能优化等关键环节。通过实战案例和避坑指南,帮助开发者快速掌握Rockchip芯片的ISP开发技巧,提升图像处理质量。

weixin_29195615的博客 571

WinAPI: SetComputerName - 更改计算机名称

//声明: SetComputerName( lpComputerName: PChar {新名称串指针} ): BOOL; //举例: var s: string; begin s := 'NewName'; if SetComputerName(PChar(s)) then ShowMessage(s) else ...

weixin_33896726的博客 271

【PB03F 超详细-环境搭建】蓝牙5.2安信可PB-03F-Kit开发板二次开发环境搭建

PB-03是由深圳市安信可科技有限公司开发的蓝牙模块。本博文介绍安信可PB-03F-Kit开发板的基本情况、开发环境搭建,以及以点亮LED为例介绍程序编写和固件烧录的操作流程。 安信可PB-03F-Kit开发板使用的PHY6252这样一款高集成度的低功耗蓝牙系统级芯片(SoC),专为物联网(IoT)、移动设备、可穿戴电子设备、智能家居等各种应用而设计。......

qq_44078824的博客 1万+

8、鼠疫流行过程的计算机建模介绍

本博文介绍了一种基于概率细胞自动机和蒙特卡罗方法的计算机模型,用于模拟由大沙鼠传播的鼠疫流行过程。结合GIS和遥感技术,该模型能够分析鼠疫在不同聚居地类型和季节变化下的传播特征,揭示了群落密度、分布及流行接触率对鼠疫传播的影响。研究还验证了模型与自然流行过程的一致性,并探讨了鼠疫在宿主数量低谷时的持续机制。模型为鼠疫防控和流行病研究提供了定量分析工具。

x2y3z4a5b的博客 105

获取/设置计算机名字

using Microsoft.VisualBasic.Devices;//Microsoft.VisualBasic.dll /// <summary> /// Sets a new NetBIOS name for the local computer. The name is stored in the registry and the name ch...

weixin_30463341的博客 216

采用了fluent模拟了平壁面结霜过程。udf,很经典,可以试试。

利用该模型作为FLUENT中的源项,模拟了在局部冷却下冷表面上的霜形成,以预测霜的形态、温度分布和霜的重量,结果与实验结果吻合良好。结果显示,霜首先围绕冷却块形成,然后逐渐向其他方向扩展,冷却块上方的霜密度最大。随着时间的推移,平均霜厚度逐渐增加,生长速率减慢,而平均霜密度随增长速率变快而增加。相变传递微观过程与机理、蒸发及冷凝换热、强化传热、高效传热管、热泵、制冷、节水节能新技术、电子元器件冷却、余热回收及梯级利用等。udf,很经典,可以试试。工程热物理、空调、热能、低温制冷、化工、物理等。

qq_15963745的博客 922

C语言调用WindowsAPI函数获取计算机名称

源程序为:#include#includevoid main(){ char a[255];        unsigned long size=255; GetComputerName(a,&size);    printf("The computers name is:/n "); printf("%s",a);    printf("/n");} 使用到的API 函数是:

huluputi的专栏 5460

文末含资料链接和视频讲解!YOLOv8+RepVGG+QueryDet小目标检测终极指南:从理论到实战,突破遥感图像检测难题

QueryDet(Query Detection)机制代表了目标检测领域的一个重要范式转变。传统的目标检测方法基于anchor或anchor-free的密集预测,需要为图像中的每个可能位置生成预测。而QueryDet采用了稀疏查询的方式,通过少量的可学习查询向量来直接预测目标。 这种设计灵感来源于Transformer架构中的注意力机制。在自然语言处理中,Transformer通过query-key-value机制实现了高效的序列建模。QueryDet将这一思想引入到目标检测中,将检测问题转化为查询匹配问

FJN110的博客 384

【QT开发教程】如何在Qt中使用Protobuf进行高效数据序列化

Protocol Buffers(Protobuf)是Google开发的一种语言中立、平台中立、可扩展的序列化机制,常用于数据交换和存储。Qt作为一个跨平台的C++图形用户界面应用框架,可以与Protobuf结合使用,实现高效的数据序列化和反序列化。本文将介绍如何在Qt中集成和使用Protobuf,包括基本概念、安装步骤、使用示例以及实际应用。

科技改变人类,技术成就未来 1439

使用脚本更改计算机名

第一种:Dim revalSet objnet = CreateObject ("WScript.Network")Set R = CreateObject("WScript.Shell")reval = InputBox ("当前的计算机名是:" & objnet.ComputerName,"输入新的计算机名")On Error Resume NextstrCo...

weixin_34019929的博客 1676

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

一键修改计算机名(无需重启)

@ ECHO OFF color 0A ECHO ---------------------------------------------------------------------------- ECHO. ECHO 版权所有 copyright of @@@@@@@@@ ECHO. ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...

迷逝 3877

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

编程修改windows计算机名。

在公司软件定制部门工作时研究了改计算机名问题,有了些心得,写了个工具实现. 不但改计算机名,netbios名也同时更新.win2000和winxp下测试通过.    #include "stdafx.h"#include "ChgCompName.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[]

Loudy的专栏 1410

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Windows硬件系统函数 - SetComputerName

VB声明Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long说明设置新的计算机名返回值Long,非零表示成功,零表示失败。会设置GetLastError

水木清华 1309

更改主机名的方法(永久)

更改主机名的方法(永久)

u011868279的博客 1万+

修改主机名字

hostnamectl set-hostname +名字 修改的基本都是这个位置的修改主机名的方法主要有临时生效修改主机名的方法主要有临时生效和永久生效两种: 1、临时生效 所谓临时生效,就是在服务器不重启的情况下,临时改变主机名。通过使用hostname 命令即可实现。 (1)输入下面的命令,其中mylinux是目标名称。 命令:hostname mylinux 2、永久生效 (1)修改/etc/sysconfig/network 文件 命令:vim /etc/sysconfig/netw..

m0_64896408的博客 2140

windows远程桌面mstsc@保存登录凭证问题CredentialGuard@中转投屏等细节@局域网环境

文章目录被连接机器的信息获取:获取名字:获取ip:主控机的设置:输入信息result: 被连接机器的信息获取: 获取名字: 记下改名字(也可以自行修改计算机名) 获取ip: 主控机的设置: win+R: 输入信息 第一栏:输入computer ip/username(刚才获取的局域网的话) 用名字也可: 关键是第二栏,输入被控机器的用户名及其密码(登录选型如果是pin码似乎不行,需要用密码登录) result: 这里被控机器我用的是本地账号登录: ...

xuchaoxin1375的博客 7773
上一篇: VC++ 得到计算机名和用户名 GetComputerName GetUserName
下一篇: 秒杀多线程第十六篇 多线程十大经典案例之一 双线程读写队列数据
MoreWindows
MoreWindows 《白话经典算法》、《秒杀多线程》作者 《白话经典算法》、《秒杀多线程》作者 领域专家: 操作系统技术领域 领域专家: 操作系统技术领域
博客等级 码龄15年 2万+粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值