Jump to content

Script Help


Recommended Posts

I am trying to write a script to allow non admin users to restart services on a server. I am new to scripting and this is what i have so far. Would like to rap it with Autoit and make it an exe and have the customers run it from a drive that they have access to on the server. Any help would be great.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_Allow_Decompile=n

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

;

; WhoHasNTWPS.au3

; Script to Stop and Start Service with a service account

; Check working directory for security reasons. Only users with proper NTFS permissions

; can run this program. Prevent unauthorized users from copying and running

; this program from another unsecured folder.

; Set the RunAs parameters to use service account

RunAsSet("Service Account", "Domain", "password")

; Run program as service account

strComputer = "ServerName-p1"

strServiceName = "Service_Name"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

objItem StopService("strServiceName")

Wscript Sleep 10000

objItem StartService("strServiceName")

MsgBox "The Service " & UCase("strServiceName") & " On " & UCase("strComputer") & " Has Been Restarted"

Link to comment
Share on other sites

I am trying to write a script to allow non admin users to restart services on a server. I am new to scripting and this is what i have so far. Would like to rap it with Autoit and make it an exe and have the customers run it from a drive that they have access to on the server. Any help would be great.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_Allow_Decompile=n

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

;

; WhoHasNTWPS.au3

; Script to Stop and Start Service with a service account

; Check working directory for security reasons. Only users with proper NTFS permissions

; can run this program. Prevent unauthorized users from copying and running

; this program from another unsecured folder.

; Set the RunAs parameters to use service account

RunAsSet("Service Account", "Domain", "password")

; Run program as service account

strComputer = "ServerName-p1"

strServiceName = "Service_Name"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

objItem StopService("strServiceName")

Wscript Sleep 10000

objItem StartService("strServiceName")

MsgBox "The Service " & UCase("strServiceName") & " On " & UCase("strComputer") & " Has Been Restarted"

To do this you really need 2 exe's. I have attached 2 scripts that you can try. You need to edit CycleService.au3 and edit the variables at the bottom of the script, compile it to an exe, and then put it in the folder on the server where users have access. The second script Restart Service.au3 you need to edit and put in the appropriate credentials. Compile this one and place it in the same folder as the CycleService.exe you created. Users should be able to restart the service by running the Restart Service.exe.

I can not take credit for the first 440 lines of the CycleService script. It utilizes a ServiceControl UDF written I believe by GEOSoft. For simplicity sake I didn't write it as an Include statement but merely copied it into the CycleService script.

CycleService.au3

Restart_Service.au3

Link to comment
Share on other sites

I got the CycleService to run but not the restart service. Keep getting

Error: Incorrect number of parameters in function call.....any ideas?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_Allow_Decompile=n

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

RunAs("Service Account", "Domain", "password", "CycleService.exe")

;NOTE if you are using the newest version of AutoIT then RunAsSet no longer exists.

;Instead of the above code it would look like this:

;RunAs("Service Account", "Domain", "password", "CycleService.exe")

quote name='erik7426' date='Aug 25 2008, 07:25 AM' post='570316']

To do this you really need 2 exe's. I have attached 2 scripts that you can try. You need to edit CycleService.au3 and edit the variables at the bottom of the script, compile it to an exe, and then put it in the folder on the server where users have access. The second script Restart Service.au3 you need to edit and put in the appropriate credentials. Compile this one and place it in the same folder as the CycleService.exe you created. Users should be able to restart the service by running the Restart Service.exe.

I can not take credit for the first 440 lines of the CycleService script. It utilizes a ServiceControl UDF written I believe by GEOSoft. For simplicity sake I didn't write it as an Include statement but merely copied it into the CycleService script.

Link to comment
Share on other sites

I got the CycleService to run but not the restart service. Keep getting

Error: Incorrect number of parameters in function call.....any ideas?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_Allow_Decompile=n

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

RunAs("Service Account", "Domain", "password", "CycleService.exe")

;NOTE if you are using the newest version of AutoIT then RunAsSet no longer exists.

;Instead of the above code it would look like this:

;RunAs("Service Account", "Domain", "password", "CycleService.exe")

quote name='erik7426' date='Aug 25 2008, 07:25 AM' post='570316']

To do this you really need 2 exe's. I have attached 2 scripts that you can try. You need to edit CycleService.au3 and edit the variables at the bottom of the script, compile it to an exe, and then put it in the folder on the server where users have access. The second script Restart Service.au3 you need to edit and put in the appropriate credentials. Compile this one and place it in the same folder as the CycleService.exe you created. Users should be able to restart the service by running the Restart Service.exe.

I can not take credit for the first 440 lines of the CycleService script. It utilizes a ServiceControl UDF written I believe by GEOSoft. For simplicity sake I didn't write it as an Include statement but merely copied it into the CycleService script.

I left out a parameter in the call to RunAs. It should be...

RunAs("Service Account", "Domain", "password",0,"CycleService.exe")
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...