It is currently Fri Oct 30, 2020 5:58 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: wmic small GUI
PostPosted: Thu Nov 07, 2019 5:28 pm 
Offline
Addict
Addict

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 948
Hi all :D

Starting from an idea of tatanas on the use of WMI request on network, a small test interface just to demonstrate (to new PB users) how to encapsulate the Windows command wmic.exe
Base topic: viewtopic.php?p=544243#p544243

The program does not process input errors, it is just a minimum interface.

The interface was generated with the form designer and then cut and pasted into a single file. Re-separate if you want to modify easily.

It is necessary that the server machine is configured to accept remote requests, DCOM and that its firwall lets out these protocols

Server can be IP or hostname
Username and Password must exist on server an must be administrator.
Code:
; WMIC GUI
; Marc56 2019/11/07 - Based on a suggestion from tatanas (using wmic.exe)
; https://www.purebasic.fr/english/viewtopic.php?p=544194#p544194

EnableExplicit

SetGadgetFont(#PB_Default, FontID(LoadFont(#PB_Any, "Consolas", 9)))

;XIncludeFile "WMIC_GUI.pbf"
; -------------------------------------------------------------------------------------
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #Txt_Server
  #Txt_User
  #Txt_Password
  #Txt_Query
  #Str_Server
  #Str_User
  #Str_Password
  #Str_Query
  #Btn_Send_Query
  #Editor
  #Btn_Stop
EndEnumeration

Enumeration FormFont
  #Font_Window_0_0
EndEnumeration

LoadFont(#Font_Window_0_0,"Consolas", 10)

Declare ResizeGadgetsWindow_0()


Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  OpenWindow(#Window_0, x, y, width, height, "WMI Query Testing Network", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  CreateStatusBar(0, WindowID(#Window_0))
  AddStatusBarField(600)
  StatusBarText(0, 0, "Ready")
  TextGadget(#Txt_Server, 10, 10, 110, 20, "Server")
  TextGadget(#Txt_User, 130, 10, 100, 20, "User")
  TextGadget(#Txt_Password, 250, 10, 100, 20, "Password")
  TextGadget(#Txt_Query, 370, 10, 100, 20, "Query")
  StringGadget(#Str_Server, 10, 30, 110, 25, "")
  StringGadget(#Str_User, 130, 30, 110, 25, "")
  StringGadget(#Str_Password, 250, 30, 110, 25, "", #PB_String_Password)
  StringGadget(#Str_Query, 370, 30, 220, 25, "service list")
  ButtonGadget(#Btn_Send_Query, 370, 60, 80, 25, "Send Query")
  EditorGadget(#Editor, 10, 90, 580, 280)
  SetGadgetFont(#Editor, FontID(#Font_Window_0_0))
  ButtonGadget(#Btn_Stop, 510, 60, 80, 25, "Stop")
EndProcedure

Procedure ResizeGadgetsWindow_0()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(#Window_0)
  FormWindowHeight = WindowHeight(#Window_0)
  ResizeGadget(#Str_Query, 370, 30, FormWindowWidth - 380, 25)
  ResizeGadget(#Editor, 10, 90, FormWindowWidth - 20, FormWindowHeight - StatusBarHeight(0) - 97)
  ResizeGadget(#Btn_Stop, 510, 60, FormWindowWidth - 520, 25)
EndProcedure
; --- end of form -----------------------------------------------------------------------

Procedure Send_Query(*Value)
    Debug "Send_Query()"
    StatusBarText(0, 0, "Please Wait...")
    Protected Server$   = GetGadgetText(#Str_Server)
    Protected User$     = GetGadgetText(#Str_User)
    Protected Password$ = GetGadgetText(#Str_Password)
    Protected Query$    = GetGadgetText(#Str_Query)
   
    Protected Full_Line$ = "/node:"         + Chr(34) + Server$     + Chr(34) +
                           " /user:"        + Chr(34) + User$       + Chr(34) +
                           " /password:"    + Chr(34) + Password$   + Chr(34) +
                           " "              + Query$
    Debug "Command Line: wmic " + Full_Line$
   
    Protected Run =  RunProgram("wmic", Full_Line$, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
    If Run
        StatusBarText(0, 0, "Running Query...Please Wait a few seconds...")
        While ProgramRunning(Run)
            If AvailableProgramOutput(Run)
                AddGadgetItem(#Editor, -1, ReadProgramString(Run))
            EndIf
        Wend   
        StatusBarText(0, 0, "Done.")
    Else
        StatusBarText(0, 0, "Error.")
    EndIf
EndProcedure

OpenWindow_0()

Repeat
    Select WaitWindowEvent()       
        Case #PB_Event_Gadget   
            Select EventGadget()
                Case #Btn_Send_Query
                    Define ID = CreateThread(@Send_Query(), 1)
                    ;Send_Query(1)
                Case #Btn_Stop
                    If IsThread(ID)
                        KillThread(ID)
                    EndIf
            EndSelect     
           
        Case #PB_Event_Timer     
           
        Case #PB_Event_CloseWindow     
            End
           
        Case #PB_Event_SizeWindow   
            ResizeGadgetsWindow_0()
           
    EndSelect
ForEver

End
Tested of course. (Je n'ai pas traité les accents, mais on peut le faire.)

Enjoy

:wink:

(edit: moved in Tricks 'n' Tips)

_________________
(English is not my native language, I use an online translator.)


Last edited by Marc56us on Sun Mar 08, 2020 10:06 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: wmic small GUI
PostPosted: Thu Nov 07, 2019 7:16 pm 
Offline
User
User

Joined: Wed Nov 06, 2019 10:28 am
Posts: 73
Simple and effective solution. I like it :)
I hope I will be able to do the same with Win API.


Top
 Profile  
Reply with quote  
 Post subject: Re: wmic small GUI
PostPosted: Sat Nov 09, 2019 12:41 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4747
Location: Lyon - France
Works great on W10 :wink:
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye