我为我的工作写了一个小工具,我需要将实际的机器名称更改为机器的序列号,我已经找到了如何获取序列号但我不知道如何设置机器名称我尝试过的每一个解决方案都没有工作,有人有一些建议吗?
Dim q As New SelectQuery("Win32_bios")
Dim search As New ManagementObjectSearcher(q)
Dim info As New ManagementObject
Try
For Each info In search.Get
Call MessageBox.Show("Serial Number: " & info("serialnumber").ToString +
vbCrLf + "Machine Name : " + Environment.MachineName)
Next
Return 1
Catch err As ManagementException
Call MessageBox.Show("Error: " & err.Message)
Return -99
End Try
我找到了解决方案
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Verb = "Runas"
pi.WindowStyle = ProcessWindowStyle.Hidden
pi.Arguments = "/K WMIC computersystem where caption='" + Environment.MachineName + "' rename Prova"
pi.FileName = "cmd.exe"
pi.UseShellExecute = True
pi.CreateNoWindow = True
Process.Start(pi)
它对我来说只是一个实用工具,但是如果我不想要求许可来运行这个过程,还有一种方法吗?