Powershell新手来了我试图写一个有用的工具,它有3个按钮和一个文本窗口。每个按钮调用一个不同的powershell (.ps1)脚本来执行不同的事情。如果可以的话,我想将这些脚本的输出写入GUI文本窗口,但这似乎比人们想象的要困难。如果这太多了,那么至少我想在文本窗口中显示脚本已经完成了。就像“脚本已经被运行”一样。
这是我到目前为止所拥有的。
Add-Type -AssemblyName System.Windows.Forms
function call_Clean
{
# Here the path to call your script
. "
如果用户想推迟关闭时间,我有一个power-shell表单提示用户(关闭时间由另一个ps脚本作为参数,在初始脚本中计算)。
我想在不活动30分钟后结束表格,我该怎么做呢?
Powershell代码(表格):
#creating the form object
$form = New-Object System.Windows.Forms.Form
#setting the from title
$form.Text = "System warning"
#setting the form dimesnions and positions
$form.Size = N
建议将处理程序创建为函数是最好的,因为这是传递参数的唯一方法。
我的问题是,我该如何将参数传递给按钮处理程序?
假设我想将当前用户配置文件作为参数传入,并在单击按钮时显示它,我该怎么做呢?
假设我有这样的代码:
#Pass a parameter to the button function to display current user
Function Button_Click()
{
[System.Windows.Forms.MessageBox]::Show("Hello World." , "My Dialog Box")
}
Functio