Jump to content

Print from GUI is it possible?


Recommended Posts

Hey there fellow AutoIt Scriptors... can anyone tell me if there is a way to print information once I run a gui and retrieve information from a PC?

I'm stumped... and it's driving me mad.

Any help is greatly appreciated.

 

Here is my script...

#include <GuiEdit.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
$Computer = ""
$NIC =""


MyScout()

Func MyScout()
Local $font, $btnQry, $btnRemote, $btnSMSSoftware, $btnSMSHardware, $msg
$font = "Times New Roman"
$data = GUIGetMsg()
GUICreate("Scout Tool", 400, 600)
GUISetState(@SW_SHOW)
$filemenu = GUICtrlCreateMenu("&File")
$fileitem = GUICtrlCreateMenuItem("Print...", $filemenu)
GUICtrlCreateLabel("Scout Tool", 10, 10, 100, 30)
GUICtrlSetFont(-1, 15, 400, 2, $font)
GUICtrlCreateLabel("SCCM Information", 275, 180, 100, 30)
GUICtrlCreateLabel("DeadSerious" & @CRLF & _
"Script created by: DeadSerious Group" & @CRLF & "ADMJ" & _
@CRLF & "Version 1.1" & @CRLF & "Date Created: 2/4/2014", 10, 500, 300)

GUICtrlCreateIcon(@scriptdir & "\scout.ico","",115,5,45,30)
$hEdit = GUICtrlCreateEdit("", 10, 40,250,400)
$PC = GUICtrlCreateInput("Enter Computer Name", 270, 40, 120, 25)
$btnQry = GUICtrlCreateButton("Query System",270, 70, 100, 30)
$btnRemote = GUICtrlCreateButton("Remote Control",270, 110, 100, 30)
$btnSMSSoftware = GUICtrlCreateButton("Installed Software",270, 200, 100, 30)
$btnSMSHardware = GUICtrlCreateButton("Hardware Inventory",270, 240, 100, 30)

GUISetState()
;_GUICtrlEdit_AppendText($hEdit, "Date: " & @MON & "/" & @MDAY & "/" & @YEAR & @CRLF)
_GUICtrlEdit_AppendText($hEdit, @CRLF & "Computer System Information")
_GUICtrlEdit_AppendText($hEdit, @CRLF & "----------------------------------------------")



While 1
   $msg = GUIGetMsg()
Select
   Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
   Case $msg = $btnQry
      $Computer = GUICtrlRead($PC)
      If $Computer = "Enter Computer Name" Then
         MsgBox(16,"Error", "Please enter a Host Name before clicking on the Query button!")
      ElseIf $Computer = "" Then
         MsgBox(16,"Error", "You MUST enter a Host Name before clicking on the Query button!")
      Else
         Local $memory = _Get_Memory() / 1024 / 1024 /1024 ; <===== Gets memory information and divides by 1024 3 times
         Local $x = Round($memory) ; <======== Rounds off the memory to the nearest GB
         $NIC = ""
         $objWMIService = ObjGet("winmgmts:\\" & $Computer & "\root\CIMV2")
         
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "Host: " & _Get_Name())
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "PC Model: " & _Get_SystemVendor() & " " & _Get_System_Model())
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "Serial Number: " & _Serial())
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "Memory: " & $x & " GB Memory")
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "Last User: " & _LastUserName() & @CRLF)
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "Operating System Information")
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "----------------------------------------------")
      
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "OS: " & _OS() & @CRLF & "OS Service Pack: " & _OS_SP())
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "Last Boot: " & _LastBoot()& @CRLF & @CRLF)
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "Network Information")
      _GUICtrlEdit_AppendText($hEdit, @CRLF & "----------------------------------------------")
      _GUICtrlEdit_AppendText($hEdit, @CRLF & MyIP() & $NIC)
      
      _GUICtrlEdit_AppendText($hEdit, @CRLF & @CRLF & " <-----------------------  End Query  -------------------------->")
      _GUICtrlEdit_AppendText($hEdit, @CRLF & @CRLF & @CRLF)
      

      
      
      EndIf
   Case $msg = $btnRemote
      Remote()
   Case $msg = $btnSMSSoftware
      $Computer = GUICtrlRead($PC)
      Run("C:\Program Files\Internet Explorer\iexplore.exe" & " http://technet.microsoft.com")
   Case $msg = $btnSMSHardware
      Run("C:\Program Files (x86)\Internet Explorer\iexplore.exe" & " http://www.anandtech.com")
   Case $msg = $fileitem
      Print()
   EndSelect
WEnd
   GUIDelete()
EndFunc




Func Remote() ; ================= If SCCM Remote is not installed show error ==========================================]
   $Remotex64 = FileExists("C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe")
   $Remotex86 = FileExists("C:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe")
   If $Computer = "" Then
      MsgBox(16,"Error", "Please enter a Host Name before you click on the Remote button!")
   ElseIf $Computer = "" Then
      MsgBox(0,"Error","You must enter a valid Host Name before clicking on the Remote button!")
      
   ElseIf  $Remotex64 = 1 Then
   Run("C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe " & $Computer & " \\mysccm01")
ElseIf $Remotex64 = -1 Then
   MsgBox(0,"Error", "SCCM Remote is not installed!")
ElseIf $Remotex86 = 1 Then
     Run("C:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\i386\CmRcViewer.exe " & $Computer & " \\mysccm01")
     Else
     MsgBox(0,"Error", "SCCM Remote is not installed!")
  EndIf
EndFunc




Func _Get_Name() ; <========== Gets Host Name of Remote PC ==========]
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_ComputerSystem", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.name
     Next
        
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 
 
  Func _Get_System_Model() ; <======= Gets Model Name of Remote PC ===]
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.Version
     Next
        
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 
 
Func _Get_SystemVendor() ; <======== Gets Manufacturer Name or Remote PC ================]
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.Vendor
     Next
        
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 
 
Func _LastUserName() ; <========= Gets LoggedOn User of Remote PC ======================]
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.Username
     Next
        
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 
 
 
Func _Serial() ; <======== Gets serial number of Remote PC ====================]
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.SerialNumber
     Next
        
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 
 
 Func _OS() ; <========== Gets Operating System Name ========================]
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.Caption
     Next
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 
 
 
 
 Func _LastBoot() ; <========== Gets System Uptime of Remote PC =======================]
Local $s_Text = ''
$objWMIService = ObjGet("winmgmts:\\" & $Computer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery( "SELECT LastBootUpTime FROM Win32_OperatingSystem")
For $objItem In $colItems
   Local $s_Text = $objItem.LastBootUpTime
   Return (StringMid($s_Text, 5, 2) & "/" & StringMid($s_Text, 7, 2) & "/" & StringLeft($s_Text, 4) & " " & StringMid($s_Text, 9, 2) & ":" _
   & StringMid($s_Text, 11, 2) & ":" & StringMid($s_Text, 13, 2)) 
Next

EndFunc
 
 
 
Func _OS_SP() ; <========== Gets OS Service Pack installed of Remote PC =========]
Local $s_Text = ''
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.ServicePackMajorVersion
     Next
        
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 


Func _Get_Memory() ; <========== Gets OS Service Pack installed of Remote PC =========]
Local $s_Text = ''
$objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
$objWMIService = $objWMILocator.ConnectServer($Computer, "\root\cimv2", "", "", "&H80")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", 0x30)
If (IsObj($objWMIService)) Then
   For $objItem In $colItems
      Local $s_Text = $ObjItem.TotalPhysicalMemory
     Next
        
        Return String($s_Text)
    Else
        Return 0
    EndIf
 EndFunc 


 Func _Get_TotalMemory() ; <========= Rounds off Total Memory to GB's ==================]
   Local $s_Text = ''
    $memory = _Get_TotalMemory() / 1024 / 1024 /1024 
    Local $x = Round($memory)
 Return String($x)
 EndFunc


Func MyIP()
$objWMIService = ObjGet("winmgmts:\\" & $Computer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True', "WQL", 0x10 + 0x20)
If IsObj($colItems) then
   For $objItem In $colItems
      $NIC = $NIC & "NIC: " & $objItem.Description & @CRLF
      $strIPAddress = $objItem.IPAddress(0)
      $NIC = $NIC & "IPAddress: " & $strIPAddress & @CRLF
      $NIC = $NIC & "MAC Address: " & $objItem.MACAddress & @CRLF & @CRLF
      Local $i = 0
While $i <= 10
    $i = $i + 1
WEnd
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" )
Endif 
EndFunc;<========= End Get Network Configuration


Func Print()
Local $print = _FilePrint(MyScout())
If $print Then
    MsgBox(0, "Print", "The file was printed.")
Else
    MsgBox(0, "Print", "Error: " & @error & @CRLF & "The file was not printed.")
 EndIf
 EndFunc
Link to comment
Share on other sites

i may be misreading, by MyScout() calls Print() which calls _FilePrint() which calls MyScout() again... you have some serious logic problem here.

solution:

_FilePrint() expects a text file name. instead of calling Print() from MyScout(), you need only export the data to a text file and then call _FilePrint() with that file.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Universalist, thank you for taking a look at my script, yes I will agree with you my logic is a little messed up, I'm trying to get the GUI part to print once the script is ran.

Is that possible? I'm not familar with how to do that.

I'm just now learning how to create a gui and wanted to see if I can print the output from directly from the gui, however I did not want to save the information to a file first if that is possible, just print directly from the gui.

Let me know if that is possible and if you could point me in the direction of how to script that I would really appreciate the help... thx.

Link to comment
Share on other sites

deadserious,

_FilePrint works by supplying the "print" verb to the default application for a file.  So "txt" might be notepad, "doc" will be MS Word, etc.

So you can see how this

Local $print = _FilePrint(MyScout())

does'nt make a lot of sense.  I tried to test your code but am getting object errors in the _Get_Memory routine.

One thing you can try is to write your file to a tempfile, print it with _FilePrint and delete the temp file.  All this assumes that you are trying to print to the local printer.

kylomas

edit: To answer your specific question.  I do not think you can print directly from your script unless you can send "printer language" to the printer port (PCL for example for HP printers). 

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...