Pass credentials to execute Shell as Administrator?

Is there a way to execute a shell with credentials to run as administrator on Windows. My need is to have a user start a Xojo Web application service in a remote Windows Server 2019 server. I have solved the restart portion by using PSTools psservice64.exe but unfortunately the access is denied by the server unless the console that sends the command to start is also running as administrator.

The Shell command syntax is as follows:

"c:\windows\psservice64 \\servername.domain -u adminuser@domain -p adminpassword start XojoWebAppService"

Everything I’ve tried requires a login when the shell is run, ie: Xojo shell using build security or WindowsShellExecuteAsAdminMBS. This will not work since the user on the factory floor will not have administrator credentials. I need to mask those in a desktop application with one big button to start the service if it crashes.

Can’t you just set up the service to automatically restart if it crashes?

Windows Services built by Xojo don’t set a service failure flag. To get automatic recovery to work you’ll need to run the command sc.exe failureflag XojoWebAppService 1.

Yes, I already have, but invariably that eventually fails and requires a manual start. Machine operators can call our local NOC to restart it, but that requires them leaving their machine, finding a phone and calling. Meanwhile the application is down and production is stopped.

This is an interim solution because the machine’s automation output is a large number of XML files we can’t control, only one of which is the wheat among the chaff needed to extract a job count. The production is barcode driven high speed folding and the web app reads the xmls until the job count is found and then it sends a POST to a MIS server at the corporate datacenter, then resets for the next barcode read. Why the automatic restarts eventually fails seems to be a Windows bug.

Ahhhh… I guess that is why the automatic restart eventually fails. Thanks Wayne! I’ll try tthat and maybe I don’t need to do what I’ve been working on.

Maybe runas

(How to use the RunAs command in Windows — LazyAdmin)**

Perhaps the PSExec tool would be helpful.