Jump to content

End process


Recommended Posts

Hello everyone,

Newbie here to AutoIT. I would appreciate a little help with a script that can remotely end a process on a Win 2k8 R2 server. The process gets hung up at times and I need to be able to have one of our managers clear it up without actually giving him access to the box. I have come up with a batch file that works fine, but I don't want the embedded credentials for the local admin on the server exposed in the batch file. I want to compile the batch into an .exe that he can run as needed.

In my batch file I have:

taskkill /S ServerName /U DOMAIN\ServerLocaladmin /P LocalAdminPwd /F /IM "taskmgr.exe"


And in my .au3 file I have:
 

Local $strUsername = "ServerLocaladmin"
Local $strPassword = "LocalAdminPwd"
Local $strDomain = "Domain"
Local $strServer = "ServerName"
Local $SystemDrive = EnvGet("SYSTEMDRIVE")
Local $Process = chr(34) & "taskmgr.exe" & chr(34)
Local $Return

;Msgbox (0, "Var", $Process)

$Return = MsgBox (4, "Terminate " & $Process, "This utility will terminate " & $Process & " on the server in order to free up stuck sessions. Would you like to proceed?")

;MsgBox (0, "error", "Return is " & $Return)

If $Return == 6 Then
   Run(@ComSpec & " /c taskkill /S " & $strServer & " /U " & $strDomain & "\" & $strUsername & " /P " & $strPassword & " /F /IM " & $Process, @SW_SHOW)
EndIf


...but this isn't working when the file is copied to his PC. I would also like to get the output of the batch command in the output box but I don't know how to do this.

Does the script look ok or is there a better way of ending the process remotely?

Thank you

Edited by Melba23
Amended title
Link to comment
Share on other sites

Hi.

Can you try to change all " in your run command to ' and strip chr(34) inside $Process?

I'm currently not able to test it. I hope the best, Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

Hi @CiprianD,

AutoIT has an embedded RunAs function that should simplify what you're trying to achieve:

#RequireAdmin

RunAs("ServerLocaladmin", "domain", "LocalAdminPwd", 0, 'taskkill /S ServerName /F /IM "taskmgr.exe"', Default, @SW_HIDE)

Just compile this to an exe and it should work!

Link to comment
Share on other sites

On 8/24/2017 at 1:15 PM, Neutro said:

Hi @CiprianD,

AutoIT has an embedded RunAs function that should simplify what you're trying to achieve:

#RequireAdmin

RunAs("ServerLocaladmin", "domain", "LocalAdminPwd", 0, 'taskkill /S ServerName /F /IM "taskmgr.exe"', Default, @SW_HIDE)

Just compile this to an exe and it should work!

This seems to elevate the UAC with the permissions of the local admin account, but it does not kill the process remotely. I also tried a domain admin account with no luck.

Link to comment
Share on other sites

@Ciprian The Run function on your script from the 1st post it missing the working directory before the @SW_SHOW.  Add the working directory and it works fine.

Run(@ComSpec & " /c taskkill /S " & $strServer & " /U " & $strDomain & "\" & $strUsername & " /P " & $strPassword & " /F /IM " & $Process, @WorkingDir, @SW_SHOW)

One way to see the output of the batch command is by adding && pause to the Run function.

Run(@ComSpec & " /c taskkill /S " & $strServer & " /U " & $strDomain & "\" & $strUsername & " /P " & $strPassword & " /F /IM " & $Process & ' && pause', @WorkingDir, @SW_SHOW)

 

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

1 hour ago, Danny35d said:

@Ciprian The Run function on your script from the 1st post it missing the working directory before the @SW_SHOW.  Add the working directory and it works fine.

Run(@ComSpec & " /c taskkill /S " & $strServer & " /U " & $strDomain & "\" & $strUsername & " /P " & $strPassword & " /F /IM " & $Process, @WorkingDir, @SW_SHOW)

One way to see the output of the batch command is by adding && pause to the Run function.

Run(@ComSpec & " /c taskkill /S " & $strServer & " /U " & $strDomain & "\" & $strUsername & " /P " & $strPassword & " /F /IM " & $Process & ' && pause', @WorkingDir, @SW_SHOW)

 

That seemed to have done the trick. Thank you very much!

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...