Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Bob Swart (aka Drs.Bob) Dr.Bob's Delphi Clinics Dr.Bob's Delphi Courseware Manuals
View Bob Swart's profile on LinkedIn Drs.Bob's Delphi Notes
These are the voyages using Delphi Enterprise (and Architect). Its mission: to explore strange, new worlds. To design and build new applications. To boldly go...
Title:

How to "Run As Administrator" with parameter?

Author: Bob Swart
Posted: 8/11/2007 2:37:13 PM (GMT+1)
Content:

I've been working on a number of Delphi 2007 and C++Builder 2007 DataSnap application under Windows Vista, and one of the things I need to do from time to time is to run the DataSnap server application with the /regserver command-line parameter as well as with the "Run As Administrator" option. Without the /regserver command-line, the Delphi 2007 DataSnap servers won't register themselves automatically, but if you pass the /regserver command-line they must be "Run As Administrator", otherwise you'll get a message that This Program has Stopped Working...
The problem is that I've been unable to specify both the command-line and the "Run As Administrator" options at the same time. The only workaround I could think of (which I'm still using today), is to first create a shortcut to the DataSnap executable, then modify the properties of the shortcut so it includes the /regserver command-line parameter, and finally execute the shortcut with the "Run As Administrator" option.

If someone knows a better (easier) solution to this problem, please let me know. Thanks in advance!

Back  


9 Comments

AuthorPostedComments
TOndrej 07/08/11 16:05:01I think you could also temporarily create a .manifest file with requestedExecutionLevel "requireAdministrator" which should cause the UAC prompt for administrator's password. You could write a tool to automate that task, of course.
Stefan van As 07/08/11 22:46:39Have you tried runasspc? (http://robotronic.de/runasspc). Besides running a program under a user account other than the logged-in user, it also allows you to pass command-line parameters.
Dmitry Streblechenko 07/08/11 23:55:08You can modify AxCtrls.pas, ComObj.pas, ComServ.pas to register the COM server(s) in HKCU\Software\Classes rather than HKCR and use RegisterTypeLibForUser rather than RegisterTypeLib. See 50386 on QC for details (I posted the relevant changes for these units).
Bob Swart 07/08/12 08:23:56Thanks for all suggestions, I'll investigate those further. At least I'm glad I didn't overlook something really easy ;-)
G. Harris 07/08/13 11:29:01How about starting a command prompt? Start | cmd that generally runs as an administrator. Then all you need to do is to run the datasnap application with the /regserver switch.
Bob Swart 07/08/13 11:59:04@G. Harris: Apart from the fact that Start | Run is hidden by default, unfortunately, running a command prompt is not done in Administrator mode (even if I run it as a user with Admin rights). The only things that seems to help is running C:\Windows\System32\cmd in "As Administrator" to spawn new applications as administrator in the command prompt. But IMHO that feels as kludgy as creating the shortcut to the DataSnap application itself...
Pieter Polak 07/08/13 20:55:25What about simple "runas" from a command prompt (or batch file): runas /user:administrator "DataSnapServerApp /regserver"
Bob Swart 07/08/13 21:16:07Thank you Pieter, that worked indeed.
seo service 13/09/06 19:49:35xIqPhw I really liked your blog article. Great.


New Comment (max. 2048 characters, no HTML):

Name:
Comment:



This webpage © 2005-2019 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.