我尝试了不同帖子中的几件事,但我似乎无法让它变得大胆
有谁知道怎么做到这一点?
$LabelComputer = New-Object System.Windows.Forms.Label
$LabelComputer.Text = "Computer Settings"
$LabelComputer.AutoSize = $True
$LabelComputer.Top="5"
$LabelComputer.Left="10"
$LabelComputer.Anchor="Left,Top"
$form1.Controls.Add($LabelComputer)
Run Code Online (Sandbox Code Playgroud) 我有这个脚本
#Change hostname
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
Write-Host "Change hostname " -NoNewLine
$ComputerName = [Microsoft.VisualBasic.Interaction]::InputBox('Insert the desired computername:', 'Change hostname')
Write-Host "- DONE" -ForegroundColor DarkGreen -BackgroundColor green -NoNewline
Write-Host " hostname = $ComputerName "
Rename-Computer -NewName $ComputerName
Run Code Online (Sandbox Code Playgroud)
当计算机名称获取空格时,它会失败导致主机名不能有空格.我可以阻止表单有任何空格,或者有人知道如何在重新创建错误时返回到输入框
我可以从我的桌面完美运行这个脚本:
private void Sleep_Click(object sender, EventArgs e)
{
PowerShell ps = PowerShell.Create();
ps.AddScript(@"D:\Desktop\alllightsoff.ps1");
ps.Invoke();
}
Run Code Online (Sandbox Code Playgroud)
但是当我更改程序文件的路径时,它什么也没做......有什么想法吗?
private void Sleep_Click(object sender, EventArgs e)
{
PowerShell ps = PowerShell.Create();
ps.AddScript(@"C:\Program Files (x86)\Home Control\alllightsoff.ps1");
ps.Invoke();
}
Run Code Online (Sandbox Code Playgroud)
可能与权限有关,该脚本不需要管理员权限即可运行,当我从程序文件夹手动运行 ps1 脚本时就可以正常工作。
我什至尝试了 %AppData% 文件夹并得到相同的结果,ps1 文件无法运行。
任何人都可以告诉我为什么我总是得到相同的输出结果?
$syslocal = Get-WmiObject -Class Win32_UserAccount -Filter "localaccount=true" |
where {$_.Disabled -eq $False}
if ($syslocal -eq "") {
Write-Host "Syslocal Enabled"
exit 0
} else {
Write-Host "No Syslocal"
exit 0
}
Run Code Online (Sandbox Code Playgroud)
它只需要查看帐户syslocal是否存在以及是否启用了3个结果:
但所有结果都是一样的.
powershell ×4
c# ×1
conditional ×1
finally ×1
fonts ×1
label ×1
loops ×1
try-catch ×1
winforms ×1