启动时,程序应该运行一个shell命令,例如" C:\ Program File \ Oracle \ VirtualBox \ VBoxManage.exe -startvm ..."
再次启动时,它应该运行一个不同的命令,例如" C:\ Program File \ Oracle \ VirtualBox \ VBoxManage.exe -controlvm ..."
我怎么写这样的程序?我可以用什么语言?我知道一些PHP和javascript,但这些不允许你创建在windows下运行的可执行文件:(
答案 0 :(得分:1)
我尝试使用powershell。不完全是.exe,但这里是一个.ps1表单(有一个3按钮GUI),允许你单独运行这些命令。
function KNUCKLE-DRAGGERS-3-BUTTON-FORM {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button3 = New-Object System.Windows.Forms.Button
$button2 = New-Object System.Windows.Forms.Button
$button1 = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
$handler_form1_Load=
{
}
$handler_button1_Click=
{
###########################################################################################################
# Button 1 commands #
###########################################################################################################
C:\Program File\Oracle\VirtualBox\VBoxManage.exe -startvm
}
$handler_button2_Click=
{
###########################################################################################################
# Button 2 commands #
###########################################################################################################
C:\Program File\Oracle\VirtualBox\VBoxManage.exe -controlvm
}
$handler_button3_Click=
{
###########################################################################################################
# Button 3 commands #
###########################################################################################################
$form1.close()
#Exit
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Knuckle-Dragger Was Here"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 212
$System_Drawing_Size.Height = 176
$form1.ClientSize = $System_Drawing_Size
$form1.add_Load($handler_form1_Load)
$button3.TabIndex = 2
$button3.Name = "button3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 140
$System_Drawing_Size.Height = 35
$button3.Size = $System_Drawing_Size
$button3.UseVisualStyleBackColor = $True
$button3.Text = "Exit"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 36
$System_Drawing_Point.Y = 114
$button3.Location = $System_Drawing_Point
$button3.DataBindings.DefaultDataSourceUpdateMode = 0
$button3.add_Click($handler_button3_Click)
$form1.Controls.Add($button3)
$button2.TabIndex = 1
$button2.Name = "button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 140
$System_Drawing_Size.Height = 35
$button2.Size = $System_Drawing_Size
$button2.UseVisualStyleBackColor = $True
$button2.Text = "Second Command"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 36
$System_Drawing_Point.Y = 71
$button2.Location = $System_Drawing_Point
$button2.DataBindings.DefaultDataSourceUpdateMode = 0
$button2.add_Click($handler_button2_Click)
$form1.Controls.Add($button2)
$button1.TabIndex = 0
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 140
$System_Drawing_Size.Height = 35
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.Text = "First Command"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 36
$System_Drawing_Point.Y = 28
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($handler_button1_Click)
$form1.Controls.Add($button1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
KNUCKLE-DRAGGERS-3-BUTTON-FORM
#