Old 26th July 2019, 11:12   #1
Junior Member
Join Date: Jul 2019
Posts: 30
Creating and starting Windows service using SimpleSC


I am using SimpleSC::InstallService and StartService to create and start a windows service. However, I have noticed that the window hangs for few seconds ( 3-4s )during this process. It sometimes shows "Not Responding"

I have tried another method using progress bar where the progress bar is displayed when the service installs and starts. There also I have noticed that the progress bar stops for some time.

Below is the code
SimpleSC::ExistsService "AGService"
Pop $0
${If} $0 != 0
DetailPrint "Installing AGWindowsService"
SimpleSC::InstallService "MyService" "AGWindowsService" "16" "2" "$INSTDIR\winservice\MyWindowsService.exe" "" $R8 $R5
SimpleSC::SetServiceDescription "MyService" "This service is used to communicate with My Server"

SimpleSC::SetServiceLogon "MyService" $R8 $R5
Pop $0 ; return error(1)/success(0)
StrCmp $0 +1 Done ; If successful grant the service logon privilege to "MyServiceUser"

SimpleSC::GrantServiceLogonPrivilege $R8
Pop $0 ; return error(1)/success(0)

DetailPrint "Starting AGWindowsService"
SimpleSC::StartService "AGService" "" 30

SimpleSC::ServiceIsRunning "AGService" 1 30
Pop $0
Pop $1
${if} $0 != 0
# error
MessageBox MB_OK|MB_ICONSTOP "Unable to start service - Reason: $0"
${if} $1 == 0
# service not running
MessageBox MB_OK|MB_ICONSTOP "Unable to start service - Reason: $0"
SimpleSC::RestartService "AGService" "" 30

Please help!!!
DivyaArun is offline   Reply With Quote
Old 26th July 2019, 11:22   #2
Anders's Avatar
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
Ideally you should only perform these types of tasks in a Section. If you need to do it on a custom page you can try https://nsis.sourceforge.io/BgWorker_plug-in

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump