Windows system agent-free remote script execution method and device and computer equipment

By configuring the remote execution environment of the Windows system and selecting an appropriate script execution method, the problem in the existing technology of being unable to achieve stable, safe, and flexible remote execution of scripts without an agent is solved, and efficient and safe automated operation and maintenance are achieved. .

CN119356949AActive Publication Date: 2025-01-24杭州美创科技股份有限公司
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411940374.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-01-24
Estimated Expiration
2044-12-26

AI Technical Summary

Technical Problem

The existing Windows system remote script execution method has shortcomings in some scenarios, such as the inability to achieve stable, secure and flexible remote execution without additional installation and configuration, especially when executing complex PowerShell scripts or programs with GUI interfaces. There are restrictions when there are.

Method used

By configuring the remote execution environment of the Windows system, including setting up identity authentication, selecting the script execution method, configuring the WinRM service, initializing the remote connection and performing connection testing, selecting the execution method according to the script's storage location and type, and finally running the script according to the execution method. and process the execution results.

Benefits of technology

It achieves a more stable, secure and flexible remote execution capability without additional installation and configuration, improves the efficiency of automated operation and maintenance, and solves the security risks and resource consumption problems existing in traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119356949A_ABST
    Figure CN119356949A_ABST
Patent Text Reader

Abstract

The invention discloses an agent-free remote script execution method and device for a windows system and computer equipment. The method comprises the following steps: configuring a remote execution environment of the Windows system, including setting identity authentication, selecting a script execution mode, and configuring WinRM service when the script execution mode is selected; initializing remote connection and carrying out connection testing; selecting an execution method of the script according to the storage position and the script type of the script; and executing the script according to the execution method, and processing a script execution result. By implementing the method provided by the invention, more stable, safer and more flexible remote execution capability can be provided on the premise of no additional installation and configuration, and the efficiency of automatic operation and maintenance is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a script execution method, and more specifically to a Windows system agentless remote script execution method, device and computer equipment. Background Art

[0002] Windows system remote script execution is usually used in batch configuration management, software deployment, system monitoring, troubleshooting and other scenarios. It can help IT administrators efficiently manage and automate multiple servers, especially in large-scale network environments or distributed architectures, and can significantly improve work efficiency and response speed.

[0003] At present, the common methods for remote script execution in Windows systems include SSH-based methods, third-party automation tools, and WinRM (Windows Remote Management). For SSH-based methods, although the SSH protocol is usually associated with Linux systems, Microsoft has integrated OpenSSH client and server components in Windows 10 and above, allowing Windows users to perform secure remote command execution and file transfer through the SSH protocol. However, this method may require manual installation and configuration of the SSH service in some older versions of Windows systems, which adds additional operational complexity. In addition, this method is prone to improper configuration, which can easily lead to security vulnerabilities and increase security risks. For remote execution using third-party automation tools, tools such as Puppet, Ansible Tower (part of Red Hat Ansible Engine), and SaltStack can generally be used. They provide advanced functions and can perform automated operations such as software deployment and configuration management on multiple Windows servers. These tools usually require the installation of an agent on the target machine. However, the agent in this way needs to run for a long time, which may consume additional CPU and memory resources, especially in large-scale environments, which may become a performance bottleneck. Some tools are commercial software and require the purchase of a license to use all their functions, increasing operation and maintenance costs. The third method, WinRM, is a protocol launched by Microsoft for remote management of Windows systems. It allows the execution of commands and scripts over the network and is widely used in automated operation and maintenance tasks. However, in some scenarios, WinRM may have limitations on PowerShell scripts that execute complex logic and cannot fully meet the needs. If a program with a graphical interface is running, the program may stop and cannot continue to execute when the remote connection is interrupted.

[0004] Although the existing Windows remote script execution method can meet the needs of automated operation and maintenance to a certain extent, it still has shortcomings in some scenarios. For example, when the Windows host cannot install the agent program or OpenSSH component, the existing method may fail; in addition, in some cases, WinRM has limited support for executing complex PowerShell scripts or programs with GUI interfaces.

[0005] Therefore, it is necessary to design a new method to provide more stable, secure, and flexible remote execution capabilities without additional installation and configuration, and to further improve the efficiency of automated operation and maintenance. Summary of the invention

[0006] The purpose of the present invention is to overcome the defects of the prior art and provide a method, device and computer equipment for executing a remote script without an agent in a Windows system.

[0007] To achieve the above object, the present invention adopts the following technical solution: a Windows system agentless remote script execution method, comprising: Configure the Windows system remote execution environment, including setting identity authentication, selecting the script execution method, and configuring the WinRM service when selecting the script execution method; Initialize remote connection and perform connection test; Selecting a script execution method according to the script storage location and script type; The script is executed according to the execution method, and the result of the script execution is processed.

[0008] The further technical solution is: the configuration of the Windows system remote execution environment includes setting identity authentication, selecting the script execution mode and configuring the WinRM service, including: Setting the identity authentication of the executing user, wherein the identity authentication of the executing user includes a common user or a domain user; Select a script execution mode, wherein the script execution mode includes a non-encrypted service or an SSL encrypted service, and configure a WinRM service when selecting the script execution mode.

[0009] The further technical solution is: configuring the WinRM service when selecting the script execution mode includes: Log in to the Windows server with administrator privileges and start PowerShell; Run the winrm quickconfig -quiet command to quickly configure the WinRM service; Enable Basic Authentication; When you need to allow unencrypted communication, run the PowerShell command to configure the Windows Remote Management service; Set the maximum number of shells that each user can open simultaneously; Set the maximum memory usage for each shell; Configure WinRM listening port; When SSL encryption service is required, write and execute a .ps1 script, which should contain all the configuration steps and run the script with administrator privileges.

[0010] A further technical solution is as follows: the initializing remote connection and performing connection test comprises: Determine whether a lock needs to be created according to the identity authentication, and create a lock when necessary, wherein the lock is used to limit concurrent execution; Check whether the system currently has an established remote connection session; Start a shell on the remote host and run the connection test script to get the test execution results; Reuse the connection or close the remote connection session according to the test execution result.

[0011] A further technical solution is: the method for executing the script is selected according to the storage location and script type of the script, including: Obtaining a storage location of the script and a type of the script, wherein the storage location of the script includes a target host or a remote execution system, and the type of the script includes PowerShell or non-PowerShell; If the PowerShell script is stored in the remote system, use the base64 encoding execution method; if the PowerShell script is stored in the target system, call the PowerShell command execution method, and use the Invoke-Expression method for non-PowerShell scripts.

[0012] The further technical solution is: if the PowerShell script is stored in the remote system, the base64 encoding execution method is used; if the PowerShell script is stored in the target system, the PowerShell command execution method is called, and after the non-PowerShell script uses the Invoke-Expression method, it also includes: For programs with GUI interfaces, create a scheduled task to solve the problem of program exit after the remote connection is disconnected, and use the scheduled task to trigger script execution.

[0013] A further technical solution is: executing the script according to the execution method and processing the result of the script execution includes: The script is executed according to the execution method, and the result of the script execution is processed in a synchronous or asynchronous manner; the synchronous manner is to wait for the result to be returned after the execution is completed, and the asynchronous manner is to dynamically obtain the output result in real time.

[0014] The present invention also provides a Windows system agent-free remote script execution device, comprising: Configuration unit, used to configure the Windows system remote execution environment, including setting identity authentication, selecting the script execution mode, and configuring the WinRM service when the script execution mode is selected; Initialization unit, used to initialize remote connection and perform connection test; A selection unit, used to select an execution method of the script according to the storage location and script type of the script; An execution processing unit is used to execute the script according to the execution method and process the result of the script execution.

[0015] The present invention further provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor implements the above method when executing the computer program.

[0016] The present invention also provides a storage medium, wherein the storage medium stores a computer program, and the computer program implements the above method when executed by a processor.

[0017] Compared with the prior art, the present invention has the following beneficial effects: the present invention configures the remote execution environment of the Windows system, sets identity authentication and selects a suitable script execution method, including configuring the WinRM service. Initializes the remote connection and performs a connection test to ensure that the connection is stable, selects the execution method according to the script type and storage location, and finally runs the script according to the execution method and processes the execution result, ensuring efficient and stable automated operation and maintenance, and providing a more stable, secure and flexible remote execution capability without additional installation and configuration, thereby further improving the efficiency of automated operation and maintenance.

[0018] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0020] Figure 1A flowchart of a method for executing a remote script without an agent in a Windows system provided by an embodiment of the present invention; Figure 2 A schematic diagram of a sub-process of a Windows system agentless remote script execution method provided by an embodiment of the present invention; Figure 3 A schematic diagram of a sub-process of a Windows system agentless remote script execution method provided by an embodiment of the present invention; Figure 4 A schematic diagram of a sub-process of a Windows system agentless remote script execution method provided by an embodiment of the present invention; Figure 5 A schematic block diagram of a Windows system agentless remote script execution device provided by an embodiment of the present invention; Figure 6 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0022] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0023] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0024] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0025] See also Figure 1 , Figure 1A schematic flow chart of the agentless remote script execution method for Windows system provided by the embodiment of the present invention. By configuring the remote execution environment of the Windows system, including identity authentication and WinRM service, it is ensured that the remote script can be executed without an agent. WinRM is used for quick configuration, and the appropriate script execution method is selected to support non-encrypted and SSL encrypted communications to ensure security. The remote connection passes identity authentication and connection tests to ensure that the connection is stable and reliable. According to the script type and storage location, a suitable execution method is selected to support base64 encoding execution of PowerShell scripts or calling PowerShell commands. Finally, synchronous or asynchronous execution methods are adopted to ensure real-time acquisition of script execution results, thereby improving the efficiency of automated operation and maintenance.

[0026] Figure 1 1 is a flowchart of a Windows system agentless remote script execution method provided by an embodiment of the present invention. Figure 1 As shown, the method includes the following steps S110 to S140.

[0027] S110. Configure the Windows system remote execution environment, including setting identity authentication, selecting a script execution method, and configuring the WinRM service when selecting the script execution method.

[0028] In this embodiment, the configuration of the execution environment mainly determines the identity authentication method and script execution method of the Windows system remote execution, and starts and configures the corresponding WinRM service on the target Windows host.

[0029] In one embodiment, see Figure 2 , the above-mentioned step S110 may include steps S111~S112.

[0030] S111. Setting the identity authentication of the executing user, wherein the identity authentication of the executing user includes a common user or a domain user.

[0031] In this embodiment, a common user or a domain user can be configured as the identity for script execution according to the requirements. Among them, the common user is suitable for a single-machine environment or a small local area network, and the user account is stored in the security account database of the local computer.

[0032] Domain users are suitable for corporate network environments. User accounts are managed by Active Directory and can implement authentication across multiple computers. Domain user usernames usually contain @ or \ characters, such as domain\username or username@domain.com.

[0033] S112. Select a script execution mode, wherein the script execution mode includes a non-encrypted service or an SSL encrypted service, and configure a WinRM service when selecting the script execution mode.

[0034] In this embodiment, when selecting the script execution mode, configuring the WinRM service includes: Log in to the Windows server with administrator privileges and start PowerShell; execute the winrmquickconfig -quiet command to quickly configure the WinRM service; enable basic authentication; when you need to allow non-encrypted communication, run the PowerShell command to configure the Windows Remote Management service; set the maximum number of shells that each user can open simultaneously; set the maximum memory usage for each shell; configure the WinRM listening port; when SSL encryption service is required, write and execute a .ps1 script, which should contain all the configuration steps, and run this script with administrator privileges.

[0035] In this embodiment, in the script remote execution system, the IP address, user name and password of the target Windows host need to be configured, and this information should be encrypted and saved to ensure security. This usually involves back-end development work to ensure that these sensitive information is stored and transmitted in a secure manner.

[0036] In this embodiment, two different configuration methods are provided for the WinRM service: If you choose to use non-encrypted mode (only in a test environment or internal secure network), you can follow the steps below: Log in to the target Windows server and run PowerShell as an administrator. Run the following command to configure the WinRM service: winrm quickconfig –quiet; winrm set winrm / config / service / auth '@{Basic="true"}'; winrm set winrm / config / service '@{AllowUnencrypted="true"}'; Set-Item WSMan:\localhost\Shell\MaxShellsPerUser 100; Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 300; Set-Item WSMan:\localhost\Listener\Listener*\Port 5985; These commands will complete the basic configuration of WinRM, allow unencrypted connections, and set limits on the number of sessions and memory usage.

[0037] For production environments, it is highly recommended to use SSL encryption services for added security. You can create a .ps1 script to simplify this process.

[0038] Replace your.hostname with the actual hostname or IP address. Run PowerShell as an administrator and execute the following command to run the above script: Type c:\enable_winrm_ssl.ps1 | PowerShell.exe -noprofile -; This script will create a self-signed certificate and configure WinRM to use that certificate to communicate over HTTPS port 5986. It will also set up basic authentication and other related parameters.

[0039] In this embodiment, you can select the appropriate authentication method and script execution method according to the actual situation, and correctly configure the WinRM service on the target Windows host. Please ensure that you follow the best practices during the configuration process, especially when handling sensitive information, and take appropriate security measures.

[0040] S120: Initialize remote connection and perform connection test.

[0041] In this embodiment, in the implementation of scenarios such as automated deployment, operation and maintenance management, or remote monitoring, initializing a remote connection and performing a connection test are key steps to ensure that subsequent operations proceed smoothly.

[0042] In one embodiment, see Figure 3 , the above-mentioned step S120 may include steps S121~S124.

[0043] S121. Determine whether a lock needs to be created according to the identity authentication, and create a lock when necessary, wherein the lock is used to limit concurrent execution.

[0044] In this embodiment, before starting the remote operation, it is first necessary to determine whether a lock needs to be created based on the identity authentication type. In the case of using a domain user for identity authentication, considering that multiple machines in the domain environment may simultaneously initiate requests to the same target machine, creating a lock can effectively prevent problems caused by the simultaneous execution of multiple scripts, such as resource competition or data conflicts. The specific method of creating a lock can be to create a temporary file or record on the target machine. When a task starts to execute, first check whether the file or record exists. If it exists, wait until the previous task is completed and the lock is released.

[0045] For ordinary user identity authentication, since it is usually used in a single or a few controlled environments, there is no need to create locks to limit concurrent execution.

[0046] S122: Confirm whether the system currently has an established remote connection session.

[0047] In this embodiment, before trying to establish a new remote connection, it should be checked whether there is an available connection session. If so, the existing session can be directly reused, which not only saves time for re-establishing the connection, but also reduces resource consumption. By checking the status of the session, it can be quickly determined whether the script can be executed immediately, thereby improving overall efficiency.

[0048] S123. Start Shell on the remote host and run the connection test script to obtain the test execution result.

[0049] In this embodiment, once the status of the connection session is determined, the next step is to start a shell on the remote host and execute a simple connection test script. The main purpose of this script is to verify whether the environment on the remote host is suitable for performing subsequent operations. For example, you can test whether the connection is normal by executing a command that outputs a specific string. If the output result is consistent with the expectation, it means that the environment configuration on the remote host is correct and you can continue to perform subsequent tasks; if it is not consistent, you need to further investigate the problem, which may be a network problem, a permission problem, or some configuration on the target host that affects the execution of the script.

[0050] S124: Reuse the connection or close the remote connection session according to the test execution result.

[0051] In this embodiment, whether to keep or close the remote connection session is determined according to the execution result of the connection test script. If the test result shows that everything is normal and it is expected that there will be subsequent operations to be performed, the current connection session can be retained for reuse. However, if the test fails or there is no subsequent operation plan, the connection session should be closed in time to release the occupied resources.

[0052] By reusing existing connection sessions, the time cost of reestablishing connections before each operation is reduced, and the overall efficiency of automated operations is improved. In the case of using domain users, creating locks can avoid security risks caused by concurrent execution of multiple tasks and enhance the security of the system. Reasonable management of the life cycle of connection sessions can effectively utilize network resources and computing resources and avoid unnecessary waste. By executing connection test scripts, potential problems can be discovered at an early stage, avoiding unforeseen errors when formally executing tasks, thereby reducing the failure rate. Whether using ordinary users or domain users for identity authentication, this mechanism can flexibly respond to different usage scenarios, improving the adaptability of the system.

[0053] In summary, initializing and testing remote connections through the above steps can not only improve the efficiency and security of automated operations, but also ensure the effective use of resources, which is a recommended practice.

[0054] S130: Select an execution method for the script according to the storage location and script type of the script.

[0055] In this embodiment, during the remote script execution process, selecting a suitable execution method is crucial to ensure successful execution of the script.

[0056] In one embodiment, see Figure 4 , the above-mentioned step S130 may include steps S131~S133.

[0057] S131, obtaining a storage location of the script and a type of the script, wherein the storage location of the script includes a target host or a remote execution system, and the type of the script includes PowerShell or non-PowerShell.

[0058] In this embodiment, before starting to execute the script, you first need to clarify the storage location of the script (i.e., on which machine the script is stored) and the type of the script (whether it is a PowerShell script or a non-PowerShell script). The storage location of the script determines the subsequent execution method, while the type of the script affects the specific execution command. The storage location of the script can be the target host (i.e., the machine on which the script ultimately needs to be executed) or the remote execution system (i.e., the machine that initiates the remote execution request). The types of scripts are mainly divided into two categories: PowerShell scripts and non-PowerShell scripts.

[0059] S132. If the PowerShell script is stored in the remote system, use the base64 encoding execution method; if the PowerShell script is stored in the target system, call the PowerShell command execution method, and use the Invoke-Expression method for non-PowerShell scripts.

[0060] In this embodiment, when the script is stored in the remote execution system, the script can be executed in Base64 encoding. Specifically, the script content is first converted into a Base64 encoded string, and then executed through the powershell -encodedcommand {Base64 encoded script} command. The advantage of this method is that the script content can be hidden, adding a layer of security protection. However, this method has a limit on the length of the script content, and the length of the encoded script cannot exceed 8164 characters. For scripts that exceed this length, another method needs to be adopted: first create a temporary file in the remote execution system and write the script content to the file; then use the WinRM protocol to upload the temporary file to the specified location on the target host; finally, execute the script content on the target host through the powershell -NoProfile -ExecutionPolicy Bypass {temporary file path} command. After execution is completed, remember to delete the temporary file to clean up resources.

[0061] If the script already exists on the target host, you can simply execute it directly using the powershell -NoProfile -ExecutionPolicy Bypass {path to the script file} command. This method is simple and direct, and does not require additional data transfer.

[0062] For non-PowerShell scripts (such as Windows batch files or EXE programs), you can use the Invoke-Expression "& SCRIPT MYARGS" command to execute. The SCRIPT variable represents the absolute path of the script, and the MYARGS variable represents the parameters passed to the script. To simplify the operation, you can encapsulate the above command into a PowerShell script, determine whether it is a PowerShell script based on whether the configured script path name ends with .ps1, and then call the corresponding execution method.

[0063] S133. For programs with a GUI interface, a scheduled task is created to solve the problem of program exit after the remote connection is disconnected, and the scheduled task is used to trigger script execution.

[0064] In this embodiment, for those programs with a graphical user interface (GUI), the program may automatically exit after the remote connection is disconnected. To solve this problem, a scheduled task can be created on the target host, which triggers and executes the corresponding script under specific conditions. For example, the schtasks / create / tn start_telnet / tr c:\scripts\start_telnet.bat / sc once / st 00:00:00 / sd 2020 / 01 / 01 command can be used to create a scheduled task named start_telnet, which executes the start_telnet.bat batch file located in the c:\scripts\ directory at the specified date and time. To facilitate remote calls, you can also create a PowerShell script named start_telnet.ps1, whose content is only Start-ScheduledTask -TaskName "start_telnet" to start the scheduled task. In this way, the program can continue to run even if the remote connection is disconnected.

[0065] Select the most appropriate execution method according to the storage location and type of the script, so that the system can flexibly adapt to different usage scenarios. Using Base64 encoding to execute PowerShell scripts can hide the script content, increasing the security of the system. By encapsulating the execution logic into a script, the operation process is simplified, which is convenient for later maintenance and upgrades. By creating a scheduled task, the problem of GUI program exiting after the remote connection is disconnected is effectively solved, ensuring the continuous operation of the program. Reasonable management and optimization of resource usage, such as timely deletion of temporary files that are no longer needed, helps improve the overall performance of the system.

[0066] S140: Execute the script according to the execution method, and process the result of the script execution.

[0067] In this embodiment, the script is executed according to the execution method, and the result of the script execution is processed synchronously or asynchronously; the synchronous method is to wait for the result to be returned after the execution is completed, and the asynchronous method is to dynamically obtain the output result in real time.

[0068] During remote script execution, correctly handling the results of script execution is crucial to evaluating the effectiveness of script execution and discovering potential problems in a timely manner. After determining the storage location and type of the script and selecting the appropriate execution method, the next step is to execute the script and process its results. Depending on the synchronous or asynchronous nature of the script execution, the way the results are processed will also be different.

[0069] In synchronous call mode, the system will directly wait for the script to be executed, collect the script's return status code, standard output (stdout) and error output (stderr), and return these results to the caller of the script remote execution system. The implementation is simple and the logic is clear, which is suitable for scenarios with short script execution time. When the script execution time is long, the caller needs to wait for a long time to receive a response, and the user experience is poor; in addition, the parallel execution efficiency of the synchronous method is low, because a task queue can only process one script execution request at the same time.

[0070] At this time, it is necessary to call asynchronously and dynamically obtain the script output in real time. Specifically, start the script execution, but do not block the caller, allowing the caller to continue to perform other tasks. Establish a WebSocket connection to achieve real-time communication, allowing the server to push the dynamic output results of the script execution to the client. Check the standard output and error output of the script regularly. Once new output content is detected, it is immediately sent to the caller of the script remote execution system in line format through the WebSocket connection. When the script execution is completed, stop the output check loop, and send the final status code and any remaining output content to the caller, completing the entire asynchronous execution process.

[0071] The caller can see the execution progress and output of the script in real time, which improves the user experience. Since asynchronous execution does not block the caller, multiple script execution requests can be processed at the same time, improving the concurrent processing capability of the system. Once an exception occurs in the script execution, the caller can immediately receive the error message, which helps to quickly locate the problem. However, the implementation is relatively complex and requires additional infrastructure support (such as WebSocket service).

[0072] Whether directly obtaining the execution results synchronously or monitoring the script execution status in real time asynchronously, it can meet the needs of different users and improve the user experience. The asynchronous processing mechanism enables the system to better cope with complex execution environments, support higher concurrency, and also leave room for future functional expansion. By monitoring the script execution status in real time, problems can be discovered and solved in the first place, reducing the time for troubleshooting. The asynchronous execution method avoids occupying system resources for a long time and improves resource utilization, especially when processing a large number of script execution requests.

[0073] In summary, choosing the appropriate synchronous or asynchronous result processing method according to the script execution method can not only meet the needs of diverse application scenarios, but also significantly improve the performance and reliability of the system.

[0074] The method of this embodiment is aimed at the field of automated operation and maintenance of IT systems, and is intended to solve the challenges faced by IT administrators when performing efficient, unified management and automated operations on multiple Windows servers, especially the shortcomings in the current remote script execution method of Windows systems. Specifically, traditional remote script execution methods usually rely on an agent installed on the target machine. Although the method of this embodiment achieves remote control, it also brings potential security risks, such as security risks caused by vulnerabilities in the agent itself or improper configuration. The present invention adopts an agentless approach to eliminate this risk, thereby improving the overall security of the system.

[0075] The agentless approach does not require the installation and running of additional agent programs on each target machine, which effectively reduces the usage of CPU, memory and other resources. This approach is particularly advantageous in environments with limited resources or strict performance requirements.

[0076] Traditional agent-based methods require complex installation, configuration, and upgrade operations on each target machine, which increases the difficulty of system management. The method of this embodiment avoids these cumbersome operations through an agentless approach, greatly simplifies system deployment and subsequent maintenance, and enables IT administrators to focus more on the management and optimization of core businesses.

[0077] The method of this embodiment first performs initialization and connection testing before remote script execution to check in advance the problems that may cause script execution failure or output not meeting expectations. By reusing the remote execution connection, not only the execution efficiency is improved, but also the impact on the target host is reduced.

[0078] According to the storage location and type of different scripts, the method of this embodiment can automatically select the most appropriate script execution method. This flexible execution strategy is applicable to a variety of complex application scenarios, ensuring the success rate and efficiency of script execution.

[0079] In some cases, a remote connection disconnection may cause a program with a graphical user interface (GUI) to exit unexpectedly. The method of this embodiment uses specific technical means to ensure that these programs can continue to run even after the remote connection is disconnected, thereby improving the stability and reliability of the system.

[0080] The method of this embodiment supports asynchronous calling, allowing the script to be executed in the background, and providing instant feedback by dynamically acquiring the script output in real time. This method not only improves the user experience, but also enhances the concurrent processing capability and troubleshooting efficiency of the system.

[0081] The method of this embodiment improves the efficiency and reliability of IT system automated operation and maintenance by improving security, reducing resource consumption, simplifying deployment and maintenance, optimizing remote execution initialization and connection testing, automatically selecting script execution methods, solving the GUI program exit problem after the remote connection is disconnected, and supporting asynchronous calls and real-time dynamic acquisition of script output. This not only solves the shortcomings of existing methods, but also provides IT administrators with a more efficient and convenient management tool.

[0082] The above-mentioned Windows system agentless remote script execution method configures the remote execution environment of the Windows system, sets identity authentication and selects the appropriate script execution method, including configuring the WinRM service. Initialize the remote connection and perform a connection test to ensure that the connection is stable, then select the execution method according to the script type and storage location. Finally, run the script according to the execution method and process its execution results to ensure efficient and stable automated operation and maintenance, and provide more stable, secure and flexible remote execution capabilities without additional installation and configuration, further improving the efficiency of automated operation and maintenance.

[0083] Figure 5 1 is a schematic block diagram of a Windows system agentless remote script execution device 300 provided by an embodiment of the present invention. Figure 5 As shown, corresponding to the above Windows system agentless remote script execution method, the present invention also provides a Windows system agentless remote script execution device 300. The Windows system agentless remote script execution device 300 includes a unit for executing the above Windows system agentless remote script execution method, and the device can be configured in a desktop computer, a tablet computer, a laptop, and other terminals. Specifically, please refer to Figure 5 The Windows system agentless remote script execution device 300 includes a configuration unit 301, an initialization unit 302, a selection unit 303 and an execution processing unit 304.

[0084] The configuration unit 301 is used to configure the remote execution environment of the Windows system, including setting identity authentication, selecting the script execution mode, and configuring the WinRM service when selecting the script execution mode; the initialization unit 302 is used to initialize the remote connection and perform a connection test; the selection unit 303 is used to select the execution method of the script according to the storage location and script type of the script; the execution processing unit 304 is used to execute the script according to the execution method and process the result of the script execution.

[0085] In one embodiment, the configuration unit 301 includes an authentication setting subunit and a mode selection subunit.

[0086] The authentication setting subunit is used to set the identity authentication of the executing user, wherein the identity authentication of the executing user includes ordinary users or domain users; the mode selection subunit is used to select the script execution mode, wherein the script execution mode includes non-encrypted service or SSL encrypted service, and the WinRM service is configured when the script execution mode is selected. Specifically, use administrator privileges to log in to the Windows server and start PowerShell; execute the winrm quickconfig -quiet command to quickly configure the WinRM service; enable basic authentication; when it is necessary to allow non-encrypted communication, run the PowerShell command to configure the Windows remote management service; set the maximum number of shells that each user can open at the same time; set the maximum memory usage of each shell; configure the WinRM listening port; when SSL encrypted service is required, write and execute a .ps1 script, the script should contain all the configuration steps, and run this script with administrator privileges.

[0087] In one embodiment, the initialization unit 302 includes: The lock creation determination subunit is used to determine whether a lock needs to be created based on the identity authentication, and to create a lock when necessary, wherein the lock is used to limit concurrent execution; the session judgment subunit is used to confirm whether the system currently has an established remote connection session; the startup test subunit is used to start a Shell on a remote host and run a connection test script to obtain a test execution result; the processing subunit is used to reuse the connection or close the remote connection session based on the test execution result.

[0088] In one embodiment, the selection unit 303 includes: An acquisition subunit is used to acquire a storage location of a script and a type of the script, wherein the storage location of the script includes a target host or a remote execution system, and the type of the script includes PowerShell or non-PowerShell; The calling subunit is used to execute the PowerShell script using base64 encoding if the PowerShell script is stored in the remote system; if the PowerShell script is stored in the target system, the PowerShell command execution method is called, and the Invoke-Expression method is used for non-PowerShell scripts.

[0089] The interface processing subunit is used to solve the problem of program exit after the remote connection is disconnected for programs with GUI interfaces by creating scheduled tasks, and use the scheduled tasks to trigger script execution.

[0090] In one embodiment, the execution processing unit 304 is used to execute the script according to the execution method, and process the result of the script execution in a synchronous or asynchronous manner; the synchronous manner is to wait for the result to be returned after the execution is completed, and the asynchronous manner is to dynamically obtain the output result in real time.

[0091] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned Windows system agentless remote script execution device 300 and each unit can refer to the corresponding description in the aforementioned method embodiment, and for the convenience and brevity of description, it will not be repeated here.

[0092] The above-mentioned Windows system agentless remote script execution device 300 can be implemented in the form of a computer program, and the computer program can be used in Figure 6 Runs on the computer device shown.

[0093] See also Figure 6 , Figure 6 500 is a schematic block diagram of a computer device provided in an embodiment of the present application. The computer device 500 may be a terminal, wherein the terminal may be an electronic device with communication function such as a smart phone, a tablet computer, a laptop computer, a desktop computer, a personal digital assistant, and a wearable device.

[0094] See also Figure 6 The computer device 500 includes a processor 502 , a memory and a network interface 505 connected via a system bus 501 , wherein the memory may include a non-volatile storage medium 503 and an internal memory 504 .

[0095] The non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions, and when the program instructions are executed, the processor 502 can execute a Windows system agentless remote script execution method.

[0096] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500 .

[0097] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a Windows system agentless remote script execution method.

[0098] The network interface 505 is used to communicate with other devices over the network. Figure 6The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present application, and does not constitute a limitation on the computer device 500 to which the solution of the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0099] The processor 502 is used to run the computer program 5032 stored in the memory to implement the following steps: Configure the Windows system remote execution environment, including setting identity authentication, selecting the script execution method, and configuring the WinRM service when selecting the script execution method; initialize the remote connection and perform a connection test; select the execution method of the script according to the storage location and script type of the script; execute the script according to the execution method, and process the result of the script execution.

[0100] In one embodiment, the processor 502 implements the following steps when implementing the steps of configuring the Windows system remote execution environment, including setting identity authentication, selecting a script execution mode, and configuring the WinRM service: Set the identity authentication of the executing user, wherein the identity authentication of the executing user includes a common user or a domain user; select the script execution mode, wherein the script execution mode includes a non-encrypted service or an SSL encrypted service, and configure the WinRM service when selecting the script execution mode.

[0101] In one embodiment, when implementing the step of configuring the WinRM service when selecting the script execution mode, the processor 502 specifically implements the following steps: Log in to the Windows server with administrator privileges and start PowerShell; execute the winrmquickconfig -quiet command to quickly configure the WinRM service; enable basic authentication; when you need to allow non-encrypted communication, run the PowerShell command to configure the Windows Remote Management service; set the maximum number of shells that each user can open simultaneously; set the maximum memory usage for each shell; configure the WinRM listening port; when SSL encryption service is required, write and execute a .ps1 script, which should contain all the configuration steps, and run this script with administrator privileges.

[0102] In one embodiment, when implementing the steps of initializing the remote connection and performing the connection test, the processor 502 specifically implements the following steps: Determine whether a lock needs to be created based on the identity authentication, and create a lock when necessary, wherein the lock is used to limit concurrent execution; confirm whether the system currently has an established remote connection session; start a Shell on the remote host and run a connection test script to obtain a test execution result; reuse the connection or close the remote connection session based on the test execution result.

[0103] In one embodiment, when the processor 502 implements the step of selecting the execution method of the script according to the storage location and the script type of the script, the processor 502 specifically implements the following steps: Get the storage location and type of the script, where the storage location of the script includes the target host or the remote execution system, and the script type includes PowerShell or non-PowerShell; if the PowerShell script is stored in the remote system, use the base64 encoding execution method; if the PowerShell script is stored in the target system, call the PowerShell command execution method, and use the Invoke-Expression method for non-PowerShell scripts.

[0104] In one embodiment, after implementing the steps of: if the PowerShell script is stored in the remote system, use the base64 encoding execution method; if the PowerShell script is stored in the target system, call the PowerShell command execution method; if the PowerShell script is not stored in the target system, use the Invoke-Expression method, the processor 502 further implements the following steps: For programs with GUI interfaces, create a scheduled task to solve the problem of program exit after the remote connection is disconnected, and use the scheduled task to trigger script execution.

[0105] In one embodiment, when the processor 502 implements the step of executing the script according to the execution method and processing the result of the script execution, the processor 502 specifically implements the following steps: The script is executed according to the execution method, and the result of the script execution is processed in a synchronous or asynchronous manner; the synchronous manner is to wait for the result to be returned after the execution is completed, and the asynchronous manner is to dynamically obtain the output result in real time.

[0106] It should be understood that in the embodiment of the present application, the processor 502 may be a central processing unit (CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0107] It can be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiment can be completed by instructing the relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiment of the above method.

[0108] Therefore, the present invention also provides a storage medium. The storage medium may be a computer-readable storage medium. The storage medium stores a computer program, wherein when the computer program is executed by a processor, the processor executes the following steps: Configure the Windows system remote execution environment, including setting identity authentication, selecting the script execution method, and configuring the WinRM service when selecting the script execution method; initialize the remote connection and perform a connection test; select the execution method of the script according to the storage location and script type of the script; execute the script according to the execution method, and process the result of the script execution.

[0109] In one embodiment, when the processor executes the computer program to implement the configuration of the Windows system remote execution environment, including setting identity authentication, selecting a script execution mode, and configuring a WinRM service step, the processor specifically implements the following steps: Set the identity authentication of the executing user, wherein the identity authentication of the executing user includes a common user or a domain user; select the script execution mode, wherein the script execution mode includes a non-encrypted service or an SSL encrypted service, and configure the WinRM service when selecting the script execution mode.

[0110] In one embodiment, when the processor executes the computer program to implement the step of configuring the WinRM service when selecting the script execution mode, the processor specifically implements the following steps: Log in to the Windows server with administrator privileges and start PowerShell; execute the winrmquickconfig -quiet command to quickly configure the WinRM service; enable basic authentication; when you need to allow non-encrypted communication, run the PowerShell command to configure the Windows Remote Management service; set the maximum number of shells that each user can open simultaneously; set the maximum memory usage for each shell; configure the WinRM listening port; when SSL encryption service is required, write and execute a .ps1 script, which should contain all the configuration steps, and run this script with administrator privileges.

[0111] In one embodiment, when the processor executes the computer program to implement the steps of initializing the remote connection and performing the connection test, the processor specifically implements the following steps: Determine whether a lock needs to be created based on the identity authentication, and create a lock when necessary, wherein the lock is used to limit concurrent execution; confirm whether the system currently has an established remote connection session; start a Shell on the remote host and run a connection test script to obtain a test execution result; reuse the connection or close the remote connection session based on the test execution result.

[0112] In one embodiment, when the processor executes the computer program to implement the step of selecting the execution method of the script according to the storage location and script type of the script, the processor specifically implements the following steps: Get the storage location and type of the script, where the storage location of the script includes the target host or the remote execution system, and the script type includes PowerShell or non-PowerShell; if the PowerShell script is stored in the remote system, use the base64 encoding execution method; if the PowerShell script is stored in the target system, call the PowerShell command execution method, and use the Invoke-Expression method for non-PowerShell scripts.

[0113] In one embodiment, the processor, after executing the computer program to implement the steps of: if the PowerShell script is stored in the remote system, use base64 encoding to execute the method; if the PowerShell script is stored in the target system, call the PowerShell command execution method; if the PowerShell script is stored in the target system, use the Invoke-Expression method for non-PowerShell scripts, further implements the following steps: For programs with GUI interfaces, create a scheduled task to solve the problem of program exit after the remote connection is disconnected, and use the scheduled task to trigger script execution.

[0114] In one embodiment, when the processor executes the computer program to implement the steps of executing the script according to the execution method and processing the result of the script execution, the processor specifically implements the following steps: The script is executed according to the execution method, and the result of the script execution is processed in a synchronous or asynchronous manner; the synchronous manner is to wait for the result to be returned after the execution is completed, and the asynchronous manner is to dynamically obtain the output result in real time.

[0115] The storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk, etc., which are computer-readable storage media that can store program codes.

[0116] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0117] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0118] The steps in the method of the embodiment of the present invention can be adjusted in order, combined and deleted according to actual needs. The units in the device of the embodiment of the present invention can be combined, divided and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0119] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, terminal, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.

[0120] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A method for executing remote scripts without an agent in Windows system, characterized in that: include: Configure the Windows system remote execution environment, including setting identity authentication, selecting the script execution method, and configuring the WinRM service when selecting the script execution method; Initialize remote connection and perform connection test; Selecting a script execution method according to the script storage location and script type; The script is executed according to the execution method, and the result of the script execution is processed.

2. The Windows system agentless remote script execution method according to claim 1, characterized in that: The configuration of the Windows system remote execution environment includes setting identity authentication, selecting the script execution mode, and configuring the WinRM service, including: Setting the identity authentication of the executing user, wherein the identity authentication of the executing user includes a common user or a domain user; Select a script execution mode, wherein the script execution mode includes a non-encrypted service or an SSL encrypted service, and configure a WinRM service when selecting the script execution mode.

3. The Windows system agentless remote script execution method according to claim 1, characterized in that: The configuration of the WinRM service when selecting the script execution mode includes: Log in to the Windows server with administrator privileges and start PowerShell; Run the winrm quickconfig -quiet command to quickly configure the WinRM service; Enable Basic Authentication; When you need to allow unencrypted communication, run the PowerShell command to configure the Windows Remote Management service; Set the maximum number of shells that each user can open simultaneously; Set the maximum memory usage for each shell; Configure WinRM listening port; When SSL encryption service is required, write and execute a .ps1 script, which should contain all the configuration steps and run the script with administrator privileges.

4. The Windows system agentless remote script execution method according to claim 1, characterized in that: Initializing the remote connection and performing the connection test include: Determine whether a lock needs to be created according to the identity authentication, and create a lock when necessary, wherein the lock is used to limit concurrent execution; Check whether the system currently has an established remote connection session; Start a shell on the remote host and run the connection test script to get the test execution results; Reuse the connection or close the remote connection session according to the test execution result.

5. The Windows system agentless remote script execution method according to claim 1, characterized in that: The method of executing the script is selected according to the storage location and the script type of the script, including: Obtaining a storage location of the script and a type of the script, wherein the storage location of the script includes a target host or a remote execution system, and the type of the script includes PowerShell or non-PowerShell; If the PowerShell script is stored in the remote system, use the base64 encoding execution method; if the PowerShell script is stored in the target system, call the PowerShell command execution method, and use the Invoke-Expression method for non-PowerShell scripts.

6. The Windows system agentless remote script execution method according to claim 5, characterized in that: If the PowerShell script is stored in the remote system, the base64 encoding execution method is used; if the PowerShell script is stored in the target system, the PowerShell command execution method is called, and the non-PowerShell script uses the Invoke-Expression method, and also includes: For programs with GUI interfaces, create a scheduled task to solve the problem of program exit after the remote connection is disconnected, and use the scheduled task to trigger script execution.

7. The Windows system agentless remote script execution method according to claim 1, characterized in that: The step of executing the script according to the execution method and processing the result of the script execution includes: The script is executed according to the execution method, and the result of the script execution is processed in a synchronous or asynchronous manner; the synchronous manner is to wait for the result to be returned after the execution is completed, and the asynchronous manner is to dynamically obtain the output result in real time.

8. A Windows system agentless remote script execution device, characterized in that: include: Configuration unit, used to configure the Windows system remote execution environment, including setting identity authentication, selecting the script execution mode, and configuring the WinRM service when the script execution mode is selected; Initialization unit, used to initialize remote connection and perform connection test; A selection unit, used to select an execution method of the script according to the storage location and script type of the script; An execution processing unit is used to execute the script according to the execution method and process the result of the script execution.

9. A computer device, characterized in that: The computer device comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.

10. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Method, device and system for remotely collecting host process information

    CN102480749A

  • Automatic script execution system and execution method

    CN114528055A

  • Automatic testing method and device, computer readable storage medium and electronic equipment

    CN115048313A

  • Application release integrated management method

    CN115543346A

  • Agentless remote machine management

    US12170674B1