Jump to content

Using C# and VB Code in AutoIt through .NET Framework


LarsJ
 Share

Recommended Posts

just for completeness sake, I made sure the CLR worked as expected, it does, and I think I have my question answered with one of your UDFs I was pointed to in another thread

#include ".\Includes\CLR.au3"

_Example()

Func _Example()

    Local $oAssemblyCSharp = _CLR_CompileCSharp( FileRead( "Program.cs" ), "Microsoft.CSharp.dll | System.dll | System.Core.dll | System.Data.dll | System.Windows.Forms.dll | System.Data.DataSetExtensions.dll | System.Net.Http.dll | System.Xml.dll | System.Xml.Linq.dll" ) ; You must add the "System.Windows.Forms.dll"
    If @error Then Return ConsoleWrite( "DotNet_LoadCScode ERR" & @CRLF ) ; assembly because of line 1 in the C# code.
    ConsoleWrite( "DotNet_LoadCScode OK" & @CRLF )
  
  Local $oFoo = _CLR_CreateObject($oAssemblyCSharp, "Foo")
  
    ;Local $oFoo = DotNet_CreateObject( $oCode, "Foo" ) ; $oFoo is an object of the "Foo" class in the C# code
    Local $str[2] = ["d:\", "*.rul"]
;    ConsoleWrite("Argument 1: " & $str[0] & @CRLF)
;    ConsoleWrite("Argument 2: " & $str[1] & @CRLF)

   If IsObj( $oFoo ) Then $oFoo.Test("d:\", "*.pdf")  ; Test is a method (function) of the $oFoo object


EndFunc   ;==>_Example
 DotNet_LoadCScode OK
d:\Silas_Marner.pdf
Access to the path 'd:\$RECYCLE.BIN\S-1-5-18' is denied.
Access to the path 'd:\$RECYCLE.BIN\S-1-5-21-1413502519-275084148-3136176451-1001' is denied.
Access to the path 'd:\OneDriveTemp\S-1-5-21-2603686496-927448665-3859144988-1001' is denied.
Access to the path 'd:\System Volume Information' is denied.
Access to the path 'd:\$RECYCLE.BIN\S-1-5-21-2603686496-927448665-3859144988-1001' is denied.
Access to the path 'd:\$RECYCLE.BIN\S-1-5-21-471186804-2718147522-1210400304-1001' is denied.
Access to the path 'd:\$RECYCLE.BIN\S-1-5-21-471186804-2718147522-1210400304-1004' is denied.
d:\OneDrive\Music\Acoustic Alchemy\Roseland\Digital Booklet - Roseland.pdf
d:\OneDrive\Documents\atlassian-git-cheatsheet.pdf
d:\OneDrive\Documents\Effective GUI Testing Automation.pdf
d:\OneDrive\Documents\Getting_Started_With_ABS.pdf
d:\OneDrive\Documents\ICJuliusCaesarWeb.pdf
d:\OneDrive\Documents\IS-CHS-Common-MSI-Conditions.pdf
d:\OneDrive\Documents\Notepad++ Cheat Sheet.pdf
d:\OneDrive\Documents\PFC INV 2008 Ebook.pdf
d:\OneDrive\Documents\reliable-thermal-management-for-military-embedded-systems.whitepaperpdf.render.pdf
d:\OneDrive\Documents\Ubuntu_Cheat_Sheet.pdf
d:\OneDrive\Documents\UIB_FV2011-3725(1 0).pdf
d:\OneDrive\Documents\usersguide.pdf
d:\OneDrive\Documents\wgr614v6_ref_man_20Apr05.pdf
d:\OneDrive\Documents\WhitePaper-IS-Designing-Update-Friendly-MSI-Installation.pdf
d:\OneDrive\Documents\wp_is_UsingChainedMSIs.pdf
d:\OneDrive\Documents\XamarinFormsBook-Ch01-Apr2016.pdf
d:\OneDrive\Music\Books\02-19- Digital Booklet Bach Unaccomp.pdf
d:\OneDrive\Music\Collegium Vocale Gent & Philippe Herrewe\Monteverdi_ Vespro della Beata Vergine\Digital Booklet - Monteverdi_ Vespro.pdf
d:\OneDrive\Music\Feist\Metals (Amazon MP3 Exclusive Version) [+Digital Booklet]\14 - Digital Booklet_ Metals.pdf
d:\OneDrive\Music\Kaskade - Fire & Ice\Kaskade - Fire & Ice Booklet.pdf
d:\OneDrive\Music\Miles Davis\Sketches of Spain (50th Anniversary Lega\Digital Booklet - Sketches Of Spain.pdf
d:\OneDrive\Music\Nightmare Before Christmas (Special Edit\Digital Booklet - Nightmare Before C.pdf
d:\OneDrive\Music\Rush\Clockwork Angels [+digital booklet]\13 - Digital Booklet_ Clockwork Angels.pdf
d:\OneDrive\Music\Silversun Pickups\Better Nature\Digital Booklet - Better Nature.pdf
d:\OneDrive\Music\Smash Mouth\Magic (Deluxe Edition) [+digital booklet]\18 - Digital Booklet_ Magic.pdf
d:\OneDrive\Music\They Might Be Giants\The Spine Surfs Alone\TMBG_The_Spine_Surfs_Alone__Full_Album_Download__08_Art.pdf
d:\OneDrive\Music\They Might Be Giants\The Spine Surfs Alone\TMBG_The_Spine_Surfs_Alone__Full_Album_Download__09_Art.pdf
d:\OneDrive\Music\U2\Songs of Innocence\Digital Booklet - Songs of Innocence.pdf
d:\OneDrive\Work Portable Apps\PDF-XChangeEditorPortable\App\PDFXEdit\PDF_VE.pdf
d:\OneDrive\Work Portable Apps\PDF-XChangeEditorPortable\App\PDFXEdit\Help\PDFXVE6Sm.pdf
d:\OneDrive\Work Portable Apps\PDF-XChangeEditorPortable\App\PDFXEdit\Stamps\ENU\DynamicDate.pdf
Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

To be able to pass an AutoIt array to C# or VB.NET the C#/VB variable to receive the array must be an array of objects. An AutoIt array is an array of variants (a safearray). The corresponding C#/VB variable is an array of objects. I think that's all.

Link to comment
Share on other sites

Passing variables and arrays

Passing variables and arrays back and forth between AutoIt code and C#/VB.NET is demonstrated in examples in UsingCSandVB.7z as you can find in bottom of first post. There are two set of examples: A set with C# code and a set with VB code. You can find the examples in these folders:

  • Examples\1) Introductory C# and VB examples\
    • 3) Passing variables\
      • 1) From AutoIt to C# or VB\
      • 2) From C# or VB to AutoIt\
    • 4) Passing 1D arrays\
      • 1) From AutoIt to C# or VB\
      • 2) From C# or VB to AutoIt\
    • 5) Passing 2D arrays\
      • 1) From AutoIt to C# or VB\
      • 2) From C# or VB to AutoIt\
Link to comment
Share on other sites

Running PowerShell Scripts
This example as well as the DotNet UDF is a translation of a corresponding AutoHotkey example and UDF. In particular, the UDF is very nice code. Therefore, the example becomes easy and simple.

PSScripts.cs:

using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;

public class PSClass {
  public string RunScript( string script ) {
    Runspace runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();

    Pipeline pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript( script );
    pipeline.Commands.Add( "Out-String" );

    Collection<PSObject> results = pipeline.Invoke();

    runspace.Close();
    return results[0].ToString();
  }
}

PSScripts.au3:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

;#AutoIt3Wrapper_UseX64=y

Opt( "MustDeclareVars", 1 )

#include "..\..\Includes\DotNetAll.au3"

Example()

Func Example()
  Local $oNetCode = DotNet_LoadCScode( FileRead( "PSScripts.cs" ), "System.Core.dll | C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll" )
  Local $oPSClass = DotNet_CreateObject( $oNetCode, "PSClass" ), $sOutput

  $sOutput = $oPSClass.RunScript( "echo hello" )
  ConsoleWrite( $sOutput )

  $sOutput = $oPSClass.RunScript( "$PSVersionTable" )
  ConsoleWrite( $sOutput )

  $sOutput = $oPSClass.RunScript( "Get-Service" )
  ConsoleWrite( $sOutput )

  $sOutput = $oPSClass.RunScript( "Get-HotFix" )
  ConsoleWrite( $sOutput )

  $sOutput = $oPSClass.RunScript( FileRead( "Arrays.ps1" ) )
  ConsoleWrite( $sOutput )

  $sOutput = $oPSClass.RunScript( FileRead( "Hash.ps1" ) )
  ConsoleWrite( $sOutput )
EndFunc

Arrays.ps1:

$myList = 5.6, 4.5, 3.3, 13.2, 4.0, 34.33, 34.0, 45.45, 99.993, 11123

echo "Print all the array elements"
$myList

echo "Get the length of array"
$myList.Length

echo "Get Second element of array"
$myList[1]

echo "Get partial array"
$subList = $myList[1..3]

echo "Print subList"
$subList

echo "Using for loop"
for ($i = 0; $i -le ($myList.length - 1); $i += 1) {
  $myList[$i]
}

echo "Using foreach loop"
foreach ($element in $myList) {
  $element
}

echo "Using while loop"
$i = 0
while($i -lt 4) {
  $myList[$i];
  $i++
}

echo "Assign values"
$myList[1] = 10
$myList

echo ""

Hash.ps1:

$hash = @{ ID = 1; Shape = "Square"; Color = "Blue"}

echo "Print all hashtable keys"
$hash.keys

echo "Print all hashtable values"
$hash.values

echo "Get ID"
$hash["ID"]

echo "Get Shape"
$hash.Number

echo "Print size"
$hash.Count

echo "Add key-value"
$hash["Updated"] = "Now"

echo "Add key-value"
$hash.Add("Created","Now")

echo "Print size"
$hash.Count

echo "Remove key-value"
$hash.Remove("Updated")

echo "Print size"
$hash.Count

echo "Sort by key"
$hash.GetEnumerator() | Sort-Object -Property key

echo ""

Output:

hello

Name                           Value                  
----                           -----                  
PSVersion                      5.1.19041.1237         
PSEdition                      Desktop                
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1237        
CLRVersion                     4.0.30319.42000        
WSManStackVersion              3.0                    
PSRemotingProtocolVersion      2.3                    
SerializationVersion           1.1.0.1                



Status   Name               DisplayName                           
------   ----               -----------                           
Stopped  AJRouter           AllJoyn Router Service                
Stopped  ALG                Application Layer Gateway Service     
Stopped  AntiVirMailService Avira Mail Protection                 
Running  AntivirProtecte... Avira Protected Service               
Running  AntiVirSchedule... Avira Scheduler                       
Running  AntiVirService     Avira Real-Time Protection            
Stopped  AntiVirWebService  Avira Web Protection                  
Running  AppHostSvc         Application Host Helper Service       
Stopped  AppIDSvc           Application Identity                  
Running  Appinfo            Application Information               
Stopped  AppMgmt            Application Management                
Stopped  AppReadiness       App Readiness                         
Stopped  AppVClient         Microsoft App-V Client                
Running  AppXSvc            AppX Deployment Service (AppXSVC)     
Stopped  aspnet_state       ASP.NET State Service                 
Stopped  AssignedAccessM... AssignedAccessManager Service         
Running  AudioEndpointBu... Windows Audio Endpoint Builder        
Running  Audiosrv           Windows Audio                         
Stopped  autotimesvc        Cellular Time                         
Running  AviraOptimizerHost Avira Optimizer Host                  
Running  AviraPhantomVPN    Avira Phantom VPN                     
Running  AviraSecurity      Avira Security                        
Stopped  AviraSecurityUp... Avira Security Updater                
Running  AviraUpdaterSer... Avira Updater Service                 
Stopped  AxInstSV           ActiveX Installer (AxInstSV)          
Running  Backupper Service  AOMEI Backupper Scheduler Service     
Running  BcastDVRUserSer... GameDVR and Broadcast User Service_...
Stopped  BDESVC             BitLocker Drive Encryption Service    
Running  BFE                Base Filtering Engine                 
Running  BITS               Background Intelligent Transfer Ser...
Stopped  BluetoothUserSe... Bluetooth User Support Service_58ee4  
Running  BrokerInfrastru... Background Tasks Infrastructure Ser...
Running  Browser            Computer Browser                      
Stopped  BTAGService        Bluetooth Audio Gateway Service       
Running  BthAvctpSvc        AVCTP service                         
Stopped  bthserv            Bluetooth Support Service             
Running  camsvc             Capability Access Manager Service     
Stopped  CaptureService_... CaptureService_58ee4                  
Running  cbdhsvc_58ee4      Clipboard User Service_58ee4          
Running  CDPSvc             Connected Devices Platform Service    
Running  CDPUserSvc_58ee4   Connected Devices Platform User Ser...
Stopped  CertPropSvc        Certificate Propagation               
Running  ClipSVC            Client License Service (ClipSVC)      
Stopped  COMSysApp          COM+ System Application               
Stopped  ConsentUxUserSv... ConsentUX_58ee4                       
Running  CoreMessagingRe... CoreMessaging                         
Running  cphs               Intel(R) Content Protection HECI Se...
Running  cplspcon           Intel(R) Content Protection HDCP Se...
Stopped  CredentialEnrol... CredentialEnrollmentManagerUserSvc_...
Running  CryptSvc           Cryptographic Services                
Running  CscService         Offline Files                         
Running  DcomLaunch         DCOM Server Process Launcher          
Stopped  defragsvc          Optimize drives                       
Stopped  DeviceAssociati... DeviceAssociationBroker_58ee4         
Running  DeviceAssociati... Device Association Service            
Stopped  DeviceInstall      Device Install Service                
Stopped  DevicePickerUse... DevicePicker_58ee4                    
Stopped  DevicesFlowUser... DevicesFlow_58ee4                     
Stopped  DevQueryBroker     DevQuery Background Discovery Broker  
Running  Dhcp               DHCP Client                           
Stopped  diagnosticshub.... Microsoft (R) Diagnostics Hub Stand...
Stopped  diagsvc            Diagnostic Execution Service          
Running  DiagTrack          Connected User Experiences and Tele...
Stopped  DialogBlockingS... DialogBlockingService                 
Running  DispBrokerDeskt... Display Policy Service                
Stopped  DisplayEnhancem... Display Enhancement Service           
Stopped  DmEnrollmentSvc    Device Management Enrollment Service  
Stopped  dmwappushservice   Device Management Wireless Applicat...
Running  Dnscache           DNS Client                            
Stopped  DoSvc              Delivery Optimization                 
Stopped  dot3svc            Wired AutoConfig                      
Running  DPS                Diagnostic Policy Service             
Stopped  DsmSvc             Device Setup Manager                  
Stopped  DsSvc              Data Sharing Service                  
Running  DusmSvc            Data Usage                            
Stopped  Eaphost            Extensible Authentication Protocol    
Stopped  edgeupdate         Microsoft Edge Update Service (edge...
Stopped  edgeupdatem        Microsoft Edge Update Service (edge...
Stopped  EFS                Encrypting File System (EFS)          
Stopped  embeddedmode       Embedded Mode                         
Stopped  EntAppSvc          Enterprise App Management Service     
Running  EventLog           Windows Event Log                     
Running  EventSystem        COM+ Event System                     
Stopped  Fax                Fax                                   
Running  fdPHost            Function Discovery Provider Host      
Running  FDResPub           Function Discovery Resource Publica...
Stopped  fhsvc              File History Service                  
Running  FontCache          Windows Font Cache Service            
Running  FontCache3.0.0.0   Windows Presentation Foundation Fon...
Stopped  FrameServer        Windows Camera Frame Server           
Stopped  GoogleChromeEle... Google Chrome Elevation Service (Go...
Running  gpsvc              Group Policy Client                   
Stopped  GraphicsPerfSvc    GraphicsPerfSvc                       
Stopped  gupdate            Google Update Tjeneste (gupdate)      
Stopped  gupdatem           Google Update Tjeneste (gupdatem)     
Running  hidserv            Human Interface Device Service        
Stopped  HvHost             HV Host Service                       
Stopped  icssvc             Windows Mobile Hotspot Service        
Running  igfxCUIService2... Intel(R) HD Graphics Control Panel ...
Stopped  IKEEXT             IKE and AuthIP IPsec Keying Modules   
Running  InstallService     Microsoft Store Install Service       
Running  iphlpsvc           IP Helper                             
Running  IpOverUsbSvc       Windows Phone IP over USB Transport...
Stopped  IpxlatCfgSvc       IP Translation Configuration Service  
Running  KeyIso             CNG Key Isolation                     
Stopped  KtmRm              KtmRm for Distributed Transaction C...
Running  LanmanServer       Server                                
Running  LanmanWorkstation  Workstation                           
Running  lfsvc              Geolocation Service                   
Running  LicenseManager     Windows License Manager Service       
Stopped  lltdsvc            Link-Layer Topology Discovery Mapper  
Running  lmhosts            TCP/IP NetBIOS Helper                 
Running  LSM                Local Session Manager                 
Stopped  LxpSvc             Language Experience Service           
Stopped  MapsBroker         Downloaded Maps Manager               
Stopped  MessagingServic... MessagingService_58ee4                
Stopped  MicrosoftEdgeEl... Microsoft Edge Elevation Service (M...
Stopped  MixedRealityOpe... Windows Mixed Reality OpenXR Service  
Stopped  MozillaMaintenance Mozilla Maintenance Service           
Running  mpssvc             Windows Defender Firewall             
Stopped  MSDTC              Distributed Transaction Coordinator   
Stopped  MSiSCSI            Microsoft iSCSI Initiator Service     
Stopped  msiserver          Windows Installer                     
Stopped  MsKeyboardFilter   Microsoft Keyboard Filter             
Running  MSMQ               Message Queuing                       
Stopped  NaturalAuthenti... Natural Authentication                
Stopped  NcaSvc             Network Connectivity Assistant        
Running  NcbService         Network Connection Broker             
Running  NcdAutoSetup       Network Connected Devices Auto-Setup  
Stopped  Netlogon           Netlogon                              
Stopped  Netman             Network Connections                   
Running  NetMsmqActivator   Net.Msmq Listener Adapter             
Running  NetPipeActivator   Net.Pipe Listener Adapter             
Running  netprofm           Network List Service                  
Stopped  NetSetupSvc        Network Setup Service                 
Running  NetTcpActivator    Net.Tcp Listener Adapter              
Running  NetTcpPortSharing  Net.Tcp Port Sharing Service          
Stopped  NgcCtnrSvc         Microsoft Passport Container          
Stopped  NgcSvc             Microsoft Passport                    
Running  NlaSvc             Network Location Awareness            
Running  nsi                Network Store Interface Service       
Running  OneSyncSvc_58ee4   Sync Host_58ee4                       
Stopped  p2pimsvc           Peer Networking Identity Manager      
Stopped  p2psvc             Peer Networking Grouping              
Running  PcaSvc             Program Compatibility Assistant Ser...
Stopped  PeerDistSvc        BranchCache                           
Stopped  perceptionsimul... Windows Perception Simulation Service 
Stopped  PerfHost           Performance Counter DLL Host          
Stopped  PhoneSvc           Phone Service                         
Stopped  PimIndexMainten... Contact Data_58ee4                    
Stopped  pla                Performance Logs & Alerts             
Running  PlugPlay           Plug and Play                         
Stopped  PNRPAutoReg        PNRP Machine Name Publication Service 
Stopped  PNRPsvc            Peer Name Resolution Protocol         
Stopped  PolicyAgent        IPsec Policy Agent                    
Running  Power              Power                                 
Stopped  PrintNotify        Printer Extensions and Notifications  
Stopped  PrintWorkflowUs... PrintWorkflow_58ee4                   
Running  ProfSvc            User Profile Service                  
Stopped  PushToInstall      Windows PushToInstall Service         
Stopped  QWAVE              Quality Windows Audio Video Experience
Stopped  RasAuto            Remote Access Auto Connection Manager 
Running  RasMan             Remote Access Connection Manager      
Stopped  RemoteAccess       Routing and Remote Access             
Stopped  RemoteRegistry     Remote Registry                       
Stopped  RetailDemo         Retail Demo Service                   
Running  RmSvc              Radio Management Service              
Running  RpcEptMapper       RPC Endpoint Mapper                   
Stopped  RpcLocator         Remote Procedure Call (RPC) Locator   
Running  RpcSs              Remote Procedure Call (RPC)           
Running  SamSs              Security Accounts Manager             
Stopped  SCardSvr           Smart Card                            
Stopped  ScDeviceEnum       Smart Card Device Enumeration Service 
Running  Schedule           Task Scheduler                        
Stopped  SCPolicySvc        Smart Card Removal Policy             
Stopped  SDRSVC             Windows Backup                        
Stopped  seclogon           Secondary Logon                       
Running  SecurityHealthS... Windows Security Service              
Stopped  SEMgrSvc           Payments and NFC/SE Manager           
Running  SENS               System Event Notification Service     
Stopped  Sense              Windows Defender Advanced Threat Pr...
Stopped  SensorDataService  Sensor Data Service                   
Stopped  SensorService      Sensor Service                        
Stopped  SensrSvc           Sensor Monitoring Service             
Stopped  SessionEnv         Remote Desktop Configuration          
Running  SgrmBroker         System Guard Runtime Monitor Broker   
Stopped  SharedAccess       Internet Connection Sharing (ICS)     
Stopped  SharedRealitySvc   Spatial Data Service                  
Running  ShellHWDetection   Shell Hardware Detection              
Stopped  shpamsvc           Shared PC Account Manager             
Stopped  smphost            Microsoft Storage Spaces SMP          
Stopped  SmsRouter          Microsoft Windows SMS Router Service. 
Running  SNMP               SNMP Service                          
Stopped  SNMPTRAP           SNMP Trap                             
Stopped  spectrum           Windows Perception Service            
Running  Spooler            Print Spooler                         
Stopped  sppsvc             Software Protection                   
Running  SSDPSRV            SSDP Discovery                        
Stopped  ssh-agent          OpenSSH Authentication Agent          
Running  SstpSvc            Secure Socket Tunneling Protocol Se...
Running  StateRepository    State Repository Service              
Stopped  stisvc             Windows Image Acquisition (WIA)       
Running  StorSvc            Storage Service                       
Stopped  svsvc              Spot Verifier                         
Running  swprv              Microsoft Software Shadow Copy Prov...
Running  SysMain            SysMain                               
Running  SystemEventsBroker System Events Broker                  
Running  TabletInputService Touch Keyboard and Handwriting Pane...
Stopped  TapiSrv            Telephony                             
Stopped  Te.Service         Te.Service                            
Stopped  TermService        Remote Desktop Services               
Running  Themes             Themes                                
Stopped  TieringEngineSe... Storage Tiers Management              
Running  TimeBrokerSvc      Time Broker                           
Running  TokenBroker        Web Account Manager                   
Running  TrkWks             Distributed Link Tracking Client      
Stopped  TroubleshootingSvc Recommended Troubleshooting Service   
Stopped  TrustedInstaller   Windows Modules Installer             
Stopped  tzautoupdate       Auto Time Zone Updater                
Running  UdkUserSvc_58ee4   Udk User Service_58ee4                
Stopped  UevAgentService    User Experience Virtualization Service
Stopped  uhssvc             Microsoft Update Health Service       
Stopped  UmRdpService       Remote Desktop Services UserMode Po...
Stopped  UnistoreSvc_58ee4  User Data Storage_58ee4               
Stopped  upnphost           UPnP Device Host                      
Stopped  UserDataSvc_58ee4  User Data Access_58ee4                
Running  UserManager        User Manager                          
Running  UsoSvc             Update Orchestrator Service           
Stopped  VacSvc             Volumetric Audio Compositor Service   
Running  VaultSvc           Credential Manager                    
Stopped  vds                Virtual Disk                          
Stopped  vmicguestinterface Hyper-V Guest Service Interface       
Stopped  vmicheartbeat      Hyper-V Heartbeat Service             
Stopped  vmickvpexchange    Hyper-V Data Exchange Service         
Stopped  vmicrdv            Hyper-V Remote Desktop Virtualizati...
Stopped  vmicshutdown       Hyper-V Guest Shutdown Service        
Stopped  vmictimesync       Hyper-V Time Synchronization Service  
Stopped  vmicvmsession      Hyper-V PowerShell Direct Service     
Stopped  vmicvss            Hyper-V Volume Shadow Copy Requestor  
Running  VSS                Volume Shadow Copy                    
Stopped  W32Time            Windows Time                          
Stopped  w3logsvc           W3C Logging Service                   
Running  W3SVC              World Wide Web Publishing Service     
Stopped  WalletService      WalletService                         
Stopped  WarpJITSvc         WarpJITSvc                            
Running  WAS                Windows Process Activation Service    
Stopped  wbengine           Block Level Backup Engine Service     
Stopped  WbioSrvc           Windows Biometric Service             
Running  Wcmsvc             Windows Connection Manager            
Stopped  wcncsvc            Windows Connect Now - Config Registrar
Running  WdiServiceHost     Diagnostic Service Host               
Running  WdiSystemHost      Diagnostic System Host                
Stopped  WdNisSvc           Microsoft Defender Antivirus Networ...
Stopped  WebClient          WebClient                             
Stopped  Wecsvc             Windows Event Collector               
Stopped  WEPHOSTSVC         Windows Encryption Provider Host Se...
Stopped  wercplsupport      Problem Reports Control Panel Support 
Stopped  WerSvc             Windows Error Reporting Service       
Stopped  WFDSConMgrSvc      Wi-Fi Direct Services Connection Ma...
Stopped  WiaRpc             Still Image Acquisition Events        
Stopped  WinDefend          Microsoft Defender Antivirus Service  
Running  WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se...
Running  Winmgmt            Windows Management Instrumentation    
Stopped  WinRM              Windows Remote Management (WS-Manag...
Stopped  wisvc              Windows Insider Service               
Stopped  WlanSvc            WLAN AutoConfig                       
Stopped  wlidsvc            Microsoft Account Sign-in Assistant   
Stopped  wlpasvc            Local Profile Assistant Service       
Stopped  WManSvc            Windows Management Service            
Stopped  wmiApSrv           WMI Performance Adapter               
Stopped  WMPNetworkSvc      Windows Media Player Network Sharin...
Stopped  workfolderssvc     Work Folders                          
Stopped  WpcMonSvc          Parental Controls                     
Stopped  WPDBusEnum         Portable Device Enumerator Service    
Running  WpnService         Windows Push Notifications System S...
Running  WpnUserService_... Windows Push Notifications User Ser...
Running  wscsvc             Security Center                       
Running  WSearch            Windows Search                        
Running  wuauserv           Windows Update                        
Stopped  WwanSvc            WWAN AutoConfig                       
Running  WaaSMedicSvc       Windows Update Medic Service          
Running  XblAuthManager     Xbox Live Auth Manager                
Stopped  XblGameSave        Xbox Live Game Save                   
Stopped  XboxGipSvc         Xbox Accessory Management Service     
Stopped  XboxNetApiSvc      Xbox Live Networking Service          
Stopped  AarSvc_58ee4       Agent Activation Runtime_58ee4        



Source        Description      HotFixID      InstalledBy          InstalledOn        
------        -----------      --------      -----------          -----------        
ZITECHWIN1... Update           KB5004331     NT AUTHORITY\SYSTEM  21-09-2021 00:00:00
ZITECHWIN1... Update           KB4577586     NT AUTHORITY\SYSTEM  27-06-2021 00:00:00
ZITECHWIN1... Security Update  KB5005565     NT AUTHORITY\SYSTEM  21-09-2021 00:00:00
ZITECHWIN1... Security Update  KB5005699     NT AUTHORITY\SYSTEM  21-09-2021 00:00:00


Print all the array elements
5,6
4,5
3,3
13,2
4
34,33
34
45,45
99,993
11123
Get the length of array
10
Get Second element of array
4,5
Get partial array
Print subList
4,5
3,3
13,2
Using for loop
5,6
4,5
3,3
13,2
4
34,33
34
45,45
99,993
11123
Using foreach loop
5,6
4,5
3,3
13,2
4
34,33
34
45,45
99,993
11123
Using while loop
5,6
4,5
3,3
13,2
Assign values
5,6
10
3,3
13,2
4
34,33
34
45,45
99,993
11123

Print all hashtable keys
Color
Shape
ID
Print all hashtable values
Blue
Square
1
Get ID
1
Get Shape
Print size
3
Add key-value
Add key-value
Print size
5
Remove key-value
Print size
4
Sort by key

Name                           Value 
----                           ----- 
Color                          Blue  
Created                        Now   
ID                             1     
Shape                          Square

The code has been tested on Windows 10. Doesn't work on Windows 7.

All code in Examples\6) Running PowerShell Scripts.

New zip-file at bottom of first post.

Edited by LarsJ
SciTE output
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...