Skip to content
⌘ NSIS Forum Archive

executing dos commands

27 posts

mancini#

executing dos commands

i have a problem with executing native dos shell comands like "echo"

"echo text > $INSTDIR\location.txt" written in the shell/command line of windows results in the creation of a file that contains "text"

while trying to have similar result from with a nsis script i tried

Exec "echo $INSTDIR > $INSTDIR\location.txt"

Exec '"echo" $INSTDIR > $INSTDIR\location.txt'

even

Exec '"command.com" echo $INSTDIR > $INSTDIR\location.txt'

and the file is never created

can anyone help ?
treehousetim#
if all you're trying to do is put the instdir variable into a file, try using the file functions.

FileOpen $0 "filename" w
FileWrite $0 "$INSTDIR"
FileClose $0

-Tim
Drako12#
can anyone help me with this, i didnt want to make a topic with almost the same name

im making a script to run cmd.exe then runas.exe with some parameters, the problem is, the runas.exe program asks for the admin password, how can to write the pass in the script and hit enter?
Takhir#
Joost, please explane how "to similate key events (SendKeys)". User has handle for running DOS (console) process, how to send key?

BTW, with Windows API it is possible to create DOS application (run runas.exe with parameters) with redirected IO using pipes, this case application waits for WriteFile() output (with password, for example), such plug-in might be usefull.
Joost Verburg#
If you can get it to work using the console you can always call the console with a command using Exec.

I have no time to write complete Windows API examples, sorry.
s793016#
Sorry, my English is very very poor.

If your "runas.exe" is a dos program and it totally only need input this 2 things just like this:

Username:
Password:
then you can make a text file (ex: QUOTE.TXT) with 3 line like this:
line 1:somebody this is username string
line 2:12345678 this is password string
line 3: this line have nothing here. You must keep this blank line here for input [Enter] key
after that, use a I/O redirect to input those for you.


...
exec '"$Sysdir\cmd.exe" "fullpath\runas.exe" < "fullpath\Quote.txt"'
...
Takhir#
s793016

I/O redirection with < and > works fine on Linux, and on some of Wins too, but unfortunately, not on all :-(( This is why I had to to use correct rediriction with pipes in my applications.
Anders#
the way to exec a dos command like echo:

cmd.exe /K echo Hello World

/C - Carries out the command specified by string and then terminates
/K - Carries out the command specified by string but remains

and u would have to use command.com on 9x ofcourse
Drako12#
Originally posted by Takhir
s793016

I/O redirection with < and > works fine on Linux, and on some of Wins too, but unfortunately, not on all :-(( This is why I had to to use correct rediriction with pipes in my applications.
can you explain to me how you did it? please.. =)
Drako12#
Originally posted by Anders
the way to exec a dos command like echo:

cmd.exe /K echo Hello World

/C - Carries out the command specified by string and then terminates
/K - Carries out the command specified by string but remains

and u would have to use command.com on 9x ofcourse
it doenst work

tried

runas /user:localhost\user "program" /K password
Takhir#
i/o redirect sample

a bit of code.

((pthreadParams)ptp)->rq(hInputWrite, hOutputRead, ((pthreadParams)ptp)->param);

is a call to program, which handles child process i/o (like lgOutput() sub).
More info u can find in MSDN.

Attachments

Drako12#
Re: i/o redirect sample

Originally posted by Takhir
a bit of code.

((pthreadParams)ptp)->rq(hInputWrite, hOutputRead, ((pthreadParams)ptp)->param);

is a call to program, which handles child process i/o (like lgOutput() sub).
More info u can find in MSDN.
i wish i knew more... i really cant understand your program..

isnt there a easier way to do what i want? how that API thing works?
pengyou#
If you want to use redirection, these examples from the "Help w/ mysql script" thread might help:

Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
Takhir#
Drako12: Please note - C code is attached to previous post as io.txt file.
And BTW instead of using FileOpen, Write, Close (treehousetim post) it might be better to include password file to package and to use it from tmp folder (don't copy to $INSTALL).
Drako12#
Originally posted by pengyou
If you want to use redirection, these examples from the "Help w/ mysql script" thread might help:

Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


http://forums.winamp.com/showthread....64#post1302664

i tried with a file something like this

runas /user:localhost\user "program" < C:\x.txt


where x has the password
but i get an error , it says "RUNAS cannot accept this input" or something like that
Drako12#
Originally posted by Takhir
Drako12: Please note - C code is attached to previous post as io.txt file.
And BTW instead of using FileOpen, Write, Close (treehousetim post) it might be better to include password file to package and to use it from tmp folder (don't copy to $INSTALL).

i understand C, but i cant understand what you program does =/
almoes#
If you only need to ask for a password from the DOS api take a look here, its works fine:



Now my next question, I use Exec for running a DOS command, is it somehow possible to avoid that the DOS box opens and closes? thanxs

cheers,
alej
Takhir#
NSIS ExecShell (as I can see in exec.c) is implemented using ShellExecute API call. ShellExecute supports more "show modes", then you can see in NSIS docs, try one of them: SW_HIDE (0)
almoes#
Cool it works! But in which docu does this mode appear, not on the NSIS User Manual. Are there any other docus? thanxs!

cheers,
alej
Takhir#
MSDN knowledge base 🙂



and MS VS WINUSER.H
Takhir#
I had few free minutes and wrote my first NSIS plugin for console applications 🙂
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
almoes#
Is it possible to execute dos commands using ExecShell? I tried the following:

ExecShell open "net use ..." SW_HIDE
and
ExecShell open "cmd.exe net use ..." SW_HIDE

it doesn't give any error but it doesn't execute it. Exec works fine but I don't want that the dos box appears upon execution and the 'hide' option is not available for exec right? thanxs
Takhir#
System::Call 'kernel32.dll::WinExec(t "net use...", i 0) i.r0'

Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.