read arguments for console application

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

read arguments for console application

Post by SteveTX » Sat Jan 23, 2010 7:35 pm

I am writing a modular program that runs in user mode. However, the program will need a kernel driver and DLL running. If those items are not present, I would like to install them. Is there a way to temporarily escalate execution level for a single command and WMI stuff (because some users have UAC running silent mode and don't see the requests, just deny them)?

I was thinking it would be better to have an external program that requested administrative privileges, and then would read the arguments passed to it and perform the functions. For example:

// No Driver Installed
get shell("adminpriv.exe /installdriver /installtask /installDLL")

So in writing adminpriv, how would I read the arguments that were passed to it (/installdriver, etc) ? Is there a better way to pass arguments to a runrev application (windowless)?

RRobert
Posts: 151
Joined: Sat Feb 28, 2009 8:20 pm

Re: read arguments for console application

Post by RRobert » Sun Jan 24, 2010 2:21 am

Hello Steve,
Is there a way to temporarily escalate execution level for a single command and WMI stuff (because some users have UAC running silent mode and don't see the requests, just deny them)?
I would ask for username and password, escalate the execution level by the runas command or the ShellExecute API via VBScript, check the permissions and do my stuff.
I was thinking it would be better to have an external program that requested administrative privileges, and then would read the arguments passed to it and perform the functions.
That's up to you.
[...] how would I read the arguments that were passed to it (/installdriver, etc) ? Is there a better way to pass arguments to a runrev application (windowless)?
Look in the docs for the dollar keyword. Specify "-ui" as part of the launching commandline or hide the stack, handle the arguments in the preopenStack handler, write your output to stdout and dont forget to quit the engine.

Robert

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: read arguments for console application

Post by SteveTX » Sun Jan 24, 2010 4:19 am

Well i got it working as a console thing. However, I am having some trouble getting the output to show up.

I am running shell commands but i can't seem to capture the output and print it to the terminal.

ex:

Code: Select all

 set the hideconsolewindows to true
 write "Hello? Anyone Home?" to stdOut
 get shell("netsh firewall delete portopening  protocol = TCP port = 22217")
 write it to stdOut
Nothing shows up in the terminal. Does stdOut need to be initialized somehow?

RRobert
Posts: 151
Joined: Sat Feb 28, 2009 8:20 pm

Re: read arguments for console application

Post by RRobert » Sun Jan 24, 2010 6:02 am

Nothing shows up in the terminal.
Sorry I forgot that this is a know issue or bug. And I bet that "-ui" is not working anymore too cause of the 4.0 engine changes. So you have to use something else (AutoIT, a VBScript using cscript or a command line- / batch script).

AutoIT could create compiled console applications and if you deceide to use VBScript or a command line / batch script, you could use a script packaging application or a batch compiler to get a binary. Simply search for "vbs to exe" or "batch compiler" in the search engine of your choice.

I would suggest that use a command line script, thats the easiest way and it should sufficient too for the mentioned task.
sample.cmd
@echo off
echo.Sample v.1.0
echo.Copyright (C) 2010 by ... All rights reserved.
echo.

if %1!==! goto argument_missing
if %1==status goto status

:status
echo. Status Overview
echo.
goto quit

:argument_missing
echo.Missing argument!
echo.
echo.Valid arguments are status, ...
echo.
goto quit

:quit
I used QuickBFC in the past to create a compile application and could recommend it.

Of course you could also use C/C++ to create a Win32 console application in a fairly amount of time depending on your knowledge. If you like to do so check out Visual C+ 2008 Express Edition.

Robert

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: read arguments for console application

Post by SteveTX » Sun Jan 24, 2010 7:21 am

Thanks for that. I can see this is an issue as well for Windows. However, I was able to capture the stdout and just stick it elsewhere for the time being.

RRobert
Posts: 151
Joined: Sat Feb 28, 2009 8:20 pm

Re: read arguments for console application

Post by RRobert » Tue Apr 06, 2010 3:40 pm

I took some time to look into the issue in detail. The reason why you could not write to stdout under Windows using the put command is caused by the fact that the executable is set to WINDOWS_GUI instead of WINDOWS_CUI (console application) in the subsystem field within the PE header.

You could change that by patching the binary with PE Patcher for example.

Simply change Windows GUI to Windows Console and click "Save".

PS: You still need to start your executable using the -ui argument.

Robert

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: read arguments for console application

Post by BvG » Wed Apr 07, 2010 1:45 am

for cgi and faceless apps, you don't use "write to x" for outputting stuff. you use "put", like this:

Code: Select all

#rev -ui

on startup
  put "hello world"
end startup
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

RRobert
Posts: 151
Joined: Sat Feb 28, 2009 8:20 pm

Re: read arguments for console application

Post by RRobert » Wed Apr 07, 2010 2:40 am

Yes you could also use put. But in general you need to change the subsystem value in the PE header to create a console application for Windows otherwise your content will not appear.

Robert

Post Reply