class ComputerName
{
[DllImport("kernel32.dll", EntryPoint = "SetComputerNameEx")]
public static extern int apiSetComputerNameEx(int type, string lpComputerName);
public static int setName(string name){
return apiSetComputerNameEx(5, name);
}
public static string GetRandomString(int length, bool useNum, bool useLow, bool useUpp, bool useSpe, string custom)
{
byte[] b = new byte[4];
new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
Random r = new Random(BitConverter.ToInt32(b, 0));
string s = null, str = custom;
if (useNum == true) { str += "0123456789"; }
if (useLow == true) { str += "abcdefghijklmnopqrstuvwxyz"; }
if (useUpp == true) { str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
if (useSpe == true) { str += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
for (int i = 0; i < length; i++)
{
s += str.Substring(r.Next(0, str.Length - 1), 1);
}
return s;
}
}
一键改计算机名称随机字符串
猜你喜欢
转载自blog.csdn.net/chscomfaner/article/details/82804096
今日推荐
周排行