I have, in the past, successfully used a console app compiled in admin level to install and run a console app as a service using shell commands and sc; just a simple create, start sequence but now, in 2.1 on win10 I am having a lot of problems. Namely, I can manually run the commands in an admin level command prompt and it works as expected, all good. My code, however, will create but not start the service. I have notice the UAC when I run admin cmd prompt is blue and my code run version is yellow…any thoughts? i am trying to run the service in the SpecialFolder.Resources folder…I just wrote some code to move it to the applicationdata folder and that gives me an access denied error on the destination. grrr
Services usually run as a non interactive user, should it’s likely that the service can’t run because it doesn’t have access. Try copying it to the SharedApplicationData folder instead.
Same - 102 access denied. This with UAC admin for the application. I guess my most pressing puzzle is why i can run command prompt as admin and install & start just fine from just about anywhere but via the code with admin UAC nothing
It would be helpful to see the code.
It turns out that I had changed the path to the exe to ShellPath - this was causing win to ‘mangle’ the path:
var w as new Shell
var cmd As String = "sc create myService type= own start= auto binpath= "
var path As String = Chr(34) + f.NativePath + Chr(34)
w.Execute(cmd+Path)
System.DebugLog("starting sc from shell code: " + Str(w.ErrorCode) + Str(w.Result) )cmd="sc start myService "
w.Execute(cmd)
System.DebugLog("updating description shell code: " + Str(w.ErrorCode) + Str(w.Result) )cmd = "sc description myService ““Provides service to myService products.”” "
w.Execute(cmd)
System.DebugLog(“starting service shell code: " + Str(w.ErrorCode)+” " + Str(w.Result) )
So it’s working now?
@Greg_O_Lone - Well, not that part. heres the copy folder code that turns up unexpected access denied:
bridgefolder=GetFolderItem("").Parent.Child(“myBridgeWin”)
'var dest as folderitem = new folderitem(SpecialFolder.SharedApplicationData.Child(“myCompanyFolder”))
'if not dest.Exists then
'dest.CreateFolder
'end if
'bridgefolder.CopyTo(dest)
and it gives tha IO error on the last line
I guess Im not surprised that my amatuer mistake of changing the path to shellpath was for nothing but it ‘seemed’ like the thing to do - arg! The things that keep me puzzled though are why is the UAC screen blue when i admin into a cmd prompt and yellow in the app? I wonder if its the code sign/known developer? and also this access denied part is pretty hard to understand. the console app is admin uac.