Archive: Service Creation Function


Service Creation Function
The below function, only KIND OF works. It installs the service and puts the user name in there, but you have to re-enter the password in order to start it. Can anyone see what I'm doing wrong?

<!-------------------snip-------------------->
Function serviceUtility
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Install Service if not installed ;;
;; ;;
;; Pass to function: ;;
;; $R8 - Service Name ;;
;; $R7 - Path to executable ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

!insertmacro SERVICE "installed" "$R8" 0
pop $0
strCmp $0 'false' createService
!insertmacro SERVICE "stop" "$R8" 0
Goto endServiceUtility

createService:
strCmp $R9 "1" serviceUtility1 ;if we already have userName and password continue to create
strCpy $R9 1 ;note that we've already gotten the user, password, and computername
Dialogs::InputBox "UserID" "Please enter service username to run new service as" "OK" "Cancel" "0" ${VAR_R1}
Dialogs::InputBox "Password" "Please enter the service user password:" "OK" "Cancel" "1" ${VAR_R2}
serviceUtility1:

nsSCM::Install "$R8" "$R8" 16 2 "$R7" "" "" "$R1" "$R2"


endServiceUtility:

FunctionEnd
<!------------------end snip----------------->

Thanks Much,
Eric


Try prefixing the user name with .\ as MSDN suggests.

If the service type is SERVICE_WIN32_OWN_PROCESS, use an account name in the form DomainName\UserName. The service process will be logged on as this user. If the account belongs to the built-in domain, you can specify .\UserName.
It might fail to find the user, show up the dialog which has a better search method for the user, but where the password is already lost.

I can't because the user is a domain user rather than local. So it's going to be:

DomainName\UserName

It sets the user up correctly in the service, just seems to fail on the password.


OK, figured it out. There is no problem with this script. The problem lies in our domain default group policy. The specific user has to be granted logon rights in order to be started with Net Start command. Is there a way to script this in NSIS that anyone knows?