从Windows Forms应用程序传递输入到VBScript

时间:2023-01-09 07:29:18

I have created a small desktop application which allows users to log a call with our help desk without the need of a browser or email application (since it is locked down)

我创建了一个小型桌面应用程序,允许用户使用我们的帮助台记录呼叫,而无需浏览器或电子邮件应用程序(因为它已被锁定)

Within the form code i call a vbs script which collects system information from WMI and then send an email via outlook/cdo (still deciding on email method)

在表单代码中,我调用一个vbs脚本,该脚本从WMI收集系统信息,然后通过outlook / cdo发送电子邮件(仍然决定使用电子邮件方法)

Below is my form code for the send button.

下面是我的发送按钮的表单代码。

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim strName As String
        Dim strDept As String
        Dim strEmail As String
        Dim strExt As String
        Dim strDesc As String
        Dim strAffect As String

        strName = TextBox1.Text
        strDept = TextBox2.Text
        strEmail = TextBox3.Text
        strExt = TextBox4.Text
        strDesc = RichTextBox1.Text
        strAffect = TextBox5.Text

        System.Diagnostics.Process.Start("c:\Temp\Support.vbs")
        MessageBox.Show("Thank you!")
        Me.Close()
    End Sub

End Class

My problem now comes in with the vbscript code. i need to pass the input parameters from the above form (Name, dept, email address, etc) to the VBScript file to use in the email to support, but i have no idea how to do this.

我的问题现在出现在vbscript代码中。我需要将输入参数从上面的表单(名称,部门,电子邮件地址等)传递到VBScript文件,以便在电子邮件中使用支持,但我不知道如何做到这一点。

NOTE: I have very basic vbscript and vb experience and google is my friend, i have searched the internet for 2 days to find a solution but to no avail. So naturally this is my last resource

注意:我有非常基本的vbscript和vb经验,谷歌是我的朋友,我已经在互联网上搜索了2天找到解决方案但无济于事。所以这自然是我最后的资源

Below is my VBScript file, (support.vbs) which is called by the above form. Its copy and paste code with modification.

下面是我的VBScript文件,(support.vbs),由上面的表格调用。它的复制和粘贴代码有修改。

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set Arg = WScript.Arguments

Const NUMBER_OF_ROWS = 19
Const NUMBER_OF_COLUMNS = 2

Set objWord = CreateObject("Word.Application")
objWord.Visible = true
Set objDoc = objWord.Documents.Add()

Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
objTable.Cell(1,1).Range.Text = "System Information For: "
objTable.Cell(2,1).Range.Text = "Manufacturer"
objTable.Cell(3,1).Range.Text = "Model"
objTable.Cell(4,1).Range.Text = "Domain Type"
objTable.Cell(5,1).Range.Text = "Total Physical Memory"
objTable.Cell(6,1).Range.Text = "Processor Manufacturer"
objTable.Cell(7,1).Range.Text = "Processor Name"
objTable.Cell(8,1).Range.Text = "Processor Clock Speed"
objTable.Cell(9,1).Range.Text = "Bios Version"
objTable.Cell(10,1).Range.Text = "Serial Number"
objTable.Cell(11,1).Range.Text = "Video Controller"
objTable.Cell(12,1).Range.Text = "CD-ROM Manufacturer"
objTable.Cell(13,1).Range.Text = "CD-ROM Name"
objTable.Cell(14,1).Range.Text = "KeyBoard"
objTable.Cell(15,1).Range.Text = "Primary Drive Size"
objTable.Cell(16,1).Range.Text = "Primary Drive Space Available"
objTable.Cell(17,1).Range.Text = "Service Pack"
objTable.Cell(18,1).Range.Text = "Windows Version"
objTable.Cell(19,1).Range.Text = "IP Address"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
objTable.Rows.Add()
objTable.Cell(1, 2).Range.Text = UCase(strComputer)
objTable.Cell(2, 2).Range.Text = objItem.Manufacturer
objTable.Cell(3, 2).Range.Text = objItem.Model
Select Case objItem.DomainRole
Case 0 strComputerRole = "Standalone Workstation"
Case 1 strComputerRole = "Member Workstation"
Case 2 strComputerRole = "Standalone Server"
Case 3 strComputerRole = "Member Server"
Case 4 strComputerRole = "Backup Domain Controller"
Case 5 strComputerRole = "Primary Domain Controller"
End Select
objTable.Cell(4, 2).Range.Text = strComputerRole
objTable.Cell(5, 2).Range.Text = objItem.TotalPhysicalMemory/1048576 & " MB"
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
objTable.Cell(6, 2).Range.Text = objItem.Manufacturer
objTable.Cell(7, 2).Range.Text = objItem.Name
objTable.Cell(8, 2).Range.Text = Round(objItem.MaxClockSpeed) & " MHz"
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
For Each objItem in colItems
objTable.Cell(9, 2).Range.Text = objItem.Version
objTable.Cell(10, 2).Range.Text = objItem.SerialNumber
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_VideoController")
For Each objItem in colItems
objTable.Cell(11, 2).Range.Text = objItem.Name
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
objTable.Cell(12, 2).Range.Text = objItem.Manufacturer
objTable.Cell(13, 2).Range.Text = objItem.Name
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_Keyboard")
For Each objItem in colItems
objTable.Cell(14, 2).Range.Text = objItem.Caption
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DeviceID = ""C:""")
For Each objItem in colItems
objTable.Cell(15, 2).Range.Text = Round(objItem.Size /1073741824) & " GB"
Next

Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
objTable.Cell(16, 2).Range.Text = Round(objDisk.Freespace /1073741824) & " GB"    
Next

Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objTable.Cell(17, 2).Range.Text = objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion
Next

Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objTable.Cell(18, 2).Range.Text = objOperatingSystem.Caption & "  " & objOperatingSystem.Version
Next


Set IPConfigSet = objWMIService.ExecQuery _
    ("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then 
        For i=LBound(IPConfig.IPAddress) _
            to UBound(IPConfig.IPAddress)
objTable.Cell(19, 2).Range.Text = IPConfig.IPAddress(i)
        Next
    End If
Next

objTable.AutoFormat(23)

objDoc.SaveAs("C:\Temp\Sysinfo.doc")

objWord.Quit

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\Temp\Sysinfo.doc"
myItem.Display     '-- Optional --
myItem.To = "email address"
myItem.Subject = ""
myItem.Body = "Dear IT Support" & vbCRLF & vbCRLF & "Please assist with the following:" & vbCRLF & vbCRLF & "1. Requester info.: " & strName & vbCRLF & vbCRLF & "2. Brief summary of the issue and error message," & vbCRLF & vbCRLF & "3. Name of system or piece of IT equipment which is not working (eg: screen, keyboard, Internet, etc.)," & vbCRLF & vbCRLF & "3.1 Other issues: " & vbCRLF & vbCRLF & "3.3 Telephone call issues: Telephone number being dialed/received, time issue occurred, Ext. number where issue occurred," & vbCRLF & vbCRLF & "4. Number of users affected by the issue," & vbCRLF & vbCRLF & "5. Step by step replication details(from the login screen until issue occurred)."

1 个解决方案

#1


According to this forum post, if you have the ability to run the script from within your program using the ScriptControl, you can simply add your variables as declaration lines to the script before execution.

根据此论坛帖子,如果您能够使用ScriptControl从程序中运行脚本,则可以在执行之前将变量作为声明行添加到脚本中。

If that doesn't appeal to you, according to this Stack Overflow post, you can send and retrieve your variables as command line arguments, which you can simply include in your Process.Start call.

如果这对您没有吸引力,根据此Stack Overflow帖子,您可以将变量作为命令行参数发送和检索,您可以将其简单地包含在Process.Start调用中。

#1


According to this forum post, if you have the ability to run the script from within your program using the ScriptControl, you can simply add your variables as declaration lines to the script before execution.

根据此论坛帖子,如果您能够使用ScriptControl从程序中运行脚本,则可以在执行之前将变量作为声明行添加到脚本中。

If that doesn't appeal to you, according to this Stack Overflow post, you can send and retrieve your variables as command line arguments, which you can simply include in your Process.Start call.

如果这对您没有吸引力,根据此Stack Overflow帖子,您可以将变量作为命令行参数发送和检索,您可以将其简单地包含在Process.Start调用中。