Jump to content
powerbot

changing login user for service doesnt work

Recommended Posts

powerbot

Hallo forum,

I have build a little installer for a bunch of programs. One of the programs is installing a service which I would like to run with a specific user.

Func _prog()
   FileChangeDir ( @ScriptDir )
   $CMD = @ScriptDir&"\programuser.vbs "&$pguser[1]&" "&$pgpw[1]  ;the pguser and pgpw are set in a main program
   $Error_user = RunWait(@ComSpec & " /c " & $CMD, @Scriptdir)
   $CMD = "call "&@ScriptDir&"\"&$Inst_program&" --mode unattended" ;$Inst_program is also set in the main program

   $Error_install = RunWait(@ComSpec & " /c " & $CMD, @Scriptdir)
   $CMD = 'ntrights +r SeServiceLogonRight -u '&$pguser[1]
   $Error_service = RunWait(@ComSpec & " /c " & $CMD, @ScriptDir)
   $CMD = @ScriptDir&"\programservicechange.vbs "&$pguser[1]&" "&$pgpw[1]
   $Error_service = RunWait(@ComSpec & " /c " & $CMD, @Scriptdir)
EndFunc

programuser.vbs creates a new windows user and sets a password for it that doesn't expire

'ntrights +r SeServiceLogonRight -u '&$pguser[1]   sets Logon as service Rights for that created user

programservicechange.vbs (modifies the service to start with the user and starts the service)

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServices = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Service WHERE Name = 'service'")

For Each objService In colServices

    errServiceChange = objService.Change _
        ( , , , , , , "program" , "password")  
Next

as far as I can check it it works fine (the user is created, the right password is set and the service is also set with that user)

still my problem is:

when I let the installer only run the install program and create a new user and after that change the service manually it works fine

but when I let the installer do everything (install program, create user and mod service) the service isn't started when I go to Management>Serivces

and if I start the service manually I get a message that it was paused and that it is normal for some services to be paused after start if they are not used by a program or service

the computer is member of a domain and the user with which I run the installer is local Admin

I tried many things now and i am a little frustrated. Hope you can help my

 

Edited by powerbot

Share this post


Link to post
Share on other sites
water

Hallo powerbot,

willkommen beim englischen AutoIt Forum!
Um möglichst viele Antworten auf Dein Probem zu bekommen solltest Du entweder Deine Frage auf englisch stellen oder im deutschen Forum posten.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
powerbot

Thanks for the advice

I 've translated it now :)

Share this post


Link to post
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

×